I have a robot arm in an environment. How can I check for collision between this robot arm and the environment?


It's really easy.

env = openravepy.Environment()
env.Load('_ArmFileName'_.xml') #Whatever .xml file you're using
robot = env.GetRobots()[0]
manip = robot.SetActiveManipulator('left_arm') #whatever arm you're using
robot.SetDOFValues(joint_values, manip.GetArmIndices())

where joint_values is the an array of the joint values that you want. For example, if I was working on the Baxter robot, then I'd make an array of length 7 (7 DOF arm) with each value being values within Baxter's min/max joint values. Also note that you need to specify in the xml that your robot has the appropriate arm.

  • $\begingroup$ Ohh yes.... It was really simple I thought it would be like env.CheckCollision(robot,environment). Thanks a lot for your reply. $\endgroup$ – vacky Feb 16 '16 at 2:00

This is how I do it:

# return True if in collision, False if no collision
# pass in joint angles q to test configuration other than current
def inCollision(q=None):
    with env:
        if q == None:
            return env.CheckCollision(robot) or robot.CheckSelfCollision()
            initq = robot.GetDOFValues()
            ret = env.CheckCollision(robot) or robot.CheckSelfCollision()
            return ret

NOTE: OpenRave uses ODE as its collision checker by default. And for some reason, the default build of ODE for Ubuntu does not enable cylinder-cylinder collision checking. You can use Bullet instead if you like, but I have found it to be slower than ODE. Use these lines to change which collision checker OpenRave uses:

collisionChecker = RaveCreateCollisionChecker(env, 'bullet')

Or you can just download the ODE source and recompile. These are the steps I follow:

  1. Download the latest ODE (https://bitbucket.org/odedevs/ode/downloads/ode-0.13.1.tar.gz)
  2. ./configure --enable-double-precision --enable-libccd --disable-demos --disable-asserts --enable-shared
  3. make -j8
  4. sudo make install

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.