def activate(): if(ultrasonic.get_sample() < 10): both.turn(power=-70, tacho_units=400, brake=False) time.sleep(1) bx,by = get_ballxy() rx,ry,a = get_robotxya() turn_to(brick,bx,by,rx,ry,a) time.sleep(0.5) move_to(brick,bx,by,rx,ry) kickBall(brick,by) else: time.sleep(1) bx,by = get_ballxy() rx,ry,a = get_robotxya() turn_to(brick,bx,by,rx,ry,a) time.sleep(0.5) move_to(brick,bx,by,rx,ry) kickBall(brick,by,ry) Thread(target=update_coordinates).start() connect() update_coordinates() while True: activate()
Above is the portion of my code.
get_robotxya return the coordinates of the corresponding objects and the
move_to method obviously makes the robot turn to the object and move to it. Values are returned from a server and are stored in a thread as a background process. My question here is how can I ensure that my robot don't take in false values or the same values as previous as I run it in a loop? For example:
- First set of values:
- Turn to ball move to ball and kick the ball;
- Wait till ball stops moving then only reread the values to the robot then run this in a loop.
How do I do this? I tried sleeping it
time.sleep(seconds) it works sometimes then after awhile it goes mad.