Motion task API¶
NAOqi Motion - Overview | API
Method list¶
-
class
ALMotionProxy
¶
ALMotionProxy::getTaskList
ALMotionProxy::areResourcesAvailable
ALMotionProxy::killTask
ALMotionProxy::killTasksUsingResources
ALMotionProxy::killMove
ALMotionProxy::killAll
Deprecated Methods
ALMotionProxy::killWalk
(deprecated, use killMove instead)
Methods¶
-
AL::ALValue
ALMotionProxy::
getTaskList
()¶ Gets an ALValue structure describing the tasks in the Task List
Returns: An ALValue containing an ALValue for each task. The inner ALValue contains: Name, MotionID #include <qi/os.hpp> #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_gettasklist robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get the current task list // We will create a task first, so that we see a result AL::ALValue names = "HeadYaw"; AL::ALValue angleLists = 1.0f; AL::ALValue timeList = 3.0f; bool isAbsolute = true; motion.setStiffnesses(names, 1.0f); motion.post.angleInterpolation(names, angleLists, timeList, isAbsolute); qi::os::msleep(100); std::cout << "Tasklist: " << motion.getTaskList() << std::endl; qi::os::sleep(3.0f); motion.setStiffnesses(names, 0.0f); return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use getTaskList Method""" import qi import argparse import sys import time def main(session): """ This example uses the getTaskList method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") motion_service.setStiffnesses("Head", 1.0) # Example showing how to get the current task list # We will create a task first, so that we see a result names = "HeadYaw" angleLists = 1.0 timeList = 3.0 isAbsolute = True motion_service.angleInterpolation(names, angleLists, timeList, isAbsolute, _async=True) time.sleep(0.1) print 'Tasklist: ', motion_service.getTaskList() time.sleep(2.0) motion_service.setStiffnesses("Head", 0.0) 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)
-
bool
ALMotionProxy::
areResourcesAvailable
(const std::vector<std::string>& resourceNames)¶ Returns true if all the desired resources are available. Only motion API’s‘ blocking call takes resources.
Parameters: - resourceNames – A vector of resource names such as joints or
chains names, “Body”, “JointActuators”, “Joints” or “Actuators”.
Use
getBodyNames("Body")
to get the list of the available joints for your robot.
Returns: True if the resources are available
almotion_areresourcesavailable.cpp
#include <iostream> #include <alproxies/almotionproxy.h> #include <qi/os.hpp> int main(int argc, char **argv) { std::string robotIp = "127.0.0.1"; if (argc < 2) { std::cerr << "Usage: almotion_areresourcesavailable robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Setting head stiffness on. motion.setStiffnesses("Head", 1.0f); // Example showing how to use areResourcesAvailable // We will create a task first, so that we see a result AL::ALValue names = "HeadYaw"; AL::ALValue angleLists = 1.0f; AL::ALValue timeList = 3.0f; bool isAbsolute = true; motion.post.angleInterpolation(names, angleLists, timeList, isAbsolute); qi::os::msleep(100); std::cout << "Are resources "<< names << " available?" << std::endl; std::cout << motion.areResourcesAvailable(AL::ALValue::array(names)) << std::endl; qi::os::sleep(3.0f); // Setting head stiffness off. motion.setStiffnesses("Head", 0.0f); return 0; }
almotion_areResourcesAvailable.py
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use areResourcesAvailable Method""" import qi import argparse import sys import time def main(session): """ This example uses the areResourcesAvailable method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") motion_service.setStiffnesses("Head", 1.0) # Example showing how to use areResourcesAvailable # We will create a task first, so that we see a result name = "HeadYaw" motion_service.angleInterpolation(name, 1.0, 1.0, True, _async=True) time.sleep(0.1) print "Are " + name + " resources available? " + str(motion_service.areResourcesAvailable([name])) time.sleep(1.0) motion_service.setStiffnesses("Head", 0.0) 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)
- resourceNames – A vector of resource names such as joints or
chains names, “Body”, “JointActuators”, “Joints” or “Actuators”.
Use
-
bool
ALMotionProxy::
killTask
(const int& motionTaskID)¶ Kills a motion task.
Parameters: - motionTaskID – TaskID of the motion task you want to kill.
Returns: Return true if the specified motionTaskId has been killed.
#include <qi/os.hpp> #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_killtask robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); AL::ALValue names = "HeadYaw"; AL::ALValue angleLists = 1.0f; AL::ALValue timeLists = 10.0f; bool isAbsolute = true; motion.setStiffnesses(names, 1.0f); motion.post.angleInterpolation(names, angleLists, timeLists, isAbsolute); qi::os::msleep(3000); std::cout << "Killing task..." << std::endl; AL::ALValue TaskList = motion.getTaskList(); int uiMotion = TaskList[0][1]; motion.killTask(uiMotion); std::cout << "Task killed." << std::endl; motion.setStiffnesses(names, 0.0f); return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use killTask Method""" import qi import argparse import sys import time import almath def main(session): """ This example uses the killTask method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") motion_service.setStiffnesses("Head", 1.0) # This function is useful to kill motion Task # To see the current motionTask please use getTaskList() function motion_service.angleInterpolation('HeadYaw', 90*almath.TO_RAD, 10, True, _async=True) time.sleep(3) taskList = motion_service.getTaskList() uiMotion = taskList[0][1] motion_service.killTask(uiMotion) motion_service.setStiffnesses("Head", 0.0) 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)
-
void
ALMotionProxy::
killTasksUsingResources
(const std::vector<std::string>& resourceNames)¶ Kills all tasks that use any of the resources given. Only motion API’s‘ blocking call takes resources and can be killed.
Parameters: - resourceNames – A vector of resource names such as joints or
chains names, “Body”, “JointActuators”, “Joints” or “Actuators”.
Use
getBodyNames("Body")
to get the list of the available joints for your robot.
almotion_killtasksusingresources.cpp
#include <qi/os.hpp> #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_killtasksusingresources robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to killTasksUsingResources // We will create a task first, so that we see a result AL::ALValue names = "HeadYaw"; AL::ALValue angleLists = 1.0f; AL::ALValue timeList = 3.0f; bool isAbsolute = true; motion.setStiffnesses(names, 1.0f); motion.post.angleInterpolation(names, angleLists, timeList, isAbsolute); qi::os::msleep(1000); std::cout << "Killing task..." << std::endl; motion.killTasksUsingResources(AL::ALValue::array(names)); std::cout << "Task killed." << std::endl; motion.setStiffnesses(names, 0.0f); return 0; }
almotion_killTasksUsingResources.py
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use killTasksUsingResources Method""" import qi import argparse import sys import time def main(session): """ This example uses the killTasksUsingResources method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") motion_service.setStiffnesses("Head", 1.0) # Example showing how to killTasksUsingResources # We will create a task first, so that we see a result name = "HeadYaw" motion_service.angleInterpolation(name, 1.0, 1.0, True, _async=True) time.sleep(0.5) motion_service.killTasksUsingResources([name]) motion_service.setStiffnesses("Head", 0.0) 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)
- resourceNames – A vector of resource names such as joints or
chains names, “Body”, “JointActuators”, “Joints” or “Actuators”.
Use
-
void
ALMotionProxy::
killWalk
()¶ Deprecated since version 1.14: use
ALMotionProxy::killMove
instead.Emergency Stop on Walk task: this method will end the walk task brutally, without attempting to return to a balanced state. If the robot has one foot in the air, he could easily fall.
-
void
ALMotionProxy::
killMove
()¶ Emergency Stop on Move task: this method will end the move task brutally, without attempting to return to a balanced state. If the robot has one foot in the air, he could easily fall.
#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_killmove robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to use Emergency Stop on Move task. motion.killMove(); std::cout << "Killed move." << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use killMove Method""" import qi import argparse import sys import time def main(session): """ This example uses the killMove method. """ # Get the services ALMotion & ALRobotPosture. motion_service = session.service("ALMotion") posture_service = session.service("ALRobotPosture") # Wake up robot motion_service.wakeUp() # Send robot to Stand Init posture_service.goToPosture("StandInit", 0.5) motion_service.moveTo(0.5, 0.0, 0.0, _async=True) time.sleep(3.0) # End the walk suddenly (around 20ms) motion_service.killMove() # Go to rest position motion_service.rest() 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)
-
void
ALMotionProxy::
killAll
()¶ Kills all tasks.
#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_killall robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to kill all the tasks. motion.killAll(); std::cout << "All tasks killed." << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use killAll Method""" import qi import argparse import sys def main(session): """ This example uses the killAll method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to kill all the tasks. motion_service.killAll() print "All tasks killed." 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)