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.
  3 Comments
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.
Thanks,
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,
Shivam

Sign in to comment.

Answers (1)

Sanchari
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: https://www.mathworks.com/help/simulink/slref/simulationpacingoptions.html
The following links may be useful as well:
  1. ROS Toolbox support package for TurtleBot-based robots (File Exchange): https://www.mathworks.com/matlabcentral/fileexchange/55578-ros-toolbox-support-package-for-turtlebot-based-robots?s_tid=answers_rc2-2_p5_MLT
  2. Matching Simulink time with ROS time in co-simulation (ML Answer): https://www.mathworks.com/matlabcentral/answers/1604975-why-does-the-simulink-time-not-match-ros-time-in-co-simulation?s_tid=srchtitle
  3. Enable ROS Time Model Stepping for Deployed ROS Nodes (Documentation): https://www.mathworks.com/help/ros/ug/enable-ros-time-model-stepping-for-deployed-ros-nodes.html
  4. Simulate State Space model using live inputs coming from Gazebo environment (ML Answer): https://www.mathworks.com/matlabcentral/answers/827080-is-it-possible-to-simulate-state-space-model-using-live-inputs-coming-from-gazebo-environment?s_tid=srchtitle
  5. Synchronise Simulink node with PX4 SITL-ROS-Gazebo: https://www.mathworks.com/matlabcentral/answers/789749-synchronize-simulink-node-with-px4-sitl-ros-gazebo?s_tid=srchtitle
  6. Speeding up co-simulation between Gazebo and Simulink: https://www.mathworks.com/matlabcentral/answers/750999-on-speeding-up-co-simulation-between-gazebo-and-simulink?s_tid=srchtitle
Hope this helps!

Categories

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

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!