OpenRAVE Documentation

testphysics Module

Shows how to enable physics.


Running the Example: --example testphysics


When simulations are turned on, an internal timer starts and the SimulationStep functions of all classes are called. Note that simulations extend beyond physics. That’s why there’s the distinction between simulation and physics and both are set separately. To start the internal simulation with a timestep of 0.001 seconds do

env = Environment()

To stop it do


In a plugin, every state is accessible directly through memory. In scripting (Octave/Matlab), there’s a thread safe loop that serializes information to the socket. KinBody/Robot information can be accessed from any thread as long as EvironmentBase::LockPhysics is called. In a SimulationStep call, this is not necessary as OpenRAVE locks physics before calling it.

To set the physics engine to ODE, use



orEnvSetOptions(‘physics ODE’);

To set gravity:


Make sure that whatever object you don’t want moving (like floors) are declared static. Setting Properites through XML Files

It is possible to create and setup a physics engine in the <environment> tag in the XML file description. The ode physics engine uses a custom XML reader to define a special odeproperties tag that can be used to specify friction, gravity, etc. For example:

  <!-- ... other definitions ... -->
  <physicsengine type="ode">
      <gravity>0 0 -9.8</gravity>

Take a look at the share/openrave/data/testphysics.env.xml for a working example.


Usage: [options]

test physics

  -h, --help            show this help message and exit
  --scene=SCENE         Scene file to load (default=data/hanoi.env.xml)
  --timestep=TIMESTEP   The physics simulation time step size  (default=0.001)

  OpenRAVE Environment Options:
                        List all plugins and the interfaces they provide.
                        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).
                        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
    --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."
    if options._physics is None:
        # no physics engine set, so set one
        physics = RaveCreatePhysicsEngine(env,'ode')
    with env:
        starttime = time.time()
    while True:
        bodynames = ['data/lego2.kinbody.xml', 'data/lego4.kinbody.xml', 'data/mug1.kinbody.xml']
        numbodies = 0
        if numbodies < 40:
            with env:
                body = env.ReadKinBodyXMLFile(bodynames[random.randint(len(bodynames))])
                numbodies += 1
                T = eye(4)
                T[0:3,3] = array((-0.5,-0.5,2))+0.4*random.rand(3)
        simtime = env.GetSimulationTime()*1e-6
        realtime = time.time()-starttime
        print 'sim time: %fs, real time: %fs, diff = %fs'%(simtime,realtime,simtime-realtime)

Class Definitions

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

Main example code.*args, **kwargs)[source]

Command-line execution of the example.

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


Having problems with OpenRAVE?