OpenRAVE Documentation

collision2 Module

Plot collision contacts.

../../_images/collision2.jpg

Running the Example:

openrave.py --example collision2

Command-line

Usage: openrave.py [options]

Example shows how to query collision detection information using openravepy

Options:
  -h, --help            show this help message and exit

  OpenRAVE Environment Options:
    --loadplugin=_LOADPLUGINS
                        List all plugins and the interfaces they provide.
    --collision=_COLLISION
                        Default collision checker to use
    --physics=_PHYSICS  physics engine to use (default=none)
    --viewer=_VIEWER    viewer to use (default=qtcoin)
    --server=_SERVER    server to use (default=None).
    --serverport=_SERVERPORT
                        port to load server on (default=4765).
    --module=_MODULES   module to load, can specify multiple modules. Two
                        arguments are required: "name" "args".
    -l _LEVEL, --level=_LEVEL, --log_level=_LEVEL
                        Debug level, one of
                        (fatal,error,warn,info,debug,verbose,verifyplans)
    --testmode          if set, will run the program in a finite amount of
                        time and spend computation time validating results.
                        Used for testing

Main Python Code

def main(env,options):
    "Main example code."
    env.Load('data/pr2test1.env.xml')
    robot=env.GetRobots()[0]
    raw_input('press key to show at least one contact point')
    with env:
        # move both arms to collision
        lindex = robot.GetJoint('l_shoulder_pan_joint').GetDOFIndex()
        rindex = robot.GetJoint('r_shoulder_pan_joint').GetDOFIndex()
        robot.SetDOFValues([0.226,-1.058],[lindex,rindex])

        # setup the collision checker to return contacts
        env.GetCollisionChecker().SetCollisionOptions(CollisionOptions.Contacts)

        # get first collision
        report = CollisionReport()
        collision=env.CheckCollision(robot,report=report)
        print '%d contacts'%len(report.contacts)
        positions = [c.pos for c in report.contacts]

    h1=env.plot3(array(positions),20,[1,0,0])
    raw_input('press key to show collisions with links')
    with env:
        # collisions with individual links
        positions = []
        for link in robot.GetLinks():
            collision=env.CheckCollision(link,report=report)
            if len(report.contacts) > 0:
                print 'link %s %d contacts'%(link.GetName(),len(report.contacts))
                positions += [c.pos for c in report.contacts]

    h2=env.plot3(array(positions),20,[1,0,0])
    raw_input('press any key to exit')

Class Definitions

openravepy.examples.collision2.main(env, options)[source]

Main example code.

openravepy.examples.collision2.run(*args, **kwargs)[source]

Command-line execution of the example.

Parameters:args – arguments for script to parse, if not specified will use sys.argv

Questions/Feedback

Having problems with OpenRAVE?