Hello,
we use ROS2 to publish simple string to the topic. We created ROS2 timer using this->create_wall_timer inside Coppelia plugin to publish new message every 100 ms.
But this timer is not triggered at all. We have made a workaround by creating separate thread in which message is published. But it does not look like a good solution.
Is it a problem with how ROS2 timers works or we are doing something wrong?
For the base code we are using code from ROS2 tutorial https://index.ros.org/doc/ros2/Tutorial ... ubscriber/
Thanks in advance.
ROS2 Node create_wall_timer
-
- Posts: 16
- Joined: 11 Aug 2020, 12:47
Re: ROS2 Node create_wall_timer
Hello,
we have managed to solve our problem with ROS2 Timers.
You have to spin your node so that rclcpp::TimerBase can update its state (we assumed that).
To do this in plugin, you have to spin node inside onInstancePass method (_timer has type of rclcpp::TimerBase::SharedPtr):
If you want to stop timer on simulation stop:
To start it again without creating new instance of the timer:
If someone has better approach, please write about it ;)
Cheers.
we have managed to solve our problem with ROS2 Timers.
You have to spin your node so that rclcpp::TimerBase can update its state (we assumed that).
To do this in plugin, you have to spin node inside onInstancePass method (_timer has type of rclcpp::TimerBase::SharedPtr):
Code: Select all
void Plugin::onInstancePass(const sim::InstancePassFlags &flags, bool first)
{
rclcpp::spin_some(this->get_node_base_interface());
}
Code: Select all
void Plugin::onSimulationAboutToEnd()
{
_timer->cancel();
}
Code: Select all
void Plugin::onSimulationAboutToStart()
{
_timer->reset();
}
Cheers.
Re: ROS2 Node create_wall_timer
Why a ROS timer? was it not possible with the regular API and simulation scripts to call a function every X milliseconds?avena_robotics wrote: ↑15 Dec 2020, 16:06 we use ROS2 to publish simple string to the topic. We created ROS2 timer using this->create_wall_timer inside Coppelia plugin to publish new message every 100 ms.
Depends on how you created the timer. Show complete code if possible, or the relevant parts of it.avena_robotics wrote: ↑15 Dec 2020, 16:06 But this timer is not triggered at all. We have made a workaround by creating separate thread in which message is published. But it does not look like a good solution.
Is it a problem with how ROS2 timers works or we are doing something wrong?
For the base code we are using code from ROS2 tutorial https://index.ros.org/doc/ros2/Tutorial ... ubscriber/
What'savena_robotics wrote: ↑16 Dec 2020, 11:53 You have to spin your node so that rclcpp::TimerBase can update its state (we assumed that).
To do this in plugin, you have to spin node inside onInstancePass method (_timer has type of rclcpp::TimerBase::SharedPtr):Code: Select all
void Plugin::onInstancePass(const sim::InstancePassFlags &flags, bool first) { rclcpp::spin_some(this->get_node_base_interface()); }
this->get_node_base_interface()
?Doesn't the plugin (assuming you started of the CoppeliaSim ROS2 plugin) allready call
spin_some
? What is your change about?Hard to tell, without understanding your use-case :-)
Cheers