Page 1 of 1

How to start and stop the simulator externally

Posted: 10 May 2021, 19:54
by TrimItOut
Hi,

I am trying to run a set number of trials of a simulation that I have created. Once the robot reaches the goal it stops the simulation so I am trying to create a piece of code that then starts the simulation again until the required number of trials has been reached.

I have tried to use the following code in the lua command line within CoppeliaSIm however it simply doesn't run the simulation whilst it is checking the simulator state inside the while loop.

Code:

Code: Select all

num_trials=10

for i=0,num_trials,1 do
  sim.startSimulation()
  print("trial number: "..i)
  while true do 
    if sim.getSimulationState()==0 then 
      break
    end
  end
end

print("ALL TRIALS finished")


Is there an easy solution to achieve this?

Thanks in advance!

Re: How to start and stop the simulator externally

Posted: 11 May 2021, 14:11
by coppelia
Hello,

did you have a look at this thread?

Cheers

Re: How to start and stop the simulator externally

Posted: 11 May 2021, 16:59
by TrimItOut
Exactly what I was looking for!

For anyone else looking for a similar solution I managed to implement the above functionality using an addon.

Documentation here: https://www.coppeliarobotics.com/helpFi ... addOns.htm

Thank you