I have a robot arm in an environment. How can I check for collision between this robot arm and the environment?
2 Answers
It's really easy.
env = openravepy.Environment()
env.StopSimulation()
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())
env.CheckCollision(robot)
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$– vackyCommented Feb 16, 2016 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()
else:
initq = robot.GetDOFValues()
robot.SetDOFValues(q)
ret = env.CheckCollision(robot) or robot.CheckSelfCollision()
robot.SetDOFValues(initq)
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')
env.SetCollisionChecker(collisionChecker)
Or you can just download the ODE source and recompile. These are the steps I follow:
- Download the latest ODE (https://bitbucket.org/odedevs/ode/downloads/ode-0.13.1.tar.gz)
./configure --enable-double-precision --enable-libccd --disable-demos --disable-asserts --enable-shared
make -j8
sudo make install