| 1 |
-- legOS - the independent LEGO Mindstorms OS |
| 2 |
-- doc/Sensors - sensor documentation |
| 3 |
-- (c) 1998 by Markus L. Noga <[email protected]> |
| 4 |
------------------------------------------------------------------------ |
| 5 |
|
| 6 |
By default, sensor support is enabled and initialized by the kernel. To disable, comment out the NO_DIRECT_SENSORS line in include/config.h. |
| 7 |
|
| 8 |
The three inputs and battery voltage are monitored in sequence. A/D conversion time is 266 clock ticks per channel, resulting in a maximum theoretical update frequency of 16 kHz at a system clock of 16 MHz. However, the time required by the ISR lowers this value somewhat. 8-10 kHz should be a conservative bet. |
| 9 |
|
| 10 |
Sensor values can be read like any unsigned variable. Assignments will have undefined effects, as they periodically overwritten by the A/D conversion routine. The variable names are: |
| 11 |
|
| 12 |
SENSOR_1 |
| 13 |
SENSOR_2 |
| 14 |
SENSOR_3 |
| 15 |
BATTERY |
| 16 |
|
| 17 |
|
| 18 |
Active sensors |
| 19 |
-------------- |
| 20 |
|
| 21 |
The Mindstorms light and rotation sensors are active components. They require pulsed alimenation to operate. That is, power supply must be cut when performing A/D conversion on the respective channel. |
| 22 |
|
| 23 |
To enable this functionality, use ds_active(&SENSOR_n). Otherwise, the light sensor detects ambient light, while the rotation sensor doesn't work at all. To disable, use ds_passive(&SENSOR_n). |
| 24 |
|
| 25 |
A macro LIGHT(a) to scale active light sensor values to 0 .. LIGHT_MAX is supplied, as well as convenience macros |
| 26 |
|
| 27 |
LIGHT_1 |
| 28 |
LIGHT_2 |
| 29 |
LIGHT_3 |
| 30 |
|
| 31 |
The kernel initializes all sensors to passive mode on startup and restores this state on termination of the user module. |
| 32 |
|
| 33 |
|
| 34 |
Rotation sensors |
| 35 |
---------------- |
| 36 |
|
| 37 |
Mindstorms rotation sensors provide different resistances to encode rotational position. With a finite state machine, this can be decoded into relative position. |
| 38 |
|
| 39 |
To enable this functionality, use ds_rotation_on(&SENSOR_n). To disable, use ds_rotation_off(&SENSOR_n). The decoded relative position can be read from these unsigned variables: |
| 40 |
|
| 41 |
ROTATION_1 |
| 42 |
ROTATION_2 |
| 43 |
ROTATION_3 |
| 44 |
|
| 45 |
Note that these are relative positions. By default, the sensor cannot identify absolute positions. If this information is supplied by external means, ds_rotation_set(&SENSOR_n,int pos) can be used to set an absolute position. |
| 46 |
|
| 47 |
The kernel disables rotation tracking by default. The absolute rotational position is undefined on startup. |