Synchronize Simulink node with PX4 SITL - ROS - Gazebo
Show older comments
Hi all,
I'm trying to synchronize my simulink model with px4 SITL ( ROS and gazebo). Is there a good way to ensure that the simulink node staying sync with ROS - Gazebo time? I'm running on ubuntu 18.04 with ROS and gazebo9, matlab 2020b.
I tried few things:
- Use pacing simulation while running the node, but it can't run at real time above 50 [Hz] (it start to shift and looses its sync after few steps). I tried to slow down the px4 SITL but it dosent ensure sync with the simulink node.
- Build the model from simulink and generate standalone ROS node: the node was very senstive to my fix-step choise - I couldn't make it perfecly sync with px4 SITL.
- Build the model from simulink and generate standalone ROS node with "enable ros time simulation stepping": it gives my a "FATAL" error when trying to run the node, unless my fix-step time is exactly the /clock frequency (even not a multiply of this frequency). Is there a way to change the /clock frequency or choose some multiply of this frequency?
Ill appreciate any help,
Thanks,
Iftach.
Answers (2)
Abhijeet Gadkari
on 3 May 2021
1 vote
Hello Iftach,
Option 3. seems the closest to achieve an almost "real-time" execution of your algorithm.
Typically setting the fixed-step size of the model to a multiple of /clock topic publish rate should be sufficient.
However, owing to the complexity of the issue, could you please contact technical support for further assistance?
Thanks.
Abhijeet
1 Comment
Iftach Naftaly
on 3 May 2021
Jakobus Louw
on 17 Jun 2021
1 vote
You can syncronise Gazebo and Simulink with the Gazebo Pacer block in Simulink and a GazeboPlugin (provided by MathWorks) in your world file as described in the link.
I have managed to do that by launching a .world file and running a simulink model in sync with it.
However, the Gazebo Pacer block resets time in Gazebo which causes PX4 to stop.
So I am going to try starting Gazebo first, then sync with Simulink, then connect PX4. Ill update you if it works.
Please let us know if you find a solution.
6 Comments
Jakobus Louw
on 17 Jun 2021
So use the Gazebo Pacer block in your Simulink model to sync stepping between Gazebo and Simulink. The process is discribed here: https://www.mathworks.com/help/robotics/ug/perform-co-simulation-between-simulink-and-gazebo.html
Then edit the GazeboPlugin to NOT reset time in Gazebo because this crashes PX4. Do this by uncommenting one line as discribed by this answer: https://www.mathworks.com/matlabcentral/answers/504617-how-to-prevent-simulink-pacer-from-resetting-ros-time
Iftach Naftaly
on 18 Jun 2021
Diego Rojas
on 26 Oct 2021
I was wondering if you have managed to get this to work. I too am looking to do something similar with the Gazebo Pacer and am curious if your nodes worked after starting Gazebo, then Simulink, then PX4.
Best,
Diego
Jakobus Louw
on 27 Oct 2021
If I remember correctly, I could not get Gazebo to start before PX4. PX4 starts first, then connects to Gazebo.
However, I editted the Pacer block and commented out the line of code that resets Gazebo time. That solved the issue and I could use a PX4 SITL with the Pacer block in Simulink
Diego Rojas
on 28 Oct 2021
Edited: Diego Rojas
on 28 Oct 2021
Gotcha,thanks @Jakobus Louw! The issue I am having is that when I start the simulink model + gazebo pacer, the gazebo simulation switches from unpaused to paused. Line 11 in GazeboWorldImpl.cpp seems to pause gazebo. This then effects my ros nodes such as my camera data, and stops publishing data. Curious if you ran into this issue?
Jakobus Louw
on 28 Oct 2021
Edited: Jakobus Louw
on 28 Oct 2021
I did not run into that issue.
Are you sure it pauses it? I remember when I ran Simulink with Gazebo it ran much slower than 1x speed. Maybe it just looks paused? Also, Gazebo and Simulink are then synced, but I dont know if ROS is then also synced with Gazebo
Categories
Find more on PX4 Autopilots 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!