Skip to main content



Sensor Objects

Sensors are objects that terminate the solution of an mBody when they come within close proximity. You can use them to detect collisions, for example, or just to crash out of a simulation when a proximity condition is true so that you can modify an mBody at that point before moving on with the simulation.

Trigger Conditions

When you use the 'sense' option on the solve command

>> mb.solve(tspan, 'sense', true)
		

to solve the equations of motion of an mBody, the solution proceeds until two compatible sensors (attached to bodies) get within some range of one another. Then it stops and returns to the command prompt.

The sensor object actually represents a whole sensor family composed of many members. Think of sensor families as groups of sensors that interact with each other, but not with other families. This allows you to distinguish between two or more types of sensor-trigger event.

The sub-sensors making up each sensor family come in two types, which QuIRK refers to as "master" and "slave" sensors. Sensor families may be composed of any number of master and any number of slave components. Both master and slave sensors must be attached to bodies.

Sensor families can operate in one of two modes: master/slave mode or any-trigger mode.

  • In master/slave mode, a sensor family triggers when any of its slave sensors comes within proximity range of any of its master sensors.
  • In any-trigger mode, a sensor family triggers when any of its slave sensors comes within proximity range of any other sensor.

Note that master sensors never trigger each other. (To create a sensor family which triggers when any sub-sensor comes near any other sub-sensor, just create an any-trigger sensor with one master.)

Back to top

The Sensor Family Constructor

The sensor function takes a list of bodies and vectors (in the body frame) describing the location of a sensor attached to each body from the body center of mass. The constructor distinguishes between master and slave sensors by their position in the argument list: masters first, slaves second.

To create a sensor family with a single master sensor, use the syntax

>> S = sensor(masterBody, masterPos, slave1Body, slave1Pos, ...
     slave2Body, slave2Pos, , slaveNbody, slaveNPos);
		

Or, equivalently, you can put all the slave-sensor arguments in a cell array:

>> S = sensor(masterBody, masterPos, {slave1Body, slave1Pos, ...
     slave2Body, slave2Pos, , slaveNbody, slaveNPos});
		

The syntax is slightly different if you want to create a sensor family with more than one master. In that case, you will need to enclose the list of master sensor bodies and positions in a cell array before the list of slave sensors:

>> S = sensor({master1Body, master1Pos, ...,
     masterNbody, masterNPos}, slave1Body, slave1Pos, ..., 
		 slaveNbody, slaveNPos);
		

or you can enclose both master and slave sensor specifications in cell arrays:

>> S = sensor({master1Body, master1Pos, ...,
     masterNbody, masterNPos}, {slave1Body, slave1Pos, ..., 
		 slaveNbody, slaveNPos});
		

In all four cases, you can add two optional arguments at the beginning and end of the argument list:

>> S = sensor(radius, {masterArguments}, {slaveArguments}, ...
     mode);
		

The radius option specifies how close two sensors must be to trigger, in meters. Mode is a string that can be either 'any', for any-trigger sensor operation, or 'm/s' for master/slave operation. Sensors are any-trigger by default.

Once you add a sensor to an mBody, it will be shown as a set of small triangles attached to their parent bodies when you call the mBody draw command, indicating its trigger state with a filled or open marker during animations. Master sensors have upward-pointing triangles. Sensors, and their trigger states, appear in the drawing whether or not the 'sense' flag appeared in the most recent call to mb.solve. Here is an example of an un-triggered and triggered sensor detecting a collision:

body
Back to top


QuIRK

Contributors

  • Joseph Shoer

Download QuIRK

Requires MATLAB 2009 or later