# Lecture University of Nevada Reno by MikeJenny

VIEWS: 5 PAGES: 23

• pg 1
```									Computer Science & Engineering, University of Nevada, Reno

CS 282
Simulation Physics

Lecture 26:
Studying a Physics Engine:
Open Dynamics Engine (ODE)

2 December 2010
Instructor: Kostas Bekris
CS 282

ODE Manual

http://opende.sourceforge.net/wiki/index.php/Manual
CS 282

Example

Run demo_crash
CS 282

What is the Open Dynamics Engine

Simulates physics of articulated rigid body structures
• rigid bodies of various shapes are connected together with joints of
various kinds
- e.g., a car-like vehicle
✓the 4 wheels are connected with joints to the chassis
- e.g., legged creatures
✓the legs are connected to the body
- e.g., stacks of objects
✓that stay together because of friction and contact forces

Designed to be used in interactive or real-time simulation
• able to simulate moving objects in changeable virtual environments
• emphasizes speed and stability over physical accuracy
- specially-designed scientific simulators are more accurate

Handling of contacts
• Hard contacts instead of springs: non-penetration constraint is
enforced
CS 282

Main Features

Rigid bodies
• Bodies with static geometry and mass

Joints
• Multiple types: ball-and-socket, hinge, hinge-2, prismatic (slider),
fixed, angular motor, linear motor, universal

Forces and Torques
• Applied to bodies and joints respectively

Collision Primitives for bodies
• Sphere, box, cylinder, capsule, plane, ray and triangular mesh

Collision spaces for culling
• Different alternatives: Quad Tree, Hash Space and Simple
CS 282

Mains Features

Simulation Method
• Lagrangian dynamics instead of Newtonian
• Integration method
- fast but introduces errors
• Multiple time stepping methods
• Friction model that approximates Coulomb friction

Written in C/C++
• Provides a C++ interface
• Has a native C interface as well

Many unit tests and demos

Platform specific optimizations
CS 282

Data Types

Mathematical data types
• Quaternions, Matrices and Vectors
• Necessary to keep track of rigid body configurations

Important ODE objects
• dWorld - A dynamics world
• dSpace - A collision space
• dBody - A rigid body
• dGeom - A geometry used for collision checking
• dJoint - A joint
• dJointGroup - A group used to track sets of joints
CS 282
Rigid Bodies

State Parameters
• Position Vector
• Orientation
• Linear Velocity
• Angular Velocity

Constant Properties
• Mass
• Position of center of mass
• Inertia Matrix
CS 282

Joints

Act as interactions between rigid bodies
• They introduce constraints for the configuration of rigid bodies
• Some of them they might have motors that generate forces

Types of joints:
• Ball-and-socket
• Hinge
• Hinge-2
• Prismatic (slider)
• Fixed
• Angular Motor
• Linear Motor
• Universal
CS 282

Ball-and-socket and Universal

Ball and Socket
Similar to a shoulder joint
• Not too restrictive

Constraint
• There exists a point where the
connected bodies must remain
at the same distance
• 3 DOFs

Universal
Similar to B-a-S
Constraints
• Like B-a-S but 2nd body
cannot freely rotate along a
third axis
• 2 DOFs
CS 282

Hinge and Hinge-2

Hinge
Works like a door hinge

Constraint:
• The contact points must pivot
around a central axis
• 1 DOF

Hinge-2
Works like a car-wheel

Constraint:
• Rotation around 2 axes
• 2 rotations DOFs
CS 282

Prismatic and Piston Joints

Slider/Prismatic
Similar to a hydraulic piston
Constraint:
• Relative orientations are the same,
except for distance
• 1 DOF

Piston
Less constrained version of the
prismatic joint

Constraint:
• Like prismatic joint, only that body
2 can also rotate around the axis
• 2 DOFs
CS 282

Fixed and Contact Joints

Fixed
Just connect 2 rigid bodies into
one

0 DOFs

Contact

Subclass of fixed joints

• formed temporarily for collision
detection purposes
• just for a single simulation step
CS 282

Linear and Angular Motor joint

Angular Motor
Apply torques between two rigid
bodiers

No constraints
3 DOFs

Linear Motor
Similar to an angular motor
• but instead of torques, the
joints apply forces
- in a linear fashion

No constraints
3 DOFs
CS 282

Combination Joints

Prismatic Universal Joints
Combination of prismatic and
universal joint
• 3 DOFs
- 1 from prismatic
- 2 from universal

Prismatic Rotational Joints
Combination of prismatic with
hinge joint
• 2 DOFs
- 1 from prismatic
- 1 from hinge
CS 282

Joint errors

As the simulation progresses and
the rigid bodies move
• there will be errors in the joints

ODE uses an error reduction
parameter (ERP)
• the higher the ERP, the more will
ODE try to auto-correct the
position of the bodies

• default value is relative low (0.2)
to reduce computational
CS 282

Collision Handling

Before each simulation step
• collision detection callbacks are executed
- to determine what is touching what
• the callbacks return a list of contact points
• each contact point specifies:
- a position in space
- a surface normal vector
- a penetration depth
• for each contact point, a contact joint is created that stores the
following information (user specified):
- the friction at the contact surface
- how bouncy or soft the surfaces are
- and various other properties
• all the contact joints are added in a contact joint group
- easy to add and remove from the simulation quickly
- the simulation speed goes down as the number of contacts goes up
• then a simulation step is taken
CS 282

Types of Collisions Handled

Which collisions are handled?
• i.e., between which geometric primitives?
CS 282

Physics Simulation

Abstractions:
• World
- takes care of the dynamics, e.g., forces, gravity, etc.
• Space
- takes care of the geometry, e.g., collision handling, etc.

A typical simulation proceeds as follows:
• Initialize World and Space abstractions
• Loop
- Apply simulation step
• Destroy the World and Space abstractions
CS 282

Initialization

• Create a dynamics world

• Create the bodies of the dynamics world

• Set the configurations of all the bodies

• Create the joints of the dynamics world

• Attach the joints to the bodies

• Set the parameters for the joints

• Create the corresponding collision world and geometries

• Create a joint group to hold all collision joints
CS 282

Simulation Loop

• Apply forces to the bodies in the dynamics world

• Adjust the joints as necessary

• Call collision detection

• Create a contact joint for each contact point
- Add them to the group

• Take a simulation step

• Remove all contact joints from the group
CS 282

Interaction between Dynamics World - Collision Space

Force are applied to the world
• and bodies are moved according to physics

Collisions are detected by the space abstraction
• if a collision is detected, the simulation backtracks until the point in
time that the collision occurred
• two time stepping functions
- one more accurate and slower     O(m3) time complexity, m: # of
constraints
- one faster O(m*N), N: # of iterations that is a user-specified parameter

At the point of collision, the world abstraction
• calculates collision joints and forces
• and progresses the simulation

This repeats until the simulation step is complete
CS 282

Simulation Physics class

Why do we need a simulation physics class if there are available
physics engines?

• Each engine has a rather narrow area of application
- e.g., ODE too slow for single rigid body simulation
- e.g., ODE too inaccurate for scientific simulations and engineering
- e.g., ODE rather slow for real-time AI algorithms

• In many (if not most) cases, you will have to:
- either adapt an existing engine
- or make a specialized one for your application

• In any case you need to be aware of the physics in rigid-body
simulation

```
To top