2323#include " hardware_interface/macros.hpp"
2424#include " hardware_interface/visibility_control.h"
2525
26+ #include " controller_manager_msgs/msg/interface_data.hpp"
2627#include " rclcpp/rclcpp.hpp"
2728#include " rclcpp_lifecycle/lifecycle_node.hpp"
2829#include " std_msgs/msg/float64.hpp"
@@ -203,6 +204,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
203204 if (!node_.get ())
204205 {
205206 rclcpp::NodeOptions node_options;
207+ node_options.clock_type (rcl_clock_type_t ::RCL_STEADY_TIME);
206208 node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
207209 get_underscore_separated_name () + " _state_interface_subscriber" , namespace_, node_options,
208210 false );
@@ -212,7 +214,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
212214 rclcpp::QoS qos_profile (
213215 rclcpp::QoSInitialization::from_rmw (evaluation_helper->get_qos_profile ()));
214216 // subscribe to topic provided by StatePublisher
215- state_value_sub_ = node_->create_subscription <std_msgs ::msg::Float64 >(
217+ state_value_sub_ = node_->create_subscription <controller_manager_msgs ::msg::InterfaceData >(
216218 get_value_topic_name_, qos_profile,
217219 std::bind (&DistributedReadOnlyHandle::get_value_cb, this , std::placeholders::_1));
218220 }
@@ -256,7 +258,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
256258 }
257259
258260protected:
259- void get_value_cb (const std_msgs ::msg::Float64 & msg)
261+ void get_value_cb (const controller_manager_msgs ::msg::InterfaceData & msg)
260262 {
261263 value_ = msg.data ;
262264 RCLCPP_DEBUG_STREAM (node_->get_logger (), " Receiving:[" << value_ << " ]." );
@@ -268,7 +270,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
268270 // the namespace the actual StateInterface we subscribe to is in.
269271 // We need this to create unique names for the StateInterface.
270272 std::string interface_namespace_;
271- rclcpp::Subscription<std_msgs ::msg::Float64 >::SharedPtr state_value_sub_;
273+ rclcpp::Subscription<controller_manager_msgs ::msg::InterfaceData >::SharedPtr state_value_sub_;
272274 double value_;
273275};
274276
@@ -354,6 +356,7 @@ class DistributedReadWriteHandle : public ReadWriteHandle
354356 if (!node_.get ())
355357 {
356358 rclcpp::NodeOptions node_options;
359+ node_options.clock_type (rcl_clock_type_t ::RCL_STEADY_TIME);
357360 node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
358361 get_underscore_separated_name () + " _distributed_command_interface" , namespace_,
359362 node_options, false );
@@ -363,13 +366,13 @@ class DistributedReadWriteHandle : public ReadWriteHandle
363366 rclcpp::QoS qos_profile (
364367 rclcpp::QoSInitialization::from_rmw (evaluation_helper->get_qos_profile ()));
365368 // subscribe to topic provided by CommandForwarder
366- command_value_sub_ = node_->create_subscription <std_msgs ::msg::Float64 >(
369+ command_value_sub_ = node_->create_subscription <controller_manager_msgs ::msg::InterfaceData >(
367370 get_value_topic_name_, qos_profile,
368371 std::bind (&DistributedReadWriteHandle::get_value_cb, this , std::placeholders::_1));
369372
370373 // create publisher so that we can forward the commands
371- command_value_pub_ =
372- node_-> create_publisher <std_msgs::msg::Float64>( forward_command_topic_name_, qos_profile);
374+ command_value_pub_ = node_-> create_publisher <controller_manager_msgs::msg::InterfaceData>(
375+ forward_command_topic_name_, qos_profile);
373376 }
374377
375378 explicit DistributedReadWriteHandle (const std::string & interface_name)
@@ -410,19 +413,20 @@ class DistributedReadWriteHandle : public ReadWriteHandle
410413
411414 void set_value (double value) override
412415 {
413- auto msg = std::make_unique<std_msgs ::msg::Float64 >();
416+ auto msg = std::make_unique<controller_manager_msgs ::msg::InterfaceData >();
414417 msg->data = value;
418+ msg->header .seq = seq_number_;
419+ ++seq_number_;
415420
416421 RCLCPP_DEBUG (node_->get_logger (), " DistributedCommandInterface Publishing: '%.7lf'" , msg->data );
417- std::flush (std::cout);
418422
419423 command_value_pub_->publish (std::move (msg));
420424 }
421425
422426 std::string forward_command_topic_name () const { return forward_command_topic_name_; }
423427
424428protected:
425- void get_value_cb (const std_msgs ::msg::Float64 & msg)
429+ void get_value_cb (const controller_manager_msgs ::msg::InterfaceData & msg)
426430 {
427431 value_ = msg.data ;
428432 RCLCPP_DEBUG_STREAM (
@@ -435,10 +439,11 @@ class DistributedReadWriteHandle : public ReadWriteHandle
435439 // the namespace the actual CommandInterface we subscribe to is in.
436440 // We need this to create unique names for the CommandInterface.
437441 std::string interface_namespace_;
438- rclcpp::Subscription<std_msgs ::msg::Float64 >::SharedPtr command_value_sub_;
442+ rclcpp::Subscription<controller_manager_msgs ::msg::InterfaceData >::SharedPtr command_value_sub_;
439443 std::string forward_command_topic_name_;
440- rclcpp::Publisher<std_msgs ::msg::Float64 >::SharedPtr command_value_pub_;
444+ rclcpp::Publisher<controller_manager_msgs ::msg::InterfaceData >::SharedPtr command_value_pub_;
441445 double value_;
446+ uint_fast32_t seq_number_ = 0 ;
442447};
443448
444449class DistributedCommandInterface : public DistributedReadWriteHandle
0 commit comments