Synchronization of MATLAB Control Loop In CoppeliaSim

Typically: "How do I... ", "How can I... " questions
Post Reply
Miky
Posts: 2
Joined: 28 Apr 2021, 21:04

Synchronization of MATLAB Control Loop In CoppeliaSim

Post by Miky »

Hi Coppelia,

I am trying to synchronize my MATLAB control loop with CoppeliaSim using synchronous mode.

The idea is to simulate a CoppeliaSim robot with a MATLAB controller under 10 Hz. The simulation time step in CoppeliaSim is set as 100 ms. However, after sending 10 control update triggers from MATLAB, I noticed that CopperliaSim actually runs my controller at a rate of 100 Hz. That is, after sending 10 control triggers with a commanded moving velocity of 1 m/s, my robot only moved 0.1m instead of 1m.

I wonder, if this is an underlying feature of Coppeliasim, or I am just doing something wrong here?

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

Re: Synchronization of MATLAB Control Loop In CoppeliaSim

Post by coppelia »

Hello,

I am suspecting that you are sending the trigger signal several times during one simulation step. Make sure that one simulation step is done, before sending the next trigger. To do that you could imaging having a non-threaded child script that increments an integer signal (via sim.setInt32Signal) in the sensing section, in each simulation step. On your client side, you can then stream that integer signal and detect that way if your simulation step has executed. This is what is done in the demo scene scenes/messaging/pControllerViaRemoteApi.ttt that works with the python client located in programming/remoteApiBindings/python/python/pController.py

Cheers

Miky
Posts: 2
Joined: 28 Apr 2021, 21:04

Re: Synchronization of MATLAB Control Loop In CoppeliaSim

Post by Miky »

Hi,

I implemented the python code you mentioned from "programming/remoteApiBindings/python/python/pController.py" in Matlab. I still had the same results. Clearly, I am not sending the multiple triggers during one simulation step.

In a simple case of actuating a Pioneer robot with the desired motor velocity of 0.5 m/s under simulation time dt = 100 ms, after sending 10 triggers, I noticed the robot moved approximately 0.05 m instead of 0.5 m (100 ms x 10 triggers x 0.5m/s). This implies that the actuation time was approximately 100 ms (10 ms x 10 triggers). Is it true that the controller update in CollepiaSim is much faster than the actual simulation update (100 ms in this case)?

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

Re: Synchronization of MATLAB Control Loop In CoppeliaSim

Post by coppelia »

You should have a look what the simulation time in CoppeliaSim says: if your simulation time step is 100ms, and you trigger 10 individual steps, then your simulation time should then be at 1 second (your robot could be wrongly configured, etc.).

Maybe you can share a minimalistic scene that illustrates your problem.

Additionally, use the add-on Simulation stepper (make sure you have CoppeliaSim V4.2.0 or later). Otherwise you can find a stepping tool in the model library Models/tools/. Then try to step the simulation manually 10 times, and see if you reach the same simulation stage.

Cheers

Post Reply