Tutorials:Simulations
From OpenRAVE
by Rosen Diankov
Running the Example
python:
openrave.py --example testphysics
program options/description:
openrave.py --example testphysics --help
octave/matlab: (first start openrave)
cd `openrave-config --octave-dir`/examples octave --eval testphysics
Description
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.01 seconds do
python:
env = Environment() env.StartSimulation(timestep=0.01)
octave:
orEnvSetOptions('simulation start 0.01')
To stop it do
python:
env.StopSimulation()
octave:
orEnvSetOptions('simulation stop')
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
python:
env.SetPhysicsEngine(env.CreatePhysicsEngine('ode'))
octave:
orEnvSetOptions('physics ODE');
To set gravity:
python:
env.GetPhysicsEngine().SetGravity([0,0,-9.81])
octave:
orEnvSetOptions('gravity 0 0 -9.8');
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:
<environment> <!-- ... other definitions ... --> <physicsengine type="ode"> <odeproperties> <friction>0.5</friction> <gravity>0 0 -9.8</gravity> <selfcollision>1</selfcollision> </odeproperties> </physicsengine> </environment>
Take a look at the share/openrave/data/testphysics.env.xml for a working example.

