General tools API¶
NAOqi Motion - Overview | API
Method list¶
-
class
ALMotionProxy
¶
ALMotionProxy::getBodyNames
ALMotionProxy::getSensorNames
ALMotionProxy::getLimits
ALMotionProxy::getMotionCycleTime
ALMotionProxy::getSummary
ALMotionProxy::getMass
ALMotionProxy::getCOM
ALMotionProxy::getSupportPolygon
ALMotionProxy::setMotionConfig
Deprecated Methods
ALMotionProxy::getJointNames
(deprecated, use getBodyNames instead)ALMotionProxy::getRobotConfig
Methods¶
-
std::vector<std::string>
ALMotionProxy::
getBodyNames
(const std::string& name)¶ Gets the names of all the joints in the collection.
Parameters: - name – Name of a chain, “Body”, “Chains”, “JointActuators”, “Joints” or “Actuators”.
Returns: Vector of strings, one for each joint in the collection
#include <iostream> #include <alproxies/almotionproxy.h> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_getbodynames robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get the names of all the joints in the body. std::vector<std::string> bodyNames = motion.getBodyNames("Body"); std::cout << "All joints in Body: " << std::endl; std::cout << bodyNames << std::endl; // Example showing how to get the names of all the joints in the left leg. std::vector<std::string> leftLegJointNames = motion.getBodyNames("LLeg"); std::cout << "All joints in LLeg: " << std::endl; std::cout << leftLegJointNames << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getBodyNames Method""" import qi import argparse import sys def main(session): """ This example uses the getBodyNames method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to get the names of all the joints in the body. bodyNames = motion_service.getBodyNames("Body") print "Body:" print str(bodyNames) print "" # Example showing how to get the names of all the joints in the left arm. leftArmJointNames = motion_service.getBodyNames("LArm") print "LArm:" print str(leftArmJointNames) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) main(session)
-
std::vector<std::string>
ALMotionProxy::
getJointNames
(const std::string& name)¶ Deprecated since version 1.14: use
ALMotionProxy::getBodyNames
instead.param name: Name of a chain, “Body”, “Chains”, “JointActuators”, “Joints” or “Actuators”. return: Vector of strings, one for each joint in the collection
-
std::vector<std::string>
ALMotionProxy::
getSensorNames
()¶ Gets the list of sensors supported on your robot.
Returns: Vector of sensor names #include <iostream> #include <alproxies/almotionproxy.h> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_getsensornames robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Gets the list of sensors supported on your robot. std::vector<std::string> sensorList = motion.getSensorNames(); std::cout << "Sensors: " << std::endl; for (unsigned int i=0; i<sensorList.size(); i++) { std::cout << sensorList.at(i) << std::endl; } return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getSensorNames Method""" import qi import argparse import sys def main(session): """ This example uses the getSensorNames method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to get the list of the sensors sensorList = motion_service.getSensorNames() for sensor in sensorList: print sensor if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) main(session)
-
AL::ALValue
ALMotionProxy::
getLimits
(const std::string& name)¶ Get the minAngle (rad), maxAngle (rad), maxVelocity (rad.s-1) and maxTorque (N.m). for a given joint or actuator in the body.
Parameters: - name – Name of a joint, chain, “Body”, “JointActuators”, “Joints” or “Actuators”.
Returns: Array of ALValue arrays containing the minAngle, maxAngle, maxVelocity and maxTorque for all the joints specified.
#include <iostream> #include <alproxies/almotionproxy.h> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_getlimits robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get the limits for the whole body std::string name = "Body"; std::vector<std::string> jointNames = motion.getBodyNames(name); AL::ALValue limits = motion.getLimits(name); for (unsigned int i=0; i<limits.getSize(); i++) { std::cout << " Joint name " << jointNames[i] << " minAngle " << limits[i][0] << " rad" << " maxAngle " << limits[i][1] << " rad" << " maxChange " << limits[i][2] << " rad.s-1" << " maxTorque " << limits[i][3] << " N.m" << std::endl; } return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getLimits Method""" import qi import argparse import sys def main(session): """ This example uses the getLimits method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to get the limits for the whole body name = "Body" limits = motion_service.getLimits(name) jointNames = motion_service.getBodyNames(name) for i in range(0,len(limits)): print jointNames[i] + ":" print "minAngle", limits[i][0],\ "maxAngle", limits[i][1],\ "maxVelocity", limits[i][2],\ "maxTorque", limits[i][3] if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) main(session)
-
AL::ALValue
ALMotionProxy::
getMotionCycleTime
()¶ Get the motion cycle time in milliseconds.
Returns: ALValue containing the cycle time in milliseconds as an integer.
-
AL::ALValue
ALMotionProxy::
getRobotConfig
()¶ Deprecated since version 2.4: use ALRobotModel instead.
Get the robot configuration.
return: ALValue arrays containing the robot parameter names and the robot parameter values.
-
std::string
ALMotionProxy::
getSummary
()¶ Returns a string representation of the Model’s state
Returns: A formated string #include <iostream> #include <alproxies/almotionproxy.h> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_getsummary robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get a summary of Nao's state std::cout << motion.getSummary() << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getSummary Method""" import qi import argparse import sys def main(session): """ This example uses the getSummary method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to get a summary of Nao's state print motion_service.getSummary() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) main(session)
-
float
ALMotionProxy::
getMass
(const std::string& pName)¶ Gets the mass of a joint, chain, “Body” or “Joints”.
Parameters: - pName – name of the body which we want the mass. “Body”, “Joints” and “Com” give the total mass of the robot. For the chain, it gives the total mass of the chain.
Returns: The mass in kg.
#include <iostream> #include <alproxies/almotionproxy.h> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_getmass robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get the mass of "HeadYaw". std::string pName = "HeadYaw"; float mass = motion.getMass(pName); std::cout << "Mass on " << pName << " is " << mass << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getMass Method""" import qi import argparse import sys def main(session): """ This example uses the getMass method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to get the mass of "HeadYaw". pName = "HeadYaw" mass = motion_service.getMass(pName) print pName + " mass: " + str(mass) # Example showing how to get the mass of the "LArm" chain. pName = "LArm" print "LArm mass: ", motion_service.getMass(pName) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) main(session)
-
std::vector<float>
ALMotionProxy::
getCOM
(const std::string& pName, const int& pSpace, const bool& pUseSensorValues)¶ Gets the COM of a joint, chain, “Body” or “Joints”.
Parameters: - pName – Name of the body which we want the mass. In chain name case, this function give the com of the chain.
- pSpace – Task space {FRAME_TORSO = 0, FRAME_WORLD = 1, FRAME_ROBOT = 2}.
- pUseSensorValues – If true, the sensor values will be used to determine the position.
Returns: The COM position (meter).
#include <iostream> #include <alproxies/almotionproxy.h> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_getcom robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get the COM of "HeadYaw". std::string pName = "HeadYaw"; int pSpace = 0; // FRAME_TORSO bool pUseSensors = false; std::vector<float> pos = motion.getCOM(pName, pSpace, pUseSensors); std::cout << pName << " COM position: " << std::endl; std::cout << "x: " << pos[0] << "; y: " << pos[1] << "; z: " << pos[2] << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getCOM Method""" import qi import argparse import sys import motion def main(session): """ This example uses the getCOM method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to get the COM position of "HeadYaw". name = "HeadYaw" frame = motion.FRAME_TORSO useSensors = False pos = motion_service.getCOM(name, frame, useSensors) print "HeadYaw COM Position: x = ", pos[0], " y:", pos[1], " z:", pos[2] if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) main(session)
-
std::vector<std::vector<float>>
ALMotionProxy::
getSupportPolygon
(const int& pFrame, const bool& pUseSensorValues)¶ Gets the current support polygon of the robot.
Parameters: - pFrame – Task frame. This API accepts the following values: {FRAME_WORLD = 1, FRAME_ROBOT = 2}.
- pUseSensorValues – If true, the sensor values will be used to determine the robot support polygon.
Returns: A list of 2D points representing the convex support polygon of the robot.
almotion_printSupportPolygon.py
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getSupportPolygon Method""" import qi import argparse import sys import time import pygame # display settings displayScale = 1000 # pixels/m screenWidth = 700 # pixels screenHeight = 700 # pixels screenColor = pygame.Color("white") polygonCommandColor = pygame.Color("green") polygonSensorColor = pygame.Color("red") comColor = pygame.Color("blue") def almotionToPygame(point): """ Links ALMotion to Pygame. """ return [int(-point[1] * displayScale + 0.5 * screenWidth), int(-point[0] * displayScale + 0.5 * screenHeight)] def drawPolygon(screen, data, color) : """ Draw a Polygon. """ if (data != []): pygame.draw.lines(screen, color, True, map(almotionToPygame, data), 1) def drawPoint(screen, point, color) : """ Draw a Point. """ pygame.draw.circle(screen, color, almotionToPygame(point), 3) def main(session, frame) : """ This example uses the getSupportPolygon method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") pygame.init() screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("Robot Support Polygon") running = True while (running): # Check if user has clicked 'close' for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill(screenColor) supportPolygonCommand = motion_service.getSupportPolygon(frame, False) drawPolygon(screen, supportPolygonCommand, polygonCommandColor) supportPolygonSensor = motion_service.getSupportPolygon(frame, True) drawPolygon(screen, supportPolygonSensor, polygonSensorColor) com = motion_service.getCOM("Body", frame, False) drawPoint(screen, com, comColor) pygame.display.flip() time.sleep(0.1) pygame.quit() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--ip", type=str, default="127.0.0.1", help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.") parser.add_argument("--port", type=int, default=9559, help="Naoqi port number") parser.add_argument("--frame", type=str, choices =['world', 'robot'], default = 'world') args = parser.parse_args() session = qi.Session() try: session.connect("tcp://" + args.ip + ":" + str(args.port)) except RuntimeError: print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n" "Please check your script arguments. Run with -h option for help.") sys.exit(1) if (args.frame == 'world'): frame = 1 else: frame = 2 main(session, frame)
-
void
ALMotionProxy::
setMotionConfig
(const AL::ALValue& config)¶ Internal Use.
Parameters: - config – Internal: An array of ALValues [i][0]: name, [i][1]: value