lpzrobots icon indicating copy to clipboard operation
lpzrobots copied to clipboard

Use of restart()

Open SimonBirrell opened this issue 7 years ago • 1 comments

Hi,

I have a question about the usage of restart() when subclassing Simulation.

The main loop in simulation.cpp starts like this:

 while ( ( noGraphics || !viewer->done()) &&
            (!simulation_time_reached || restart(odeHandle,osgHandle,globalData)) ) {

Two issues. First of all, setting restart() to return TRUE doesn't always exit this look, because of the logic of the condition. Secondly, restart() is often not called at all! I think that's because if C++ figure that !simulation_time_reached is TRUE then there's no point in executing restart().

I would propose the following:

 while ( ( noGraphics || !viewer->done()) &&
            (!simulation_time_reached && restart(odeHandle,osgHandle,globalData)) ) {

This seems to work for me. If I return TRUE, the main loop exits. If I return FALSE it doesn't. The restart() function always gets executed (unless the loop is exitting for some other reason).

What do you think?

Thanks

Simon

SimonBirrell avatar Nov 01 '18 15:11 SimonBirrell

Hi Simon, I think the original logic was as follows: when the simulation time is reached the restart function is called to decide whether the it should restart or not. So a restart can be initated earlier by setting simulation_time_reached=true in the normal callback functions and then also returning true in restart, but I understand that your solution is maybe better.

Regards, Georg

On Thursday 01 November 2018 09:09:14 Simon Birrell wrote:

Hi,

I have a question about the usage of restart() when subclassing Simulation.

The main loop in simulation.cpp starts like this:

 while ( ( noGraphics || !viewer->done()) &&
            (!simulation_time_reached ||
restart(odeHandle,osgHandle,globalData)) ) { ```
Two issues. First of all, setting restart() to return TRUE doesn't always
exit this look, because of the logic of the condition. Secondly, restart()
is often not called at all! I think that's because if C++ figure that
!simulation_time_reached is TRUE then there's no point in executing
restart().

I would propose the following:

while ( ( noGraphics || !viewer->done()) && (!simulation_time_reached && restart(odeHandle,osgHandle,globalData)) ) { ```

This seems to work for me. If I return TRUE, the main loop exits. If I return FALSE it doesn't. The restart() function always gets executed (unless the loop is exitting for some other reason).

What do you think?

Thanks

Simon

-- ---- Georg Martius, Tel: +49 177 6413311 ----- --------- http://georg.hronopik.de -------------

georgmartius avatar Nov 01 '18 20:11 georgmartius