Created
November 19, 2021 12:26
-
-
Save marcinwasowicz/87512872cea2a45a19c8e3240ce3861a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from naoqi import ALProxy | |
import time | |
from threading import Thread | |
EPSILON = 1e-1 | |
def hand_movement(motionProxy, close=False): | |
if close: | |
motionProxy.closeHand("LHand") | |
else: | |
motionProxy.openHand("LHand") | |
def move_joints(motionProxy, joints, positions, fractionMaxSpeed): | |
motionProxy.setAngles(joints, positions, fractionMaxSpeed) | |
def main(robotIP): | |
PORT = 9559 | |
try: | |
motionProxy = ALProxy("ALMotion", robotIP, PORT) | |
except Exception: | |
print ("Could not create proxy to ALMotion") | |
sys.exit(1) | |
motionProxy.wakeUp() | |
joints = [ | |
'LShoulderPitch', | |
'LWristYaw', | |
] | |
positions = [ | |
0.3, | |
1.0, | |
] | |
fractionMaxSpeed = 0.3 | |
motion_duration = 5 | |
open_thread = Thread(target=hand_movement, args=[motionProxy]) | |
close_thread = Thread(target=hand_movement, args=[motionProxy, True]) | |
open_thread.daemon = True | |
close_thread.daemon = True | |
start = time.time() | |
open_thread.start() | |
while motion_duration - (time.time() - start) >= EPSILON: | |
motionProxy.setAngles(joints, positions, fractionMaxSpeed) | |
close_thread.start() | |
print('Movement Finished') | |
motionProxy.rest() | |
close_thread.join() | |
open_thread.join() | |
if __name__ == "__main__": | |
robotIp = "127.0.0.1" | |
if len(sys.argv) <= 1: | |
print ("Usage python almotion_setangles.py robotIP (optional default: 127.0.0.1)") | |
else: | |
robotIp = sys.argv[1] | |
main(robotIp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment