Self-collision avoidance API

Overview | API

See also


Method list

class ALMotionProxy
bool ALMotionProxy::setCollisionProtectionEnabled(const std::string& pChainName, const bool& pEnable)

Enable Anticollision protection of the arms of the robot. Use api isCollision to know if a chain is in collision and can be inactivated.

Parameters:
  • pChainName – The chain name {“Arms”, “LArm” or “RArm”}.
  • pEnable – Activate or disactivate the anticollision of the desired Chain.
Returns:

A bool which notice if the desired activation/disactivation is applyed successfully. Activation always success. Disactivation success only if the current state of the chain is not in collision. If we want to disactivate collision of the both arms (“Arms”), the two arms must be without collision.

almotion_setcollisionprotectionenabled.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_setcollisionprotectionenabled.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

# Example showing how to activate "Arms" anticollision 
# Anticollision can be activated at every time 
pChainName = "Arms" 
pEnable    = True 
isSuccess  = proxy.setCollisionProtectionEnabled(pChainName, pEnable)
print "Anticollision activation on arms: " + str(isSuccess)

# Example showing how to disactivate "LArm" anticollision 
# Anticollision can be inactivated only if there is no collision in the desired chain 
pChainName = "LArm" 
collisionState= proxy.isCollision(pChainName) 
pEnable = False 
if ((collisionState =="none") or 
    (collisionState =="near")): 
    isSuccess= proxy.setCollisionProtectionEnabled(pChainName, pEnable)
    print "Anticollision disactivation on arms: " + str(isSuccess)
else:
    print "Cannot disactivate collision protection on left arm: collisionState = collision"
bool ALMotionProxy::getCollisionProtectionEnabled(const std::string& pChainName)

Allow to know if the collision protection is activated on the given chain.

Parameters:
  • pChainName – 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& pChainName)

Give the collision state of a chain. If a chain has a collision state “none” or “near”, it could be desactivated.

Parameters:
  • pChainName – 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)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_iscollision pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  // 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

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_iscollision.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

# Example showing how to get the collision state 
pChainName = "LArm" 
collisionState = proxy.isCollision(pChainName)

print pChainName + " collision state is " + collisionState