Starting a sim from halfway through?

Typically: "How do I... ", "How can I... " questions
Post Reply
RobAtLab
Posts: 92
Joined: 10 Jan 2018, 17:49

Starting a sim from halfway through?

Post by RobAtLab »

I'd like to take a "copy" of a v-rep sim from mid-action, part way through a process. I'd like to save this state of the whole simulation, including the values of all variables within all child scripts on all objects with such scripts. I'd then like to be able to take copies of this saved sim and start them, in such a way that the init functions on each child script do NOT run this time and hence do NOT overwrite any variables which were set in the init functions when the sim first started but later edited from within the actuation steps.

I want this so that I can set up a scenario, run it to part way through and then run a variety of different simulations starting from that midway point, each having different random perturbations applied to certain random behaviour variables within child scripts.

I don't need a fully automated way to do this, there will only be a few different starting scenarios which I need to do this to so I can make each one manually, but then I'd like to be able to start these "saved half way through" simulations from a commandline command such as

./vrep.sh -g0.62 '/home/filePath/V-REP_PRO_EDU_V3_5_0_Linux/scenes/name_of_file.ttt' -s100000 -q

When that command has run, and V-REP quits I would NOT want the "saved half way through" file to be modified, because I'd like to run that command again later with, for example, a different -g value, so as to produce my other simulation results.

Can this be done? Are there tricks involving cleverly pausing the simulation which can enable this saving of a half-completed sim to a file?

Thank you

P.S. I'm working in VREP 3.5 on linux, but might be able to update (if the newer versions are still compatible with my PC) if later versions of V-REP or CoppeliaSim can do this when 3.5 cannot, Thanks

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

Re: Starting a sim from halfway through?

Post by coppelia »

Hello,

what you are trying to do is difficult, specially the part where you want all script variables (i.e. the various script states) to be saved.
For the variables, you'd have to identify which variable needs saving/restoration, and program a logic that would allow you to do this. There is no built-in way of doing this. e.g. you could in the very last simulation step (or in the last simulation step before a pause) save all appropriate variables to file. Next time you start a simulation, you'll first restore those variables from file. All Global Lua variables are stored in variable _G, but that will really include everything. So the best is probably if all your variables are put into a table, e.g. like:

Code: Select all

myVars={}
myVars.speed=1.23
myVars.params={1,2,'hello'}
...
You can then easily serialize/deserialize those variables with:

Code: Select all

serializedData=sim.packTable(myVars)
...
myVars=sim.unpackTable(serializedData)
You'll also have to save/restore object states where it makes sense, e.g. object position/orientations, parent-child relationships, etc.

Cheers

RobAtLab
Posts: 92
Joined: 10 Jan 2018, 17:49

Re: Starting a sim from halfway through?

Post by RobAtLab »

Given how lua is an interpreted language where a variable can spring in to being anywhere, not a compiled one like C where special easily recognisable declaration statements exists within the code, is there any trick for easily locating the variables. The code my robots run is quite complex and finding all the variables in it isn't too pleasant a task, especially working out exactly which can be chanegd at what times and therefore do or don't need saving like this.

Also objects locations, child relationships, existence of dummy-dummy connections, positions of joints... How would these be saved, is there an easy way? There are quite a lot of them involved in my scenes.

Thank you

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

Re: Starting a sim from halfway through?

Post by coppelia »

All Global Lua variables are stored in variable _G. It will contain exerything, all sim.-api functions, all global variables, etc. You can't store and restore a function. So you'll have to skip those. And you'll also have to skip a few variables that are being used by the system. I think it is much more work to go that path, than to nicely group all your global variables in a table.

Since currently CoppeliaSim isn't made to allow for resume of a simulation after saving it, you'll have to decide what items/properties/parameters have changed and store/restore them. E.g. the current velocity of dynamically enabled objects, etc. Of course you'll also have to uncheck Reset scene to initial state item in the simulation dialog.

Cheers

Post Reply