Are simROS2 subscriber callback dependend on simulation dt or dynamics dt?

Typically: "How do I... ", "How can I... " questions
Post Reply
hedo
Posts: 4
Joined: 28 May 2024, 14:53

Are simROS2 subscriber callback dependend on simulation dt or dynamics dt?

Post by hedo »

Hi @all,

I want to control a robot via ros2 topics with high frequency. I managed to implement the publishing of message via dyamics_callback functions. However, my current implementation uses the simROS2 subscriber callback. I could not figure out when these callbacks are called.

Are simROS2 callbacks triggered by the main script? How can I trigger them by the physics engine?

Kind regards,

Heiko

coppelia
Site Admin
Posts: 10504
Joined: 14 Dec 2012, 00:25

Re: Are simROS2 subscriber callback dependend on simulation dt or dynamics dt?

Post by coppelia »

Hello,

as far as I can tell, you can't directly influence when the spin function is called internally: it is automatically called before each simulation step (among other). The only possibility you have would be to reduce the simulation dt to the same value as the dynamics dt. That will slow down everything, since every script will be called more often. Let me know how that works.

Cheers

hedo
Posts: 4
Joined: 28 May 2024, 14:53

Re: Are simROS2 subscriber callback dependend on simulation dt or dynamics dt?

Post by hedo »

Hi,

that is the problem. I reduced the simulation dt to the dynamics dt, but this makes the simulation too slow.
This gives me exactly the opposite of what I want to achieve. The message frequency is thus reduced.

Where is the scubscriber call handled in simROS2? Maybe I can find a fix in the plugin.

Kind regrards,

Heiko

coppelia
Site Admin
Posts: 10504
Joined: 14 Dec 2012, 00:25

Re: Are simROS2 subscriber callback dependend on simulation dt or dynamics dt?

Post by coppelia »

You can try to add a new API function to handle that (simROS2.spinSome):

In src/sim_ros2_interface.cpp:

Code: Select all

void spinSome(spinSome_in *in, spinSome_out *out)
{
    rclcpp::spin_some(node);
}
In meta/callbacks.xml:

Code: Select all

    <command name="spinSome">
        <description>Calls spin_some(node).</description>
        <params>
        </params>
        <return>
        </return>
    </command>
If that works fine, we can make this modification permanent.

Cheers

Post Reply