Self-collision avoidance API

NAOqi Motion - Overview | API


Method list

class ALMotionProxy
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

# -*- encoding: UTF-8 -*-

import argparse
from naoqi import ALProxy

def main(robotIP, PORT=9559):
    motionProxy = ALProxy("ALMotion", robotIP, PORT)

    # Example showing how to activate "Arms" anticollision
    chainName = "Arms"
    enable  = True
    isSuccess = motionProxy.setCollisionProtectionEnabled(chainName, enable)
    print "Anticollision activation on arms: " + str(isSuccess)

    # Example showing how to deactivate "LArm" anticollision
    chainName = "LArm"
    collisionState = motionProxy.isCollision(chainName)
    enable = False
    isSuccess = motionProxy.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")
    parser.add_argument("--port", type=int, default=9559,
                        help="Robot port number")

    args = parser.parse_args()
    main(args.ip, args.port)
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.

almotion_iscollision.cpp

#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;
}

almotion_isCollision.py

# -*- encoding: UTF-8 -*-

import argparse
from naoqi import ALProxy

def main(robotIP, PORT=9559):
    motionProxy = ALProxy("ALMotion", robotIP, PORT)

    # Example showing how to get the collision state
    pChainName = "LArm"
    collisionState = motionProxy.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")
    parser.add_argument("--port", type=int, default=9559,
                        help="Robot port number")

    args = parser.parse_args()
    main(args.ip, args.port)