Overview | API | foot planner Tutorial | robot position Tutorial
See also
This tutorial explains how to use the robotPosition and getFootSteps API. These both API will help you to have a better control on the walk algorithm.
Note
The tutorial is written in Python.
You can download the robot position example here: motion_robotPosition.py
To be executed, this tutorial require a config file: config.py. Modify the config file to enter your robot IP, and place it in the same folder as the example.
Please refer to the section: Python SDK Install Guide for any troubleshooting linked to python.
This tutorial uses matplotlib for plotting data: http://matplotlib.sourceforge.net/.
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 called ALMotion API.
import config
import time
import math
import almath
try:
import pylab as pyl
HAS_PYLAB = True
except ImportError:
print "Matplotlib not found. this example will not plot data"
HAS_PYLAB = False
def main():
''' robot Position: Small example to know how to deal
with robotPosition and getFootSteps
'''
motionProxy = config.loadProxy("ALMotion")
# Set NAO in stiffness On
config.StiffnessOn(motionProxy)
config.PoseInit(motionProxy, 0.2)
# Initialize the walk
motionProxy.walkInit()
We define here an experience where someone send a first walk command and, few seconds after, a second one.
We observe phenomenon of unchangeable and changeable foot step. The second walk command is executed after the unchangeable foot generated by the first walk command.
# First call of walk API
# with post prefix to not be bloquing here.
motionProxy.post.walkTo(0.3, 0.0, 0.5)
# wait that the walk process start running
time.sleep(0.1)
# get robotPosition and nextRobotPosition
robotPosition = almath.Pose2D(almath.vectorFloat(motionProxy.getRobotPosition(False)))
nextRobotPosition = almath.Pose2D(almath.vectorFloat(motionProxy.getNextRobotPosition(False)))
# get the first foot steps vector
# (footPosition, unChangeable and changeable steps)
footSteps1 = motionProxy.getFootSteps()
# Second call of walk API
motionProxy.post.walkTo(0.3, 0.0, -0.5)
# get the second foot steps vector
footSteps2 = motionProxy.getFootSteps()
Here, using walk API, we compute the move made by the robot. The goal is to find the value of the second walk command.
The robot begins the second walk command after the first command unchangeable foot step. In this case the robot position is the result of nextRobotPosition.
Then, we wait the end of the walk process (waitUntilWalkIsFinished) and we get the final robot position.
The distance is equivalent to .
And the result should be [0.3, 0.0, -0.5]
# here we wait until the walk process is over
motionProxy.waitUntilWalkIsFinished()
# then we get the final robot position
robotPositionFinal = almath.Pose2D(almath.vectorFloat(motionProxy.getRobotPosition(False)))
# compute robot Move with the second call of walk API
# so between nextRobotPosition and robotPositionFinal
robotMove = almath.pose2DInverse(nextRobotPosition)*robotPositionFinal
print "Robot Move :", robotMove
We use matplotlib function to print the foot step result of the experience.
Functions printRobotPosition and printFootSteps are definied in the motion_robotPosition.py file.
if (HAS_PYLAB):
#################
# Plot the data #
#################
pyl.figure()
printRobotPosition(robotPosition, 'black')
printRobotPosition(nextRobotPosition, 'blue')
printFootSteps(footSteps1, 'green', 'red')
pyl.figure()
printRobotPosition(robotPosition, 'black')
printRobotPosition(nextRobotPosition, 'blue')
printFootSteps(footSteps2, 'blue', 'orange')
pyl.show()
This first figure represents the result of the fisrt walk command: