NAOqi Motion - Overview | API | Tutorial
This tutorial explains how to use Cartesian control API to make the robot perform a Hula-Hoop motion (Torso control in position and in rotation).
Note
The tutorial is written in Python.
You can download the Hula Hoop example here: almotion_hulaHoop.py
Please refer to the section: Python SDK Install Guide for any troubleshooting linked to python.
In this section we describe each important piece of code of the example.
Then, the proxy to ALMotion module is created. This proxy is useful to call ALMotion API.
'''Motion: Hula Hoop'''
''' This example is only compatible with NAO '''
import argparse
import motion
import almath
from naoqi import ALProxy
def main(robotIP, PORT=9559):
'''
Example showing a Hula Hoop Motion
with the NAO cartesian control of torso
'''
motionProxy = ALProxy("ALMotion", robotIP, PORT)
postureProxy = ALProxy("ALRobotPosture", robotIP, PORT)
# Wake up robot
motionProxy.wakeUp()
# Send robot to Stand Init
postureProxy.goToPosture("StandInit", 0.5)
effector = "Torso"
frame = motion.FRAME_ROBOT
axisMask = almath.AXIS_MASK_ALL
isAbsolute = True
useSensorValues = False
currentTf = almath.Transform(motionProxy.getTransform(effector, frame, useSensorValues))
We define two loops of hula hoop. You can accelerate the motion by playing with the timeOneMove variable.
# Define the changes relative to the current position
dx = 0.03 # translation axis X (meter)
dy = 0.03 # translation axis Y (meter)
dwx = 8.0*almath.TO_RAD # rotation axis X (rad)
dwy = 8.0*almath.TO_RAD # rotation axis Y (rad)
# point 01 : forward / bend backward
target1Tf = almath.Transform(currentTf.r1_c4, currentTf.r2_c4, currentTf.r3_c4)
target1Tf *= almath.Transform(dx, 0.0, 0.0)
target1Tf *= almath.Transform().fromRotY(-dwy)
# point 02 : right / bend left
target2Tf = almath.Transform(currentTf.r1_c4, currentTf.r2_c4, currentTf.r3_c4)
target2Tf *= almath.Transform(0.0, -dy, 0.0)
target2Tf *= almath.Transform().fromRotX(-dwx)
# point 03 : backward / bend forward
target3Tf = almath.Transform(currentTf.r1_c4, currentTf.r2_c4, currentTf.r3_c4)
target3Tf *= almath.Transform(-dx, 0.0, 0.0)
target3Tf *= almath.Transform().fromRotY(dwy)
# point 04 : left / bend right
target4Tf = almath.Transform(currentTf.r1_c4, currentTf.r2_c4, currentTf.r3_c4)
target4Tf *= almath.Transform(0.0, dy, 0.0)
target4Tf *= almath.Transform().fromRotX(dwx)
path = []
path.append(list(target1Tf.toVector()))
path.append(list(target2Tf.toVector()))
path.append(list(target3Tf.toVector()))
path.append(list(target4Tf.toVector()))
path.append(list(target1Tf.toVector()))
path.append(list(target2Tf.toVector()))
path.append(list(target3Tf.toVector()))
path.append(list(target4Tf.toVector()))
path.append(list(target1Tf.toVector()))
path.append(list(currentTf.toVector()))
timeOneMove = 0.5 #seconds
times = []
for i in range(len(path)):
times.append((i+1)*timeOneMove)
# call the cartesian control API
motionProxy.transformInterpolations(effector, frame, path, axisMask, times)
# Go to rest position
motionProxy.rest()