Synchronization Between Robot and Simulink

15 views (last 30 days)
Shivam Bajpai
Shivam Bajpai on 2 Jun 2023
Answered: Sanchari on 9 Feb 2024
Good afternoon, everyone,
I am working on a path-tracking problem (deploying algorithm on Turtlebot3 (TB3) robot using ROS Noetic) using different controllers. Even though everything is fine in my model, I am facing synchronization time problem between TB3 and Simulink. In the attached image, the red circled signals ( from Motive subsystem: real time states of the robot from motion capturing system) are the real time states (x, y and theta) of the robot and green circled are the reference signal (from waypoints substem) in x and y respectively. When I do experiment, robot is moving faster than reference signal, in other words, TB3 is reaching the goal location before reference signals which is utterly undersirable and because of which it is not tracking the reference path precisely. Kindly guide be how can I synchronise time of both robot and reference signal.
Jagadeesh Konakalla
Jagadeesh Konakalla on 6 Jun 2023
Hi Shivam,
Can you try the Pacing option in the simulink ?
Let me know if this helps.
Jagadeesh K
Shivam Bajpai
Shivam Bajpai on 14 Jun 2023
Hello, Sir,
Sorry for the late reply. I tried the above solution but, still reference signal is slower than the real robot. I don't know how it can be possible even I am giving low linear and angular velocities to robot which are 0.22m/s and 2.84 rad/sec. I tried real-time synchronization as well but it also didn't work.
Thank you,

Sign in to comment.

Answers (1)

Sanchari on 9 Feb 2024
Hello Shivam,
Synchronization issues between a robot and reference signals in Simulink often arise due to discrepancies in the execution rates of the Simulink model and the robot's control loop. Here are some steps you can take to address synchronization issues:
  1. Control Loop Rate Matching: Ensure that the control loop rate in Simulink matches the control loop rate of the TB3. If the TB3 is executing its control loop faster than Simulink, the robot will reach its goal before Simulink updates the reference signals. You can adjust the sample time of the blocks in Simulink to match the TB3's control loop rate.
  2. ROS Time: Use ROS time, ros::Time::now(), instead of wall-clock time to ensure that all time-dependent operations are based on the ROS clock.
  3. ROS Rate: In your ROS nodes, use ros::Rate to control the rate of your control loop. This will help ensure that your robot's control commands are issued at a consistent rate.
  4. Simulink Pacing: As suggested before in the comments, use the Simulink Pacing to slow down the simulation to real-time/ desired execution rate. This can be found in Configuration Parameters under the Solver section. Enable "Pacing to slow down simulation" and set the desired pace.
  5. External Mode: If you're using Simulink's external mode for real-time execution on hardware, ensure that the communication interval is set appropriately to match the TB3's control loop rate.
  6. Buffering and Interpolation: If there's a delay in receiving the real-time states from the motion capturing system, consider buffering the data and using interpolation to estimate the states at the exact time steps needed by the control algorithm.
  7. ROS Synchronization Tools: Use ROS synchronization tools such as message_filters or tf2 to synchronize messages that are supposed to arrive at the same time but may be subject to network delays or processing time differences.
  8. Adjust Reference Trajectory Generation: If the reference trajectory is generated too slowly, consider precomputing the entire trajectory or larger segments of it, so the TB3 does not have to wait for new reference points.
  9. Hardware Timing: Investigate any hardware-induced latencies or timing issues that might affect the synchronization, such as delays in the motion capturing system or communication delays between the TB3 and the computer running Simulink.
  10. Diagnostics and Logging: Use ROS diagnostics and Simulink data logging to analyse the timing of various components in your system. Look for discrepancies in the timestamps of messages and execution rates.
Please refer to the following MathWorks Documentation for information on Simulation Pacing Options:
The following links may be useful as well:
  1. ROS Toolbox support package for TurtleBot-based robots (File Exchange):
  2. Matching Simulink time with ROS time in co-simulation (ML Answer):
  3. Enable ROS Time Model Stepping for Deployed ROS Nodes (Documentation):
  4. Simulate State Space model using live inputs coming from Gazebo environment (ML Answer):
  5. Synchronise Simulink node with PX4 SITL-ROS-Gazebo:
  6. Speeding up co-simulation between Gazebo and Simulink:
Hope this helps!


Find more on Network Connection and Exploration in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!