Skip to content

Commit 152e9f0

Browse files
committed
Add support to auto transform messages using the odom sensor
1 parent 2ed8233 commit 152e9f0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

topic_sensors/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# Topic Sensors
22

3-
This package provides a collection of Sensor interfaces that write incoming
3+
This package provides a collection of sensor interfaces that write incoming
44
ROS 2 messages to ros2_control state interfaces.
55

66
## Odometry Sensor
77

88
A sensor plugin that reads incoming `nav_msgs/Odometry` messages and writes
9-
them to state interfaces. No manipulation is done to the data, beyond proxying
10-
the message values.
9+
them to state interfaces.
1110

1211
### Plugin Library
1312

1413
topic_sensors/odom_sensor
14+
15+
### Parameters
16+
17+
- topic: The topic that the sensor should subscribe to
18+
- transform: Whether or not the sensor should transform the message from the
19+
ROS [REP-105](https://ros.org/reps/rep-0105.html) convention to the maritime
20+
convention documented in [REP-156](https://github.com/ros-infrastructure/rep/pull/398).

topic_sensors/src/odom_sensor.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <ranges>
2525

2626
#include "controller_common/common.hpp"
27+
#include "message_transforms/transforms.hpp"
2728

2829
namespace topic_sensors
2930
{
@@ -49,8 +50,17 @@ auto OdomSensor::on_configure(const rclcpp_lifecycle::State & /*previous_state*/
4950
}
5051
RCLCPP_INFO(logger_, std::format("Subscribing to topic: {}", topic).c_str()); // NOLINT
5152

53+
const bool transform_message = info_.hardware_parameters.at("transform_message") == "true";
54+
if (transform_message) {
55+
// NOLINTNEXTLINE
56+
RCLCPP_INFO(logger_, "Incoming messages will be transform from the ROS mobile standard to the maritime standard");
57+
}
58+
5259
state_sub_ = node_->create_subscription<nav_msgs::msg::Odometry>(
53-
topic, rclcpp::SensorDataQoS(), [this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) { // NOLINT
60+
topic, rclcpp::SensorDataQoS(), [this, &transform_message](const std::shared_ptr<nav_msgs::msg::Odometry> msg) {
61+
if (transform_message) {
62+
m2m::transforms::transform_message(*msg, "map_ned", "base_link_fsd");
63+
}
5464
state_.writeFromNonRT(*msg);
5565
});
5666
return hardware_interface::CallbackReturn::SUCCESS;

0 commit comments

Comments
 (0)