How to add Delay in python script in simulation time

Typically: "How do I... ", "How can I... " questions
Post Reply
shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

How to add Delay in python script in simulation time

Post by shadowzone »

Hello, i wanted to know how to add delay in my python script that results in delay in simulation time because my system is a bit slow if i use python's time.sleep() python might run faster than the simulation which will lead to wrong delay times, i need so send setJoint in specific intervals
i was going to use simWait but found out there is no record of it in python apis

so is there anything equivalent to time.sleep to give me delay in real simulation time ?
Few notes:
i do NOT want to stop the simulation, i just want to send signals /run my code at specific intervals in simulation time

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

Re: How to add Delay in python script in simulation time

Post by coppelia »

Hello,

you should use the synchronous mode in that case: the synchronous mode allows your remote API client to trigger each simulation step, as needed. Have a look at the example:
  • with the B0-based remote API: programming/b0RemoteApiBindings/python/synchronousImageTransmission.py
  • with the legacy remote API: programming/remoteApiBindings/python/python/synchronousImageTransmission.py
Cheers

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: How to add Delay in python script in simulation time

Post by shadowzone »

thank you for your answer,

i tried running the script and it only works one time and it doesn't run again until i restart my laptop, restarting the program or the script does nothing, i would like to know why
im runnin coppeliaSim v4.0 on ubuntu 16.04
After reading the code example i have a question does the simulation step increment in dt(default 50ms) in simulation time ? is this what this function do in the remote api binding example? "stepSimulation()" meaning if i want a delay of 100 ms between readings should i get a reading then step 2 times(assuming dt=50ms) does that mean i have 100ms delay in simulation time?
im still new to synchronous mode so if there is a documentation you can guide me to that would be great

fferri
Posts: 1222
Joined: 09 Sep 2013, 19:28

Re: How to add Delay in python script in simulation time

Post by fferri »

Synchronous mode is described at:

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: How to add Delay in python script in simulation time

Post by shadowzone »

okay great, but it seems that there is a bug on ubuntu, i tried installing coppeliaSim on windows and the script/scene worked fine but for some reason in ubuntu 16.04 the script only works once and only works again if a restart my pc so any ideas why is that?

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: How to add Delay in python script in simulation time

Post by shadowzone »

Upon further testing i looked at the terminal of coppeliaSim while running the script and this poped up the first
Image

if i rerun the script after its done it doesnt do the initialization any more

and the code doesnt stop
this is a trial after running the code the first time and closing and openning coppeliaSim
Image


also if i close coppeliaSim after the first time and try to run the script (without opening it again) it says "Running" and "Connected to remote api" which i dont think its right
Last edited by shadowzone on 31 Mar 2020, 16:42, edited 1 time in total.

fferri
Posts: 1222
Joined: 09 Sep 2013, 19:28

Re: How to add Delay in python script in simulation time

Post by fferri »

BlueZero needs the b0_resolver process to be running in order to function correctly.

If b0_resolver is not found, it is launched by CoppeliaSim (those lines with [resolver] you see in the console).

You can also try to kill the b0_resolver process (i.e. killall b0_resolver and see if it makes a difference, or killall -9 b0_resolver if it is stuck) and repeat the previous steps.

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: How to add Delay in python script in simulation time

Post by shadowzone »

okay first of all im using the script in remoteApibindings folder not the bluezero one i dont know if this makes a difference and when i tried to kill the resolver as u said it says no processes found and still wont initialize stuff same as before unless i restart my pc

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: How to add Delay in python script in simulation time

Post by shadowzone »

upon further testing synchronous mode stuff (like simple synchronous test) it seems like something is still open,
when i try to run any sync script before opening coppeliaSim it fails as expected, but if i run coppeliasim with a sync scene and script and then close the scene and coppelia sim ,
and try to run the simple sync test again , it somehow sees as if coppeliaSim is opened , so i think there is some sort of process/service that still runs in the background even after closing coppeliaSim but doing the killall b0_resolver returns no processes found so it might be something else

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: How to add Delay in python script in simulation time

Post by shadowzone »

shadowzone wrote: 31 Mar 2020, 16:34 Upon further testing i looked at the terminal of coppeliaSim while running the script and this poped up the first
Image

if i rerun the script after its done it doesnt do the initialization any more

and the code doesnt stop
this is a trial after running the code the first time and closing and openning coppeliaSim
Image


also if i close coppeliaSim after the first time and try to run the script (without opening it again) it says "Running" and "Connected to remote api" which i dont think its right
Okay so i was able to make the nodes run like the first image here everytime, by closing coppeliaSim properly and not by killing its terminal , but still the code runs properly once/boot and upon closing coppeliaSim the code still detects and connects to it somehow

Post Reply