Skip to content

Commit 32448b6

Browse files
committed
add time and publishing of when command is received
1 parent dc4b520 commit 32448b6

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ void ControllerManager::init_distributed_sub_controller_manager()
469469
{
470470
// create node for publishing/subscribing
471471
rclcpp::NodeOptions node_options;
472+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
472473
distributed_pub_sub_node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
473474
std::string(get_name()) + "_pub_sub_node", get_namespace(), node_options, false);
474475
//try to add to executor
@@ -513,6 +514,7 @@ void ControllerManager::init_distributed_central_controller_manager()
513514
if (!use_multiple_nodes())
514515
{
515516
rclcpp::NodeOptions node_options;
517+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
516518
distributed_pub_sub_node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
517519
std::string(get_name()) + "_pub_sub_node", get_namespace(), node_options, false);
518520
//try to add to executor
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
string identifier
22
string type
33
uint32 seq
4+
uint64 receive_time
45
builtin_interfaces/Time receive_stamp

hardware_interface/include/hardware_interface/distributed_control_interface/command_forwarder.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
#include "controller_manager_msgs/msg/evaluation.hpp"
1415
#include "controller_manager_msgs/msg/interface_data.hpp"
1516
#include "rclcpp/rclcpp.hpp"
1617
#include "rclcpp_lifecycle/lifecycle_node.hpp"
@@ -58,12 +59,17 @@ class CommandForwarder final
5859
const std::chrono::milliseconds period_in_ms_;
5960

6061
const std::string topic_name_;
62+
const std::string evaluation_topic_name_;
6163
std::string subscription_topic_name_;
6264
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node_;
6365
rclcpp::Publisher<controller_manager_msgs::msg::InterfaceData>::SharedPtr state_value_pub_;
6466
rclcpp::Subscription<controller_manager_msgs::msg::InterfaceData>::SharedPtr
6567
command_subscription_;
6668
rclcpp::TimerBase::SharedPtr timer_;
69+
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> evaluation_node_;
70+
rclcpp::Publisher<controller_manager_msgs::msg::Evaluation>::SharedPtr evaluation_pub_;
71+
const std::string evaluation_type_ = "commandInterface";
72+
std::string evaluation_identifier_;
6773
};
6874

6975
} // namespace distributed_control

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
203203
if (!node_.get())
204204
{
205205
rclcpp::NodeOptions node_options;
206+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
206207
node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
207208
get_underscore_separated_name() + "_state_interface_subscriber", namespace_, node_options,
208209
false);
@@ -350,6 +351,7 @@ class DistributedReadWriteHandle : public ReadWriteHandle
350351
if (!node_.get())
351352
{
352353
rclcpp::NodeOptions node_options;
354+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
353355
node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
354356
get_underscore_separated_name() + "_distributed_command_interface", namespace_,
355357
node_options, false);

hardware_interface/src/hardware_interface/distributed_control_interface/command_forwarder.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,32 @@ CommandForwarder::CommandForwarder(
2121
namespace_(ns),
2222
period_in_ms_(period_in_ms),
2323
node_(node),
24-
topic_name_(loaned_command_interface_ptr_->get_underscore_separated_name() + "_command_state")
24+
topic_name_(loaned_command_interface_ptr_->get_underscore_separated_name() + "_command_state"),
25+
evaluation_topic_name_(
26+
loaned_command_interface_ptr_->get_underscore_separated_name() + "_EVALUATION")
2527
{
2628
// if we did not get a node passed, we create one ourselves
2729
if (!node_.get())
2830
{
2931
rclcpp::NodeOptions node_options;
32+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
3033
node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
3134
loaned_command_interface_ptr_->get_underscore_separated_name() + "_command_forwarder",
3235
namespace_, node_options, false);
3336
}
3437

3538
state_value_pub_ =
3639
node_->create_publisher<controller_manager_msgs::msg::InterfaceData>(topic_name_, 10);
40+
41+
rclcpp::NodeOptions node_options;
42+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
43+
evaluation_node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
44+
loaned_command_interface_ptr_->get_underscore_separated_name() + "evaluation_node", namespace_,
45+
node_options, false);
46+
evaluation_pub_ = evaluation_node_->create_publisher<controller_manager_msgs::msg::Evaluation>(
47+
evaluation_topic_name_, 10);
48+
evaluation_identifier_ = loaned_command_interface_ptr_->get_underscore_separated_name();
49+
3750
// TODO(Manuel): We should check if we cannot detect changes to LoanedStateInterface's value and only publish then
3851
timer_ = node_->create_wall_timer(
3952
period_in_ms_, std::bind(&CommandForwarder::publish_value_on_timer, this));
@@ -117,6 +130,17 @@ void CommandForwarder::publish_value_on_timer()
117130

118131
void CommandForwarder::forward_command(const controller_manager_msgs::msg::InterfaceData & msg)
119132
{
133+
auto evaluation_msg = std::make_unique<controller_manager_msgs::msg::Evaluation>();
134+
evaluation_msg->receive_stamp = evaluation_node_->now();
135+
evaluation_msg->receive_time =
136+
static_cast<uint64_t>(evaluation_msg->receive_stamp.sec) * 1'000'000'000ULL +
137+
evaluation_msg->receive_stamp.nanosec;
138+
evaluation_msg->type = evaluation_type_;
139+
evaluation_msg->identifier = evaluation_identifier_;
140+
evaluation_msg->seq = msg.header.seq;
141+
// todo check for QoS to publish immediately and never block to be fast as possible
142+
evaluation_pub_->publish(std::move(evaluation_msg));
143+
120144
loaned_command_interface_ptr_->set_value(msg.data);
121145
}
122146

hardware_interface/src/hardware_interface/distributed_control_interface/state_publisher.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ StatePublisher::StatePublisher(
2727
if (!node_.get())
2828
{
2929
rclcpp::NodeOptions node_options;
30+
node_options.clock_type(rcl_clock_type_t::RCL_STEADY_TIME);
3031
node_ = std::make_shared<rclcpp_lifecycle::LifecycleNode>(
3132
loaned_state_interface_ptr_->get_underscore_separated_name() + "_state_publisher", namespace_,
3233
node_options, false);

0 commit comments

Comments
 (0)