Skip to content

Commit d4ae23b

Browse files
committed
first rough adaption of published massage with header
1 parent 6241a0e commit d4ae23b

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

controller_manager_msgs/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ find_package(rosidl_default_generators REQUIRED)
99
set(msg_files
1010
msg/ControllerState.msg
1111
msg/ChainConnection.msg
12+
msg/Evaluation.msg
1213
msg/HandleName.msg
1314
msg/HardwareComponentState.msg
1415
msg/HardwareInterface.msg
16+
msg/Header.msg
17+
msg/InterfaceData.msg
1518
msg/PublisherDescription.msg
1619
)
1720
set(srv_files
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
string identifier
2+
string type
3+
uint32 seq
4+
builtin_interfaces/Time receive_stamp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uint32 seq
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
controller_manager_msgs/Header header
2+
float64 data

hardware_interface/include/hardware_interface/distributed_control_interface/state_publisher.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
#include "controller_manager_msgs/msg/publisher_description.hpp"
1111

12+
#include "controller_manager_msgs/msg/interface_data.hpp"
1213
#include "rclcpp/rclcpp.hpp"
1314
#include "rclcpp_lifecycle/lifecycle_node.hpp"
1415
#include "rclcpp_lifecycle/state.hpp"
15-
#include "std_msgs/msg/float64.hpp"
1616

1717
namespace distributed_control
1818
{
@@ -53,8 +53,9 @@ class StatePublisher final
5353

5454
const std::string topic_name_;
5555
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node_;
56-
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr state_value_pub_;
56+
rclcpp::Publisher<controller_manager_msgs::msg::InterfaceData>::SharedPtr state_value_pub_;
5757
rclcpp::TimerBase::SharedPtr timer_;
58+
uint32_t seq_number_ = 0;
5859
};
5960

6061
} // namespace distributed_control

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "hardware_interface/macros.hpp"
2323
#include "hardware_interface/visibility_control.h"
2424

25+
#include "controller_manager_msgs/msg/interface_data.hpp"
2526
#include "rclcpp/rclcpp.hpp"
2627
#include "rclcpp_lifecycle/lifecycle_node.hpp"
2728
#include "std_msgs/msg/float64.hpp"
@@ -207,7 +208,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
207208
false);
208209
}
209210
// subscribe to topic provided by StatePublisher
210-
state_value_sub_ = node_->create_subscription<std_msgs::msg::Float64>(
211+
state_value_sub_ = node_->create_subscription<controller_manager_msgs::msg::InterfaceData>(
211212
get_value_topic_name_, 10,
212213
std::bind(&DistributedReadOnlyHandle::get_value_cb, this, std::placeholders::_1));
213214
}
@@ -251,7 +252,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
251252
}
252253

253254
protected:
254-
void get_value_cb(const std_msgs::msg::Float64 & msg)
255+
void get_value_cb(const controller_manager_msgs::msg::InterfaceData & msg)
255256
{
256257
value_ = msg.data;
257258
RCLCPP_DEBUG_STREAM(node_->get_logger(), "Receiving:[" << value_ << "].");
@@ -263,7 +264,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
263264
// the namespace the actual StateInterface we subscribe to is in.
264265
// We need this to create unique names for the StateInterface.
265266
std::string interface_namespace_;
266-
rclcpp::Subscription<std_msgs::msg::Float64>::SharedPtr state_value_sub_;
267+
rclcpp::Subscription<controller_manager_msgs::msg::InterfaceData>::SharedPtr state_value_sub_;
267268
double value_;
268269
};
269270

hardware_interface/src/hardware_interface/distributed_control_interface/state_publisher.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ StatePublisher::StatePublisher(
3232
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(&StatePublisher::publish_value_on_timer, this));
@@ -88,7 +89,7 @@ StatePublisher::create_publisher_description_msg() const
8889

8990
void StatePublisher::publish_value_on_timer()
9091
{
91-
auto msg = std::make_unique<std_msgs::msg::Float64>();
92+
auto msg = std::make_unique<controller_manager_msgs::msg::InterfaceData>();
9293
try
9394
{
9495
msg->data = loaned_state_interface_ptr_->get_value();
@@ -104,6 +105,8 @@ void StatePublisher::publish_value_on_timer()
104105

105106
// Put the message into a queue to be processed by the middleware.
106107
// This call is non-blocking.
108+
msg->header.seq = seq_number_;
109+
++seq_number_;
107110
state_value_pub_->publish(std::move(msg));
108111
}
109112

0 commit comments

Comments
 (0)