Skip to content

Commit e943da2

Browse files
committed
Update API according to recent upstream deprecations
1 parent c47ab31 commit e943da2

5 files changed

Lines changed: 70 additions & 53 deletions

File tree

ardusub_manager/CMakeLists.txt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@ endif()
77

88
include(GNUInstallDirs)
99

10-
set(THIS_PACKAGE_INCLUDE_DEPENDS
11-
rclcpp
12-
rclcpp_lifecycle
13-
tf2
14-
tf2_ros
15-
mavros_msgs
16-
geometry_msgs
17-
geographic_msgs
18-
)
19-
20-
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
21-
find_package(${Dependency} REQUIRED)
22-
endforeach()
23-
2410
find_package(ament_cmake REQUIRED)
11+
find_package(rclcpp REQUIRED)
12+
find_package(rclcpp_lifecycle REQUIRED)
13+
find_package(tf2 REQUIRED)
14+
find_package(tf2_ros REQUIRED)
15+
find_package(mavros_msgs REQUIRED)
16+
find_package(geometry_msgs REQUIRED)
17+
find_package(geographic_msgs REQUIRED)
2518
find_package(generate_parameter_library REQUIRED)
2619

2720
generate_parameter_library(ardusub_manager_parameters
@@ -30,9 +23,18 @@ generate_parameter_library(ardusub_manager_parameters
3023

3124
add_executable(ardusub_manager)
3225
target_sources(ardusub_manager PRIVATE src/ardusub_manager.cpp)
33-
34-
ament_target_dependencies(ardusub_manager PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
35-
target_link_libraries(ardusub_manager PUBLIC ardusub_manager_parameters)
26+
target_link_libraries(
27+
ardusub_manager
28+
PUBLIC
29+
${mavros_msgs_TARGETS}
30+
${geometry_msgs_TARGETS}
31+
${geographic_msgs_TARGETS}
32+
ardusub_manager_parameters
33+
rclcpp::rclcpp
34+
rclcpp_lifecycle::rclcpp_lifecycle
35+
tf2::tf2
36+
tf2_ros::tf2_ros
37+
)
3638
target_compile_features(ardusub_manager PUBLIC cxx_std_23)
3739

3840
install(

ardusub_manager/src/ardusub_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "mavros_msgs/srv/message_interval.hpp"
2727
#include "rclcpp/rclcpp.hpp"
2828
#include "rclcpp_lifecycle/lifecycle_node.hpp"
29-
#include "tf2_ros/transform_broadcaster.h"
29+
#include "tf2_ros/transform_broadcaster.hpp"
3030

3131
// auto-generated by generate_parameter_library
3232
#include <ardusub_manager/ardusub_manager_parameters.hpp>

thruster_hardware/CMakeLists.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@ endif()
77

88
include(GNUInstallDirs)
99

10-
set(THIS_PACKAGE_INCLUDE_DEPENDS
11-
rclcpp
12-
rclcpp_lifecycle
13-
pluginlib
14-
hardware_interface
15-
mavros_msgs
16-
rcl_interfaces
17-
rclcpp_lifecycle
18-
realtime_tools
19-
)
20-
2110
find_package(ament_cmake REQUIRED)
22-
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
23-
find_package(${Dependency} REQUIRED)
24-
endforeach()
11+
find_package(rclcpp REQUIRED)
12+
find_package(rclcpp_lifecycle REQUIRED)
13+
find_package(pluginlib REQUIRED)
14+
find_package(hardware_interface REQUIRED)
15+
find_package(mavros_msgs REQUIRED)
16+
find_package(rcl_interfaces REQUIRED)
17+
find_package(realtime_tools REQUIRED)
2518

2619
add_library(thruster_hardware SHARED)
2720
target_sources(
@@ -34,7 +27,18 @@ target_sources(
3427
${CMAKE_CURRENT_SOURCE_DIR}/include/thruster_hardware/thruster_hardware.hpp
3528
)
3629
target_compile_features(thruster_hardware PUBLIC cxx_std_23)
37-
ament_target_dependencies(thruster_hardware PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
30+
target_link_libraries(
31+
thruster_hardware
32+
PUBLIC
33+
${mavros_msgs_TARGETS}
34+
${rcl_interfaces_TARGETS}
35+
rclcpp::rclcpp
36+
rclcpp_lifecycle::rclcpp_lifecycle
37+
pluginlib::pluginlib
38+
hardware_interface::hardware_interface
39+
realtime_tools::realtime_tools
40+
)
41+
3842
pluginlib_export_plugin_description_file(hardware_interface thruster_hardware.xml)
3943

4044
install(
@@ -47,6 +51,14 @@ install(
4751
)
4852

4953
ament_export_targets(export_thruster_hardware HAS_LIBRARY_TARGET)
50-
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
54+
ament_export_dependencies(
55+
"rclcpp"
56+
"rclcpp_lifecycle"
57+
"pluginlib"
58+
"hardware_interface"
59+
"mavros_msgs"
60+
"rcl_interfaces"
61+
"realtime_tools"
62+
)
5163

5264
ament_package()

thruster_hardware/include/thruster_hardware/thruster_hardware.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class ThrusterHardware : public hardware_interface::SystemInterface
7575
std::shared_ptr<rclcpp::Client<rcl_interfaces::srv::SetParameters>> set_params_client_;
7676
std::unordered_map<std::string, ThrusterConfig> thruster_configs_;
7777

78+
// maintain a message so that we don't have to allocate one every time we write to the hardware
79+
mavros_msgs::msg::OverrideRCIn rc_override_msg_;
80+
7881
// the write loop run regardless of whether or not the hardware is active
7982
// so we need to keep track of this to ensure that we only send commands when the hardware is active
8083
bool is_active_{false};

thruster_hardware/src/thruster_hardware.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ auto ThrusterHardware::on_init(const hardware_interface::HardwareComponentInterf
7575

7676
// store the thruster configurations
7777
ThrusterConfig config;
78-
config.param.name = name;
78+
config.param.name = std::to_string(name);
7979
config.param.value.type = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER;
8080
config.param.value.integer_value = default_value;
8181
config.channel = channel;
@@ -104,11 +104,9 @@ auto ThrusterHardware::on_configure(const rclcpp_lifecycle::State & /*previous_s
104104
rt_override_rc_pub_ =
105105
std::make_unique<realtime_tools::RealtimePublisher<mavros_msgs::msg::OverrideRCIn>>(override_rc_pub_);
106106

107-
rt_override_rc_pub_->lock();
108-
for (auto & channel : rt_override_rc_pub_->msg_.channels) {
107+
for (auto & channel : rc_override_msg_.channels) {
109108
channel = mavros_msgs::msg::OverrideRCIn::CHAN_NOCHANGE;
110109
}
111-
rt_override_rc_pub_->unlock();
112110

113111
// configure a service client to set the ardusub thruster parameters
114112
using namespace std::chrono_literals;
@@ -127,11 +125,12 @@ auto ThrusterHardware::on_configure(const rclcpp_lifecycle::State & /*previous_s
127125
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
128126
auto ThrusterHardware::stop_thrusters() -> void
129127
{
130-
if (rt_override_rc_pub_ && rt_override_rc_pub_->trylock()) {
131-
for (const auto & [name, config] : thruster_configs_) {
132-
rt_override_rc_pub_->msg_.channels[config.channel - 1] = config.neutral_pwm;
133-
}
134-
rt_override_rc_pub_->unlockAndPublish();
128+
for (const auto & [name, config] : thruster_configs_) {
129+
rc_override_msg_.channels[config.channel - 1] = config.neutral_pwm;
130+
}
131+
132+
if (rt_override_rc_pub_ && rt_override_rc_pub_->can_publish()) {
133+
rt_override_rc_pub_->try_publish(rc_override_msg_);
135134
}
136135
}
137136

@@ -252,17 +251,18 @@ auto ThrusterHardware::write(const rclcpp::Time & /*time*/, const rclcpp::Durati
252251
return hardware_interface::return_type::OK;
253252
}
254253

255-
if (rt_override_rc_pub_ && rt_override_rc_pub_->trylock()) {
256-
for (const auto & [name, desc] : joint_command_interfaces_) {
257-
const auto command = get_command(name);
258-
if (std::isnan(command)) {
259-
continue;
260-
}
261-
262-
const auto config = thruster_configs_.at(desc.prefix_name);
263-
rt_override_rc_pub_->msg_.channels[config.channel - 1] = static_cast<int>(command);
254+
for (const auto & [name, desc] : joint_command_interfaces_) {
255+
const auto command = get_command(name);
256+
if (std::isnan(command)) {
257+
continue;
264258
}
265-
rt_override_rc_pub_->unlockAndPublish();
259+
260+
const auto config = thruster_configs_.at(desc.prefix_name);
261+
rc_override_msg_.channels[config.channel - 1] = static_cast<int>(command);
262+
}
263+
264+
if (rt_override_rc_pub_ && rt_override_rc_pub_->can_publish()) {
265+
rt_override_rc_pub_->try_publish(rc_override_msg_);
266266
}
267267

268268
return hardware_interface::return_type::OK;

0 commit comments

Comments
 (0)