## how to run simulations circularly and automatically

Typically: "How do I... ", "How can I... " questions
Matthew Qi
Posts: 19
Joined: 31 Aug 2017, 02:11

### how to run simulations circularly and automatically

Hi,

I am using V-REP with Python API to simulate the walking process of my robot, to make the robot perform perfectly, I have to adjust some parameters which could be a heavy work. So I want to run the simulation circularly and adjust these parameters automatically to find the optimums.

But I have no idea to make it in V-REP, could you give me some examples or any tutorials?

Yours,
Matt

coppelia
Posts: 7908
Joined: 14 Dec 2012, 00:25

### Re: how to run simulations circularly and automatically

Hello Matt,

the best for that is to use a customization script, that will adjust various parameters when simulation is not running, and that will listen to some signal or other trigger to start and stop a simulation. That customization script could also interact with a remote API client, a ROS node, or a BlueZero node (will be available in V-REP 3.5.0, to be released within 1-3 days).

Cheers

Matthew Qi
Posts: 19
Joined: 31 Aug 2017, 02:11

### Re: how to run simulations circularly and automatically

Hi,

Do we have any examples about customization scripts that I can refer to?

coppelia
Posts: 7908
Joined: 14 Dec 2012, 00:25

### Re: how to run simulations circularly and automatically

Have a look at the following models for instance:
• Models/tools/rosInterface helper tool.ttm
• Models/tools/simulation stepper tool.ttm
Cheers

Matthew Qi
Posts: 19
Joined: 31 Aug 2017, 02:11

### Re: how to run simulations circularly and automatically

Hi，
Though have read the rosInterface helper tool.ttl, I still have no idea how to write customization script interface with Python.

And I am wondering if you've misunderstanding what I mean, I think it's better to write code in Python API to make simulation keep running circularly and change parameters to find the optimum.

Thanks

coppelia
Posts: 7908
Joined: 14 Dec 2012, 00:25

### Re: how to run simulations circularly and automatically

What I meant to say:

From Python (or in general from an external application) you are much more limited in what you are able to do. But you don't have that limitation from a script running in V-REP. For that reason it is often a good idea to handle the more complex things from within a script, and have the external application just trigger specific routines or behaviours in the script.

Basically, a script can run hand-in-hand with an external application, whether it is a remote API client, a ROS node, or a BlueZero node.

Cheers

Matthew Qi
Posts: 19
Joined: 31 Aug 2017, 02:11

### Re: how to run simulations circularly and automatically

Hi，

Let's make it concretely. Suppose we have two variables , a = [0,10] and b =[1,5], in Python Remote API, we begin simulations when a = 0, b =1, every time when simulation stop , a and b should both plus one , a = 1 and b = 2, and then simulation start again.

So how could I change the value of a and b in the customization script, some sample code would be the best.

And I'm also wondering if there have any method to save data(such as the torque of joint) automatically, rather than by export the graph into CSV by hand

coppelia
Posts: 7908
Joined: 14 Dec 2012, 00:25

### Re: how to run simulations circularly and automatically

If you run in synchronous mode, then you'll be triggering each simulation step from your remote API client. Then, inside of your customization script, in a sensing section, i.e.:

Code: Select all

function sysCall_sensing()
a=a+1
b=b+1
end

you could be incrementing your values. sysCall_sensing() is called exactly once for each simulation step.

To say data, best is to do that yourself inside of a child script or customization script: you'll simply have to open a file, and write data to that file, then close that file at the end of a simulation.

Cheers