Lesson 3: Obtaining
Sensor Data
When an agent arrives on a node, how does it know what type of sensors
are available? There are special sensor tuples placed into the local
tuple space that indicate which sensors are available. The format
of the tuple is {<name = "sns">, <name = x>}
where x is the name of the sensor. Possible names include:
- pho - Photo (light)
- mic - Microphone
- tmp - Temperature
- acx - Accelerometer X
- acy - Accelerometer Y
- mgx - Magnometer X
- mgy - Magnometer Y
Sensor readings are obtained using the sense instruction.
This is
a blocking instruction that takes a value as a parameter that determines
which type of sensor to query. The types of sensors are:
- PHOTO = 1
- TEMP = 2
- MIC = 3
- MAGX = 4
- MAGY = 5
- ACCELX = 6
- ACCELY = 7
Consider the following agent found in <agilla>/Examples/Oscilloscope.ma:

This agent sits in a loop reading the photo sensor and displaying
the bottom three bits on the LEDs. It sleeps 1/8 of a second during
each loop, making it refresh the LEDs a maximum of 8 times per second.
The current version of Agill only supports a fixed-set of sensors.
Future versions will enable the programmer to plug in custom components
and will offer instructions for accessing any type of sensor.
|