Tutorial 5: Sensors
Sensors acquire information from a simulation. There are several types of Sensors, including Acceleration Sensors, Raycast Sensors, and Volume Sensors. This tutorial will show how to setup each type. It will also give examples of how each type could be used. Keep in mind that a Sensor can either be attached to a Solid or just positioned somewhere in the environment.
Let’s first create all the objects we’ll need (and assume they will be initialized elsewhere):
The first Sensor we will use here is an Acceleration Sensor:
The Sensor is automatically attached to the Solid if its Solid pointer is set. It calculates the linear and angular acceleration of the attached Solid at the point of the Sensor (which can be offset from the Solid by using the Sensor’s transform). It could be used in a simulated robot to give it the ability to sense which way it is falling.
The next Sensor is the Incline Sensor:
The Sensor takes a local rotation axis relative to its attached Solid. It calculates and returns the angle the Solid has rotated around this axis. Multiple Incline Sensors could be attached to a vehicle, for instance, to simulate a real inclinometer. The combination of an Acceleration Sensor and an Incline Sensor could be used to simulate the human vestibular system.
The next Sensor is the Raycast Sensor:
Raycast Sensors must be fired manually – they do not update anything every time step. When they are fired, they cast a ray into the environment and return data describing the closest point of intersection (if any) from the ray’s origin. The Raycast Sensor uses a contact group to limit which objects it collides with. (See other tutorials for more information on contact groups.)
The Volume Sensor is similar to the Raycast Sensor:
Volume Sensors take a “volume” Solid and query the environment for Solids that collide with the volume Solid. The resulting data structure contains a list of pointers to those Solids. Like Raycast Sensors, they can utilize contact groups to limit the set of Solids that are collided with the volume Solid; simply set the contact group of the volume Solid. They also are not updated every time step; they must be queried manually. The example above shows how to simulate an explosion: it finds all the Solids within a 5 unit radius from the volume’s center and applies an outward force on each object scaled linearly by its distance from the center.
When you are done with a Sensor, tell the Simulator to destroy it:
OPAL is Copyright © 2004-2005 Alan Fischer, Andres Reinot, and Tyler Streeter