## Multiple Simulation Episodes

Typically: "How do I... ", "How can I... " questions
fairread
Posts: 9
Joined: 13 Aug 2013, 15:37

### Multiple Simulation Episodes

Hi I wish to implement some AI algorithms on robot navigation from an initial position to a goal position in V-REP. I, however need to run multiple numbers of simulations sequentially (one simulation scene after another) After the first simulation episode finishes (by timeout or reaching goal position), I would like a new simulation episode to begin with the robot having some stored memory from the past episode and it will start at the similar initial position. How may I do this in V-REP? Thanks.

coppelia
Site Admin
Posts: 7517
Joined: 14 Dec 2012, 00:25

### Re: Multiple Simulation Episodes

Hello,

you have several ways of achieving this, for instance:
• in the simulation dialog, you could uncheck Reset scene to initial state. That way, at the end of the simulation, the scene will not be reset.
• you can also disable individual robots or models from a reset at simulation end. In a child script attached to the base of a model, you could have following code:

Code: Select all

if (simGetScriptExecutionCount()==0) then
base=simGetObjectAssociatedWithScript(sim_handle_self)
p=simGetModelProperty(base)
p=simBoolOr16(p,sim_modelproperty_not_reset)
simSetModelProperty(base,p)
end
When loading a new scene, you will have however to store the robot (or model) temporarily to a file, load the new scene and load the saved model into that scene. Have a look at following API functions:
simLoadScene can only be called from a plugin, an add-on, a remote API client or a ROS node (child scripts are only executed DURING simulation).

Or you can save only state data of the robot like position and orientation. That data you can save/load it to/from a file, to a persistent data block, or to script simulation parameters (in that case the parameter should be flagged as Parameter is persistent)

Cheers

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

### Re: Multiple Simulation Episodes

Hi!

Maybe you can simply "teleport" your robot at the initial position after each timeout or reached position, and restart your AI navigation algorithm?

To "teleport" your dynamic enabled robot at the intial place you can do the following code:

Code: Select all

--moving the dynamic object
t={robotHandle}
while (#t~=0) do
h=t[1]
simResetDynamicObject(h)
table.remove(t,1)
ind=0
child=simGetObjectChild(h,ind)
while (child~=-1) do
table.insert(t,child)
ind=ind+1
child=simGetObjectChild(h,ind)
end
end
--moving the robot to the initial position  and orientation (i.e. where the simulation started)
simSetObjectPosition(robotHandle,-1,initialPosition)
simSetObjectOrientation(robotHandle,-1,initialOrientation)


fairread
Posts: 9
Joined: 13 Aug 2013, 15:37

### Re: Multiple Simulation Episodes

Hi Admim and Eric,

Thanks for your replies, sorry I could only reply now as I went for a holiday earlier.

To Admin, I appreciate your idea to uncheck Reset Scene to Initial State, but may I know what is the way to automate the run of multiple simulation episodes? For example, let say I would like to run 20 episodes sequentially by starting the simulation today, leaving the pc running the whole night and then obtaining the results tomorrow morning. I have the basic idea of creating a script to run automated restarting of a new scene but I do not know how it could be implemented explicitly in V-REP.

In that context, I appreciate Eric's suggestion of running only single scene and whenever the robot reaches the end position or timeout occurs, it will be teleported back to the initial position. I would then need to create an episode counter which will be incremented once timeout occurs or robot reaches end position. If counter reaches 20, then the simulation scene should be terminated.

But I also welcome any suggestion to automate scene restart using scripts if you guys may have. Thanks again.

coppelia
Site Admin
Posts: 7517
Joined: 14 Dec 2012, 00:25

### Re: Multiple Simulation Episodes

Hello,

the best for your task is to use an add-on script since they also run when simulation is stopped. From that add-on script you can then load a scene, run/stop the simulation, etc.

Cheers

fairread
Posts: 9
Joined: 13 Aug 2013, 15:37

### Re: Multiple Simulation Episodes

Thanks for the suggestion, I'm trying to implement it now. Anyway, another question related to running multiple simulation episodes, is there any other way to accelerate the simulation speed apart from changing the dynamics engine, dynamic settings and simulation time step such as disabling the graphics, downscale to 2-D simulation or disabling the dynamics engine?

Thanks again!

coppelia
Site Admin
Posts: 7517
Joined: 14 Dec 2012, 00:25

### Re: Multiple Simulation Episodes

Hello,

Yes, you can:
• disable visualization. Check out the model Models/other/fast simulation mode.ttm, or the API function simSetBooleanParameter(sim_boolparam_display_enabled,false).
• disable dynamics. You can do this in the dynamics general settings. You can also individually disable models for dynamics simulation. Select the model, then open the model properties dialog. Check Model is static and Model is not respondable.
Cheers