How to start and stop the simulator externally

Typically: "How do I... ", "How can I... " questions
Post Reply
TrimItOut
Posts: 12
Joined: 01 Dec 2020, 18:39

How to start and stop the simulator externally

Post 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!

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

Re: How to start and stop the simulator externally

Post by coppelia »

Hello,

did you have a look at this thread?

Cheers

TrimItOut
Posts: 12
Joined: 01 Dec 2020, 18:39

Re: How to start and stop the simulator externally

Post 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

Post Reply