createTimer() replacement in eloquent
In ROS1 we can simply do:
ros::Timer timer = nh.createTimer(ros::Duration(0.1), timerCallback);
This gives us a tick approximately every 100 ms of ROS time. In ROS2, particularly in Eloquent, there is no similar API as far as I can determine, and the only references I find mention Ardent APIs that have been removed. However, for this code:
rclcpp::Clock ros_clock(RCL_ROS_TIME);
This returns a ROS time-based clock, but I cannot see an obvious way to go from there to a timer that ticks every simulated 100 milliseconds. rclcpp::create_wall_timer()
exists, but not the more generic rclcpp::create_timer(rclccp::Clock, duration, callback)
. How can I replicate the ROS1 behaviour in ROS2?
EDIT: Studying the API, the best I can find is something like this:
rclcpp::Clock ros_clock(RCL_ROS_TIME);
rclcpp::timer::GenericTimer<??typeof my_callback??, ros_clock> ros_timer(10ms, std::bind(&my_callback, this));
n.get_node_timers_interface()->add_timer(ros_timer, n.get_callback_groups());
This seems a very long-winded way to do this, though!