Forum

Forum Navigation
You need to log in to create posts and topics.

Is there a way to pause python script until Dorna movement is completed?

We are working on our senior design project and we are turning valves on and off in tandem with the movement of the robotic arm. We want to know if there is a way to stop the computer from reading through the whole script before each individual movement is finished. For example, we turn the valve on, then have the robot move, then turn the valve off. The problem is that we currently have to use a time.sleep() command  for the amount of time the robotic movement takes in order to pause the script until we want the valve to turn off. Also, we are not using the Dorna command box for control of the valves, we are using an Arduino and then using PySerial in order to communicate with the Arduino.

We believe this is causing a lot of issues since the computer is reading through the whole program before the robot has actually finished its movements. So we want the robot to work like this --> turn valve on, robot moves & and script is paused while waiting for the robot to finish moving, turn valve off, repeat. We don't want to have to manually time each movement and use the time.sleep() command.... we also are not much of programmers, just got stuck with this project!

@timothy-dau using time.sleep() is not a good practce.

The best way to handle this is to check the status of commands you have submitted in a while loop and see if the command has been executed or not

Another option is to check the state of the robot and see if it is still running any command or not

https://github.com/dorna-robotics/dorna/wiki/api#general-status

from dorna import Dorna

import json

robot = Dorna()

robot.connect()

robot.play(#some tasks)

while True:

device = json.load(robot.device)

if device["state"] == 0:

# tasks are executed entirely

break

time.sleep(0.001)

robot.play(#other tasks)