This section contains examples showing various possibilities of Whole Body Motion.
Control NAO’s effectors, separately or simultaneously.
motion_wbEffectorControlHead.py
#-*- coding: iso-8859-15 -*-
''' Whole Body Motion: Head orientation control '''
import config
import time
import math
def main():
''' Example of a whole body head orientation control
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
motionProxy = config.loadProxy("ALMotion")
# Set NAO in Stiffness On
config.StiffnessOn(motionProxy)
# Send NAO to Pose Init
config.PoseInit(motionProxy)
effectorName = "Head"
# Active Head tracking
isEnabled = True
motionProxy.wbEnableEffectorControl(effectorName, isEnabled)
# Example showing how to set orientation target for Head tracking
# The 3 coordinates are absolute head orientation in NAO_SPACE
# Rotation in RAD in x, y and z axis
# X Axis Head Orientation feasible movement = [-20.0, +20.0] degree
# Y Axis Head Orientation feasible movement = [-75.0, +70.0] degree
# Z Axis Head Orientation feasible movement = [-30.0, +30.0] degree
targetCoordinateList = [
[+20.0, 00.0, 00.0], # target 0
[-20.0, 00.0, 00.0], # target 1
[ 00.0, +70.0, 00.0], # target 2
[ 00.0, +70.0, +30.0], # target 3
[ 00.0, +70.0, -30.0], # target 4
[ 00.0, -75.0, 00.0], # target 5
[ 00.0, -75.0, +30.0], # target 6
[ 00.0, -75.0, -30.0], # target 7
[ 00.0, 00.0, 00.0], # target 8
]
# wbSetEffectorControl is a non blocking function
# time.sleep allow head go to his target
# The minimum period advised between two successives set commands is 0.2 s
for targetCoordinate in targetCoordinateList:
targetCoordinate = [target*math.pi/180.0 for target in targetCoordinate]
motionProxy.wbSetEffectorControl(effectorName, targetCoordinate)
time.sleep(3.0)
# Disactivate Head tracking
isEnabled = False
motionProxy.wbEnableEffectorControl(effectorName, isEnabled)
if __name__ == "__main__":
main()
motion_wbEffectorControlLArm.py
#-*- coding: iso-8859-15 -*-
''' Whole Body Motion: Left or Right Arm position control '''
import config
import motion
import time
def main(effectorName = "LArm"):
''' Example of a whole body Left or Right Arm position control
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
motionProxy = config.loadProxy("ALMotion")
# Set NAO in Stiffness On
config.StiffnessOn(motionProxy)
# Send NAO to Pose Init
config.PoseInit(motionProxy)
space = motion.SPACE_NAO
useSensor = False
effectorInit = motionProxy.getPosition(effectorName, space, useSensor)
# Active LArm tracking
isEnabled = True
motionProxy.wbEnableEffectorControl(effectorName, isEnabled)
# Example showing how to set position target for LArm
# The 3 coordinates are absolute LArm position in NAO_SPACE
# Position in meter in x, y and z axis.
# X Axis LArm Position feasible movement = [ +0.00, +0.12] meter
# Y Axis LArm Position feasible movement = [ -0.05, +0.10] meter
# Y Axis RArm Position feasible movement = [ -0.10, +0.05] meter
# Z Axis LArm Position feasible movement = [ -0.10, +0.10] meter
coef = 1.0
if (effectorName == "LArm"):
coef = +1.0
elif (effectorName == "RArm"):
coef = -1.0
targetCoordinateList = [
[ +0.12, +0.00*coef, +0.00], # target 0
[ +0.12, +0.00*coef, -0.10], # target 1
[ +0.12, +0.05*coef, -0.10], # target 1
[ +0.12, +0.05*coef, +0.10], # target 2
[ +0.12, -0.10*coef, +0.10], # target 3
[ +0.12, -0.10*coef, -0.10], # target 4
[ +0.12, +0.00*coef, -0.10], # target 5
[ +0.12, +0.00*coef, +0.00], # target 6
[ +0.00, +0.00*coef, +0.00], # target 7
]
# wbSetEffectorControl is a non blocking function
# time.sleep allow head go to his target
# The minimum period advised between two successives set commands is 0.2 s
for targetCoordinate in targetCoordinateList:
targetCoordinate = [targetCoordinate[i] + effectorInit[i] for i in range(3)]
motionProxy.wbSetEffectorControl(effectorName, targetCoordinate)
time.sleep(4.0)
# Disactivate Head tracking
isEnabled = False
motionProxy.wbEnableEffectorControl(effectorName, isEnabled)
if __name__ == "__main__":
effectorName = "RArm" # "LArm" or "RArm"
main(effectorName)
Control arms and torso simultaneously.
#-*- coding: iso-8859-15 -*-
''' Whole Body Motion: Multiple Effectors control '''
import config
import motion
import almath
import time
def main():
'''
Example of a whole body multiple effectors control "LArm", "RArm" and "Torso"
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
proxy = config.loadProxy("ALMotion")
#Set NAO in Stiffness On
config.StiffnessOn(proxy)
# send robot to Pose Init
config.PoseInit(proxy)
# Enable Whole Body Balancer
isEnabled = True
proxy.wbEnable(isEnabled)
# Legs are constrained fixed
stateName = "Fixed"
supportLeg = "Legs"
proxy.wbFootState(stateName, supportLeg)
# Constraint Balance Motion
isEnable = True
supportLeg = "Legs"
proxy.wbEnableBalanceConstraint(isEnable, supportLeg)
# Arms motion
effectorList = ["LArm", "RArm"]
space = motion.SPACE_NAO
pathList = [
[
[0.0, 0.08, 0.14, 0.0, 0.0, 0.0], # target 1 for "LArm"
[0.0, -0.05, -0.07, 0.0, 0.0, 0.0], # target 2 for "LArm"
[0.0, 0.08, 0.14, 0.0, 0.0, 0.0], # target 3 for "LArm"
[0.0, -0.05, -0.07, 0.0, 0.0, 0.0], # target 4 for "LArm"
[0.0, 0.08, 0.14, 0.0, 0.0, 0.0], # target 5 for "LArm"
],
[
[0.0, 0.05, -0.07, 0.0, 0.0, 0.0], # target 1 for "RArm"
[0.0, -0.08, 0.14, 0.0, 0.0, 0.0], # target 2 for "RArm"
[0.0, 0.05, -0.07, 0.0, 0.0, 0.0], # target 3 for "RArm"
[0.0, -0.08, 0.14, 0.0, 0.0, 0.0], # target 4 for "RArm"
[0.0, 0.05, -0.07, 0.0, 0.0, 0.0], # target 5 for "RArm"
[0.0, -0.08, 0.14, 0.0, 0.0, 0.0], # target 6 for "RArm"
]
]
axisMaskList = [almath.AXIS_MASK_VEL, # for "LArm"
almath.AXIS_MASK_VEL] # for "RArm"
coef = 1.5
timesList = [ [coef*(i+1) for i in range(5)], # for "LArm" in seconds
[coef*(i+1) for i in range(6)] ] # for "RArm" in seconds
isAbsolute = False
# called cartesian interpolation
proxy.positionInterpolations(effectorList, space, pathList,
axisMaskList, timesList, isAbsolute)
# Torso Motion
effectorList = ["Torso"]
dy = 0.05
dz = 0.05
pathList = [
[
[0.0, +dy, -dz, 0.0, 0.0, 0.0], # target 1 for "Torso"
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # target 2 for "Torso"
[0.0, -dy, -dz, 0.0, 0.0, 0.0], # target 3 for "Torso"
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # target 4 for "Torso"
[0.0, +dy, -dz, 0.0, 0.0, 0.0], # target 5 for "Torso"
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # target 6 for "Torso"
[0.0, -dy, -dz, 0.0, 0.0, 0.0], # target 7 for "Torso"
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # target 8 for "Torso"
[0.0, +dy, -dz, 0.0, 0.0, 0.0], # target 9 for "Torso"
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # target 10 for "Torso"
[0.0, -dy, -dz, 0.0, 0.0, 0.0], # target 11 for "Torso"
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # target 12 for "Torso"
],
]
axisMaskList = [almath.AXIS_MASK_ALL] # for "Torso"
coef = 0.5
timesList = [[coef*(i+1) for i in range(12)]] # for "Torso" in seconds
isAbsolute = False
proxy.positionInterpolations(effectorList, space, pathList,
axisMaskList, timesList, isAbsolute)
# Remove optimization of "LArm" and "RArm".
isActive = False
proxy.wbEnableEffectorOptimization("LArm", isActive)
proxy.wbEnableEffectorOptimization("RArm", isActive)
# Let Arms time to return to Pose Init
time.sleep(3.0)
# Disactivate Head tracking
isEnabled = False
proxy.wbEnable(isEnabled)
if __name__ == "__main__":
main()
Balance constraints in whole body motion.
Enable a balance constraint.
motion_wbEnableBalanceConstraint.py
#-*- coding: iso-8859-15 -*-
''' Whole Body Motion: Enable Balance Constraint '''
import config
import math
def main():
''' Example of a whole body Enable Balance Constraint
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
motionProxy = config.loadProxy("ALMotion")
# Set NAO in Stiffness On
config.StiffnessOn(motionProxy)
# Send NAO to Pose Init
config.PoseInit(motionProxy)
# Activate Whole Body Balancer
isEnabled = True
motionProxy.wbEnable(isEnabled)
# Legs are constrained in a plane
stateName = "Fixed"
supportLeg = "Legs"
motionProxy.wbFootState(stateName, supportLeg)
# Constraint Balance Motion
isEnable = True
supportLeg = "Legs"
motionProxy.wbEnableBalanceConstraint(isEnable, supportLeg)
# KneePitch angleInterpolation
# Without Whole Body balancer, foot will fall down
names = ["LKneePitch", "RKneePitch"]
angleLists = [ [0.0, 40.0*math.pi/180.0], [0.0, 40.0*math.pi/180.0]]
timeLists = [ [5.0, 10.0], [5.0, 10.0]]
isAbsolute = True
motionProxy.angleInterpolation(names, angleLists, timeLists, isAbsolute)
# Disactivate Whole Body Balancer
isEnabled = False
motionProxy.wbEnable(isEnabled)
if __name__ == "__main__":
main()
Make NAO kick the air with its foot.
#-*- coding: iso-8859-15 -*-
''' Whole Body Motion: kick '''
import config
import motion
import time
import math
def main():
''' Example of a whole body kick
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
proxy = config.loadProxy("ALMotion")
#Set NAO in stiffness On
config.StiffnessOn(proxy)
# send robot to Pose Init
config.PoseInit(proxy)
# Activate Whole Body Balancer
isEnabled = True
proxy.wbEnable(isEnabled)
# Legs are constrained fixed
stateName = "Fixed"
supportLeg = "Legs"
proxy.wbFootState(stateName, supportLeg)
# Constraint Balance Motion
isEnable = True
supportLeg = "Legs"
proxy.wbEnableBalanceConstraint(isEnable, supportLeg)
# Com go to LLeg
supportLeg = "LLeg"
duration = 2.0
proxy.wbGoToBalance(supportLeg, duration)
# RLeg is free
stateName = "Free"
supportLeg = "RLeg"
proxy.wbFootState(stateName, supportLeg)
# RLeg is optimized
effectorName = "RLeg"
axisMask = 63
space = motion.SPACE_NAO
# Motion of the RLeg
dx = 0.05 # translation axis X (meters)
dz = 0.05 # translation axis Z (meters)
dwy = 5.0*math.pi/180.0 # rotation axis Y (radian)
times = [2.0, 2.7, 4.5]
isAbsolute = False
targetList = [
[-dx, 0.0, dz, 0.0, +dwy, 0.0],
[+dx, 0.0, dz, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
proxy.positionInterpolation(effectorName, space, targetList,
axisMask, times, isAbsolute)
# Example showing how to Enable Effector Control as an Optimization
isActive = False
proxy.wbEnableEffectorOptimization(effectorName, isActive)
# Com go to LLeg
supportLeg = "RLeg"
duration = 2.0
proxy.wbGoToBalance(supportLeg, duration)
# RLeg is free
stateName = "Free"
supportLeg = "LLeg"
proxy.wbFootState(stateName, supportLeg)
effectorName = "LLeg"
proxy.positionInterpolation(effectorName, space, targetList,
axisMask, times, isAbsolute)
time.sleep(1.0)
# Disactivate Head tracking
isEnabled = False
proxy.wbEnable(isEnabled)
# send robot to Pose Init
pMaxSpeedFraction = 0.1
config.PoseInit(proxy, pMaxSpeedFraction)
if __name__ == "__main__":
main()
Constrain whole body balancer with foot state.
#-*- coding: iso-8859-15 -*-
''' Whole Body Motion: Foot State '''
import config
import math
def main():
''' Example of a whole body FootState
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
proxy = config.loadProxy("ALMotion")
# Set NAO in stiffness On
config.StiffnessOn(proxy)
# Send robot to Pose Init
config.PoseInit(proxy)
# Activate Whole Body Balancer.
isEnabled = True
proxy.wbEnable(isEnabled)
# Legs are constrained in a plane
stateName = "Plane"
supportLeg = "Legs"
proxy.wbFootState(stateName, supportLeg)
# HipYawPitch angleInterpolation
# Without Whole Body balancer, foot will not be keeped plane.
names = "LHipYawPitch"
angleLists = [-45.0, 10.0, 0.0]
timeLists = [3.0, 6.0, 9.0]
isAbsolute = True
angleLists = [angle*math.pi/180.0 for angle in angleLists]
proxy.angleInterpolation(names, angleLists, timeLists, isAbsolute)
# Disactivate Whole Body Balancer.
isEnabled = False
proxy.wbEnable(isEnabled)
if __name__ == "__main__":
main()