0
$\begingroup$

Gazebo Answers logo

I am trying to execute several steps of Gazebo7 simulation by sending a msgs::WorldControl message to Gazebo where simulation is paused. In effect, I aim to advance the simulation by a varying amount of time. However, regardless of what number I pass using msg.set_multi_step(m_stepCount), I cannot seem to advance by more than 1 iteration.

Did I misunderstand what multi_step does?

Relevant code excerpt from one of my experiments:

    void OnUpdate() 
    {
        // Throttle Publication
        gazebo::common::Time::MSleep(1000);

        m_step_count = m_step_count == 1 ? 700 : 1;

        msgs::WorldControl msg;
        msg.set_multi_step(m_step_count);
        this->pub->Publish(msg);

        // msgs::WorldControl stepMsg;
        // stepMsg.set_step(1);
        // this->pub->Publish(stepMsg);

        std::cout << "Publishing OnUpdate. Steps: " << m_step_count << std::endl;
    }

The result is that every second:

  • Iteration increases by 1
  • Sim Time increases by 00 00:00:00.001
  • Real Time is increased by 00 00:00:01.000
  • 700 or 1 are printed in the output string, alternating on every tick

Originally posted by LinasKo on Gazebo Answers with karma: 3 on 2018-08-14

Post score: 0


Original comments

Comment by LinasKo on 2018-08-15:
The issue has been solved, but I will keep this question open for answers regarding the effects of setting the multi_step field.

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

If you're using a world plugin, OnUpdate is called at every iteration within the physics thread. So I think what's happening is that you're introducing a 1 s sleep to every iteration - it will take 700 s until your 700 steps are processed.

I recommend you use a standalone program like this one so you don't block the physics thread.


Originally posted by chapulina with karma: 7504 on 2018-08-14

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by LinasKo on 2018-08-15:
Is there a specific reason to not block the physics thread, as it seems to be exactly what I want to do. Basically, for cross-compatibility with another product I'm working on, I want to Sense -> run physics for time t0 -> Drive -> run physics for time t1 -> Repeat

Comment by LinasKo on 2018-08-15:
Ultimately, with your help, I think figured it out. I have removed MSleep and will block the OnUpdate until a volatile boolean value is updated from another thread, resuming the simulation, instead of trying to advance it by setting multi_step.

I am aware this might not be the best solution in the long term and will be investigating the more usual way of running it asynchronously as well. Thank you.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.