フィルターのクリア

Matlab/Simulink - Gazebo -Co-Simulation - rosbag

1 回表示 (過去 30 日間)
Matthias B
Matthias B 2020 年 4 月 21 日
コメント済み: Cam Salzberger 2020 年 4 月 24 日
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...

回答 (1 件)

Cam Salzberger
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 件のコメント
Matthias B
Matthias B 2020 年 4 月 23 日
Hello Cam,
thanks for your answer. I was very excited to hear your answer.
I tried your solution and it works fine, at the first glance. But I evaluated this time synchronization by differenciating rosbag time and simulink time. I have an amount of time error which let me conclude that this solution is not quite synchron.
My setting:
ROS Bag block -> sample time: 0.1
ode1 solver -> sample time: 0.01
Gazebo Pacer -> sample time: 0.1
I want to achieve an time error less then 0.1 or in other words, less then sample time of the pacer... Do you have any further suggestions? I think I did a crucial mistake...
P.S.: Same result with enables subsystem..
Cam Salzberger
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 ExchangeROS Log Files and Transformations についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by