Skip to content

Fix operator+ error when adding Duration to header.stamp in PublishEventBasedCamera #6

@johanjohnthomas

Description

@johanjohnthomas

Description

When building stonefish_ros2 against ROS 2 Humble, the call

msg.events[i].ts = msg.header.stamp + rclcpp::Duration(0, offset_ns)

### Steps to Reproduce

1. Clone the stonefish_ros2 wrapper on Ubuntu 22.04 with ROS 2 Humble.
2. Run `colcon build` in your workspace.
3. Observe the error:
```/opt/ros/humble/include/rclcpp/rclcpp/time.hpp:223:1: note: candidate: ‘rclcpp::Time rclcpp::operator+(const rclcpp::Duration&, const rclcpp::Time&)’
  223 | operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs);
      | ^~~~~~~~
/opt/ros/humble/include/rclcpp/rclcpp/time.hpp:223:36: note:   no known conversion for argument 1 from ‘std_msgs::msg::Header_<std::allocator<void> >::_stamp_type’ {aka ‘builtin_interfaces::msg::Time_<std::allocator<void> >’} to ‘const rclcpp::Duration&’
  223 | operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
gmake[2]: *** [CMakeFiles/stonefish_ros2_interface.dir/build.make:132: CMakeFiles/stonefish_ros2_interface.dir/src/stonefish_ros2/ROS2Interface.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:597: CMakeFiles/stonefish_ros2_interface.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
  1. Build stops at ROS2Interface.cpp:701.

Proposed Fix

Convert msg.header.stamp into an rclcpp::Time (which does support operator+ with rclcpp::Duration).

Add the duration.
Assign back to the event timestamp via the implicit conversion operator.

Environment

Pop!_OS 22.04 / Ubuntu 22.04

ROS 2 Humble Hawksbill

C++17


I’ll submit a branch that applies this patch and updates the includes accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions