Matlab/Simulink - Gazebo -Co-Simulation - rosbag
2 次查看(过去 30 天)
显示 更早的评论
Hey,
im planning to do a CO-Simulation with Matlab/Simulink and Gazebo with the ROS-Toolbox in Simulink. There is a specific tool named 'Gazebo Pacer' which synchronize Gazebo simulation with the time step of Simulink. Do you have any idea to play a rosbag under this circumstances?
For clarification. I want to play a rosbag, since i press the start button in Simulink. One approach was to add the rosbag in the launchfile which is launching the whole gazebo environment. But if i do this, the playback starts immediately. But i want to start it with the play button from Simulink. Furthermore, i couldn't figure out a way to synchronize the rosbag and the simulink timestep.
Is there a possible solution for it? Or have anyone similiar problems? Maybe there is an approach with the c++ api? I'm very interested in a solution or at least a solution suggestion...
0 个评论
回答(1 个)
Cam Salzberger
2020-4-22
Hello Matthias,
One suggestion is to use the Read Data block from ROS Toolbox in your Simulink model. This is designed to output messages for a selected topic from the rosbag, synchronized with the Simulink simulation time. You can run the output to an Enabled Subsystem with a Publish block inside. You can set up multiple Read Data + Enabled Subsystem + Publish combinations if you need multiple topics out of the rosbag.
-Cam
2 个评论
Cam Salzberger
2020-4-24
I'm a little confused about what you are asking for (not sure what you mean by "time error"), but I can try to provide more information that may help get towards solutions.
The intent behind the Read Data block design is to be similar to the Subscribe block. This allows users who want to test their system with recorded data or live data from a robot to easily switch the data input mechanism. Thus, the sampling of the data is similar to the way the Subscribe block works, which may cause some downsides for your use-case. If you have a Subscribe block, and data is being published at 15 Hz, but the sample time of the Subscribe block is 0.1, then (if you synchronize simulation time to real time) you will miss some messages, and only the most recently received message is output at a given timestep. The Read Data block will behave similarly, outputting the most "recent" message based on the rosbag timestamp (offset from the start of the bag) compared to the simulation time.
If you would like to ensure that you are sending all of the messages from the rosbag, you will need to select the block sample time such that it is smaller than the smallest gap between messages. It's been a while since I've worked with it, and can't verify right now, but I believe the topic selection dialog provides this "minimum gap" information for each topic to help this workflow. Alternatively, I believe you can use Variable sample time (-2), which will calculate the sampling time for each step based on when the next message is. This has some dependency on the simulation step size though, which I can't recall offhand.
If you are trying to have the Read Data block sample faster than the Gazebo Pacer block, is there any reason you can't just set the sample times in that way (i.e. Read Data -> 0.01, Gazebo Pacer -> 0.1)?
-Cam
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gazebo Co-Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!