Skip to content

Commit 9cb0b59

Browse files
fix: detect rclcpp API differences via RCLCPP_VERSION_GTE (#115)
* fix: detect Humble via rclcpp_VERSION instead of ROS_DISTRO env var Commit 63e6e28 added a ROS_HUMBLE compile flag guarded by `if("$ENV{ROS_DISTRO}" STREQUAL "humble")`, but in the GitHub Actions build farm that check did not match even though ROS_DISTRO was "humble" at configure time. As a result the Humble build compiled the Jazzy+ branch and failed with: 'get_message_typesupport_handle' is not a member of 'rclcpp'; did you mean 'get_typesupport_handle'? Switch the detection to the rclcpp_VERSION variable populated by find_package(rclcpp). Humble ships rclcpp 16.x (threshold <17); Jazzy and newer ship 28.x+. This is deterministic and independent of the invoking shell's environment. * docs: point README CI badges at the actual workflow files The previous badge referenced a legacy `ros2.yaml` workflow that no longer exists. Replace with badges for the current workflows: ros-humble, ros-jazzy, ros-rolling, and pre-commit. * refactor: replace ROS_HUMBLE define with RCLCPP_VERSION_GTE checks Relying on CMake `if("$ENV{ROS_DISTRO}" STREQUAL "humble")` to forward a ROS_HUMBLE compile flag is brittle — it broke in the Humble CI runner even though ROS_DISTRO printed as "humble". Move the conditional compilation to the `RCLCPP_VERSION_GTE(major,minor,patch)` preprocessor macro from `<rclcpp/version.h>`, which is the authoritative version shipped by rclcpp itself via ament_generate_version_header. Per-site thresholds now reflect when each API actually changed rather than using a single rough ROS_HUMBLE flag: - typesupport_wrapper.cpp: rclcpp::get_message_typesupport_handle was added in Jazzy (rclcpp 28). Use it at >=28 and fall back to the (still existing) rclcpp::get_typesupport_handle below. Humble's rclcpp has that name too, so the rosbag2_cpp/typesupport_helpers include is no longer needed. - generic_publisher.h: the 6-arg rclcpp::PublisherBase constructor (callbacks + use_default_events) was introduced between Humble and Iron (rclcpp 17+). Guard the extra args and the callbacks_ member on RCLCPP_VERSION_GTE(17, 0, 0). - dataload_ros2.cpp: rosbag2 SerializedBagMessage::time_stamp was split into recv_timestamp/send_timestamp in Jazzy; gate the new field name on >=28 too. With everything moved to compile-time checks the `ROS_HUMBLE` compile definition and its CMake detection are unnecessary and have been removed from src/CMakeLists.txt. As a side benefit this also makes Iron compile, since the old setup unconditionally took the Jazzy path when ROS_HUMBLE wasn't defined.
1 parent 63e6e28 commit 9cb0b59

5 files changed

Lines changed: 22 additions & 33 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
[![ros2](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros2.yaml/badge.svg)](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros2.yaml)
1+
[![ROS2 Humble](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros-humble.yaml/badge.svg)](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros-humble.yaml)
2+
[![ROS2 Jazzy](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros-jazzy.yaml/badge.svg)](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros-jazzy.yaml)
3+
[![ROS2 Rolling](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros-rolling.yaml/badge.svg)](https://github.com/PlotJuggler/plotjuggler-ros-plugins/actions/workflows/ros-rolling.yaml)
24

35
# ROS plugins for PlotJuggler
46

src/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ target_link_libraries( DataStreamROS2 commonROS)
4545
add_library( TopicPublisherROS2 SHARED TopicPublisherROS2/publisher_ros2.cpp)
4646
target_link_libraries( TopicPublisherROS2 commonROS)
4747

48-
message("AMENT_PREFIX_PATH = ${AMENT_PREFIX_PATH}")
49-
message("ROS_DISTRO (env) = $ENV{ROS_DISTRO}")
50-
51-
if("$ENV{ROS_DISTRO}" STREQUAL "humble")
52-
message(STATUS "Detected Humble")
53-
target_compile_definitions(DataLoadROS2 PUBLIC ROS_HUMBLE)
54-
target_compile_definitions(TopicPublisherROS2 PUBLIC ROS_HUMBLE)
55-
target_compile_definitions(commonROS PUBLIC ROS_HUMBLE)
56-
endif()
57-
5848
#######################################################################
5949

6050

src/DataLoadROS2/dataload_ros2.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <rosbag2_cpp/types/introspection_message.hpp>
2121
#include <unordered_map>
2222
#include <rclcpp/rclcpp.hpp>
23+
#include <rclcpp/version.h>
2324
#include <rmw/rmw.h>
2425

2526
#include "dialog_select_ros_topics.h"
@@ -188,11 +189,12 @@ bool DataLoadROS2::readDataFromFile(PJ::FileLoadInfo* info, PJ::PlotDataMapRef&
188189
continue;
189190
}
190191

191-
#ifdef ROS_HUMBLE
192-
const double msg_timestamp = 1e-9 * double(msg->time_stamp); // nanoseconds to seconds
193-
#else
194-
// from jazzy and later
192+
// rosbag2 split SerializedBagMessage::time_stamp into recv_timestamp /
193+
// send_timestamp in Jazzy (rclcpp 28.x).
194+
#if RCLCPP_VERSION_GTE(28, 0, 0)
195195
const double msg_timestamp = 1e-9 * double(msg->send_timestamp); // nanoseconds to seconds
196+
#else
197+
const double msg_timestamp = 1e-9 * double(msg->time_stamp); // nanoseconds to seconds
196198
#endif
197199

198200
//------ progress dialog --------------

src/TopicPublisherROS2/generic_publisher.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020
#include <rclcpp/rclcpp.hpp>
2121
#include <rclcpp/publisher_base.hpp>
22+
#include <rclcpp/version.h>
2223

2324
#include "typesupport_wrapper.h"
2425

@@ -27,10 +28,11 @@ class GenericPublisher : public rclcpp::PublisherBase
2728
public:
2829
GenericPublisher(rclcpp::node_interfaces::NodeBaseInterface* node_base, const std::string& topic_name,
2930
const rosidl_message_type_support_t& type_support)
30-
#ifdef ROS_HUMBLE
31-
: rclcpp::PublisherBase(node_base, topic_name, type_support, rcl_publisher_get_default_options())
32-
#else
31+
// The rclcpp::PublisherBase constructor grew event-callback parameters after Humble (rclcpp 16.x).
32+
#if RCLCPP_VERSION_GTE(17, 0, 0)
3333
: rclcpp::PublisherBase(node_base, topic_name, type_support, rcl_publisher_get_default_options(), callbacks_, true)
34+
#else
35+
: rclcpp::PublisherBase(node_base, topic_name, type_support, rcl_publisher_get_default_options())
3436
#endif
3537
{
3638
}
@@ -56,7 +58,7 @@ class GenericPublisher : public rclcpp::PublisherBase
5658
return std::make_shared<GenericPublisher>(node.get_node_base_interface().get(), topic_name, *type_support);
5759
}
5860

59-
#ifndef ROS_HUMBLE
61+
#if RCLCPP_VERSION_GTE(17, 0, 0)
6062
rclcpp::PublisherEventCallbacks callbacks_;
6163
#endif
6264
};

src/typesupport_wrapper.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
2-
31
#include "typesupport_wrapper.h"
4-
#include "rosidl_runtime_cpp/message_type_support_decl.hpp"
52

6-
#ifdef ROS_HUMBLE
7-
#include "rosbag2_cpp/typesupport_helpers.hpp"
8-
#else
93
#include "rclcpp/typesupport_helpers.hpp"
10-
#endif
4+
#include "rclcpp/version.h"
5+
#include "rosidl_runtime_cpp/message_type_support_decl.hpp"
116

127
namespace wrapper
138
{
149
std::shared_ptr<rcpputils::SharedLibrary> get_typesupport_library(const std::string& type,
1510
const std::string& typesupport_identifier)
1611
{
17-
#ifdef ROS_HUMBLE
18-
return rosbag2_cpp::get_typesupport_library(type, typesupport_identifier);
19-
#else
2012
return rclcpp::get_typesupport_library(type, typesupport_identifier);
21-
#endif
2213
}
2314

2415
const rosidl_message_type_support_t* get_message_typesupport_handle(const std::string& type,
2516
const std::string& typesupport_identifier,
2617
std::shared_ptr<rcpputils::SharedLibrary> library)
2718
{
28-
#ifdef ROS_HUMBLE
29-
return rosbag2_cpp::get_typesupport_handle(type, typesupport_identifier, library);
30-
#else
19+
// rclcpp::get_message_typesupport_handle was introduced in Jazzy (rclcpp 28.x).
20+
// On Humble/Iron the only name available is rclcpp::get_typesupport_handle.
21+
#if RCLCPP_VERSION_GTE(28, 0, 0)
3122
return rclcpp::get_message_typesupport_handle(type, typesupport_identifier, *library);
23+
#else
24+
return rclcpp::get_typesupport_handle(type, typesupport_identifier, *library);
3225
#endif
3326
}
3427
} // namespace wrapper

0 commit comments

Comments
 (0)