‘If you want to impose the same duration for all your dynamic simulations, the best option is to set ‘Simulation.tDuration’ to the desired value in the appropriate solver BIC file:
R.merge('Simulation.tDuration',5);
If, on the contrary, you would like to impose various durations to your dynamic simulation, it is better to control the simulation duration through the GUI using a new block state (e.g. ‘Boat.SimTime’). You can then create an in-line module which will stop the simulation after ‘Boat.SimTime’ seconds:
R.merge("Blocks." + boatSpec.Name, {
"SimTime" : BL.State({Init : 5}),
});
// In-line module to stop simulation after 'Boat.SimTime' seconds
R.merge("Modules.Stop"+boatSpec.Name, function(){
return {
preUpdate : function(callType)
{
if (callType && ((callType & G.CallTypes.DYNAMICS_MAJOR) || (callType & G.CallTypes.DYNAMICS_MINOR)))
{
if (Z('Time') > Z('Boat.SimTime')) // stop time in seconds
// if (Z('Time') > 2) // stop time in seconds
{
print('Stop');
Host.stopRequested();
}
}
}
};
}());
Note: More information about Modules and the Simulation object can be found in the Gomboc user guide.