Skip to content

Commit dc4b520

Browse files
committed
changes for command side, publishing missing
1 parent d4ae23b commit dc4b520

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

hardware_interface/include/hardware_interface/distributed_control_interface/command_forwarder.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
#include "controller_manager_msgs/msg/publisher_description.hpp"
1313

14+
#include "controller_manager_msgs/msg/interface_data.hpp"
1415
#include "rclcpp/rclcpp.hpp"
1516
#include "rclcpp_lifecycle/lifecycle_node.hpp"
1617
#include "rclcpp_lifecycle/state.hpp"
17-
#include "std_msgs/msg/float64.hpp"
1818

1919
namespace distributed_control
2020
{
@@ -51,7 +51,7 @@ class CommandForwarder final
5151

5252
private:
5353
void publish_value_on_timer();
54-
void forward_command(const std_msgs::msg::Float64 & msg);
54+
void forward_command(const controller_manager_msgs::msg::InterfaceData & msg);
5555

5656
std::unique_ptr<hardware_interface::LoanedCommandInterface> loaned_command_interface_ptr_;
5757
const std::string namespace_;
@@ -60,8 +60,9 @@ class CommandForwarder final
6060
const std::string topic_name_;
6161
std::string subscription_topic_name_;
6262
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node_;
63-
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr state_value_pub_;
64-
rclcpp::Subscription<std_msgs::msg::Float64>::SharedPtr command_subscription_;
63+
rclcpp::Publisher<controller_manager_msgs::msg::InterfaceData>::SharedPtr state_value_pub_;
64+
rclcpp::Subscription<controller_manager_msgs::msg::InterfaceData>::SharedPtr
65+
command_subscription_;
6566
rclcpp::TimerBase::SharedPtr timer_;
6667
};
6768

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ class DistributedReadWriteHandle : public ReadWriteHandle
356356
}
357357

358358
// subscribe to topic provided by CommandForwarder
359-
command_value_sub_ = node_->create_subscription<std_msgs::msg::Float64>(
359+
command_value_sub_ = node_->create_subscription<controller_manager_msgs::msg::InterfaceData>(
360360
get_value_topic_name_, 10,
361361
std::bind(&DistributedReadWriteHandle::get_value_cb, this, std::placeholders::_1));
362362

363363
// create publisher so that we can forward the commands
364-
command_value_pub_ =
365-
node_->create_publisher<std_msgs::msg::Float64>(forward_command_topic_name_, 10);
364+
command_value_pub_ = node_->create_publisher<controller_manager_msgs::msg::InterfaceData>(
365+
forward_command_topic_name_, 10);
366366
}
367367

368368
explicit DistributedReadWriteHandle(const std::string & interface_name)
@@ -403,19 +403,20 @@ class DistributedReadWriteHandle : public ReadWriteHandle
403403

404404
void set_value(double value) override
405405
{
406-
auto msg = std::make_unique<std_msgs::msg::Float64>();
406+
auto msg = std::make_unique<controller_manager_msgs::msg::InterfaceData>();
407407
msg->data = value;
408+
msg->header.seq = seq_number_;
409+
++seq_number_;
408410

409411
RCLCPP_DEBUG(node_->get_logger(), "DistributedCommandInterface Publishing: '%.7lf'", msg->data);
410-
std::flush(std::cout);
411412

412413
command_value_pub_->publish(std::move(msg));
413414
}
414415

415416
std::string forward_command_topic_name() const { return forward_command_topic_name_; }
416417

417418
protected:
418-
void get_value_cb(const std_msgs::msg::Float64 & msg)
419+
void get_value_cb(const controller_manager_msgs::msg::InterfaceData & msg)
419420
{
420421
value_ = msg.data;
421422
RCLCPP_DEBUG_STREAM(
@@ -428,10 +429,11 @@ class DistributedReadWriteHandle : public ReadWriteHandle
428429
// the namespace the actual CommandInterface we subscribe to is in.
429430
// We need this to create unique names for the CommandInterface.
430431
std::string interface_namespace_;
431-
rclcpp::Subscription<std_msgs::msg::Float64>::SharedPtr command_value_sub_;
432+
rclcpp::Subscription<controller_manager_msgs::msg::InterfaceData>::SharedPtr command_value_sub_;
432433
std::string forward_command_topic_name_;
433-
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr command_value_pub_;
434+
rclcpp::Publisher<controller_manager_msgs::msg::InterfaceData>::SharedPtr command_value_pub_;
434435
double value_;
436+
uint_fast32_t seq_number_ = 0;
435437
};
436438

437439
class DistributedCommandInterface : public DistributedReadWriteHandle

hardware_interface/src/hardware_interface/distributed_control_interface/command_forwarder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ CommandForwarder::CommandForwarder(
3232
namespace_, node_options, false);
3333
}
3434

35-
state_value_pub_ = node_->create_publisher<std_msgs::msg::Float64>(topic_name_, 10);
35+
state_value_pub_ =
36+
node_->create_publisher<controller_manager_msgs::msg::InterfaceData>(topic_name_, 10);
3637
// TODO(Manuel): We should check if we cannot detect changes to LoanedStateInterface's value and only publish then
3738
timer_ = node_->create_wall_timer(
3839
period_in_ms_, std::bind(&CommandForwarder::publish_value_on_timer, this));
@@ -90,15 +91,15 @@ CommandForwarder::create_publisher_description_msg() const
9091
void CommandForwarder::subscribe_to_command_publisher(const std::string & topic_name)
9192
{
9293
subscription_topic_name_ = topic_name;
93-
command_subscription_ = node_->create_subscription<std_msgs::msg::Float64>(
94+
command_subscription_ = node_->create_subscription<controller_manager_msgs::msg::InterfaceData>(
9495
subscription_topic_name_, 10,
9596
std::bind(&CommandForwarder::forward_command, this, std::placeholders::_1));
9697
}
9798

9899
void CommandForwarder::publish_value_on_timer()
99100
{
100101
// Todo(Manuel) create custom msg and return success or failure not just nan.
101-
auto msg = std::make_unique<std_msgs::msg::Float64>();
102+
auto msg = std::make_unique<controller_manager_msgs::msg::InterfaceData>();
102103
try
103104
{
104105
msg->data = loaned_command_interface_ptr_->get_value();
@@ -108,14 +109,13 @@ void CommandForwarder::publish_value_on_timer()
108109
msg->data = std::numeric_limits<double>::quiet_NaN();
109110
}
110111
RCLCPP_DEBUG(node_->get_logger(), "Publishing: '%.7lf'", msg->data);
111-
std::flush(std::cout);
112112

113113
// Put the message into a queue to be processed by the middleware.
114114
// This call is non-blocking.
115115
state_value_pub_->publish(std::move(msg));
116116
}
117117

118-
void CommandForwarder::forward_command(const std_msgs::msg::Float64 & msg)
118+
void CommandForwarder::forward_command(const controller_manager_msgs::msg::InterfaceData & msg)
119119
{
120120
loaned_command_interface_ptr_->set_value(msg.data);
121121
}

hardware_interface/src/hardware_interface/distributed_control_interface/state_publisher.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ void StatePublisher::publish_value_on_timer()
101101
msg->data = std::numeric_limits<double>::quiet_NaN();
102102
}
103103
RCLCPP_DEBUG(node_->get_logger(), "Publishing: '%.7lf'", msg->data);
104-
std::flush(std::cout);
105104

106105
// Put the message into a queue to be processed by the middleware.
107106
// This call is non-blocking.

0 commit comments

Comments
 (0)