Self-collision avoidance API¶
NAOqi Motion - Overview | API
Method list¶
-
class
ALMotionProxy
¶
ALMotionProxy::setCollisionProtectionEnabled
ALMotionProxy::getCollisionProtectionEnabled
ALMotionProxy::isCollision
-
bool
ALMotionProxy::
setCollisionProtectionEnabled
(const std::string& ChainName, const bool& Enable)¶ Enable/Disable Anti-collision protection of the arms of the robot. Use
ALMotionProxy::isCollision
to know if a chain is in collision and can be inactivated.Parameters: - ChainName – The chain name {“Arms”, “LArm” or “RArm”}.
- Enable – Activate or deactivate the anti-collision of the desired Chain.
Returns: A bool which return always true.
almotion_setCollisionProtectionEnabled.py
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use setCollisionProtectionEnabled Method""" import qi import argparse import sys def main(session): """ This example uses the setCollisionProtectionEnabled method. """ # Get the service ALMotion. motion_service = session.service("ALMotion") # Example showing how to activate "Arms" anticollision chainName = "Arms" enable = True isSuccess = motion_service.setCollisionProtectionEnabled(chainName, enable) print "Anticollision activation on arms: " + str(isSuccess) # Example showing how to deactivate "LArm" anticollision chainName = "LArm" collisionState = motion_service.isCollision(chainName) print "Is there collision? ", collisionState enable = False isSuccess = motion_service.setCollisionProtectionEnabled(chainName, enable) print "isSuccess: ", isSuccess 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::
getCollisionProtectionEnabled
(const std::string& ChainName)¶ Allow to know if the collision protection is activated on the given chain.
Parameters: - ChainName – The chain name {“LArm” or “RArm”}.
Returns: Return true is the collision protection of the given Arm is activated.
-
std::string
ALMotionProxy::
isCollision
(const std::string& ChainName)¶ Give the collision state of a chain. If a chain has a collision state “none” or “near”, it could be deactivates.
Parameters: - ChainName – The chain name {“Arms”, “LArm” or “RArm”}.
Returns: A string which notice the collision state: “none” there are no collision, “near” the collision is taking in account in the anti-collision algorithm, “collision” the chain is in contact with an other body. If the chain asked is “Arms” the most unfavorable result is given.
#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_iscollision robotIp " << "(optional default \"127.0.0.1\")."<< std::endl; } else { robotIp = argv[1]; } AL::ALMotionProxy motion(robotIp); // Example showing how to get the collision state std::string pChainName = "LArm"; std::string collisionState = motion.isCollision(pChainName); std::cout << pChainName << " collision state: " << collisionState << std::endl; return 0; }
#! /usr/bin/env python # -*- encoding: UTF-8 -*- """Example: Use isCollision Method""" import qi import argparse import sys def main(session): """ This example uses the isCollision method. """ # Get the services ALMotion & ALRobotPosture. motion_service = session.service("ALMotion") # Example showing how to get the collision state pChainName = "LArm" collisionState = motion_service.isCollision(pChainName) print pChainName + " collision state is " + collisionState +"." 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)