blob: 06f525332f868ba63eb31c96b03d86ee9aa1588f [file] [log] [blame]
Brian Silverman3204dd82013-03-12 18:42:01 -07001#ifndef AOS_COMMON_SENSORS_SENSORS_H_
2#define AOS_COMMON_SENSORS_SENSORS_H_
3
4#include "aos/common/time.h"
5
6#include "aos/common/control_loop/ControlLoop.h"
7
8namespace aos {
9// This namespace contains all of the stuff for dealing with reading sensors and
10// communicating it to everything that needs it. There are 4 main classes whose
11// instances actually process the data. They must all be registered in the
12// appropriate ::aos::crio::ControlsManager hooks.
13//
14// SensorPackers get run on the cRIO to read inputs (from WPILib or elsewhere)
15// and put the values into the Values struct (which is templated for all of the
16// classes that use it).
17// SensorUnpackers get run on both the atom and the cRIO to take the data from
18// the Values struct and put them into queues for control loops etc.
19// SensorBroadcasters (on the cRIO) send the data to a SensorReceiver (on the
20// atom) to pass to its SensorUnpacker there.
21// CRIOControlLoopRunners register with a SensorBroadcaster to get called right
22// after reading the sensor data so that they can immediately pass it so a
23// SensorUnpacker and then run their control loops.
24// The actual SensorPacker and SensorUnpacker classes have the Interface suffix
25// on them.
26namespace sensors {
27
28// How many times per ::aos::control_loops::kLoopFrequency sensor
29// values get sent out by the cRIO.
30// This must evenly divide that frequency into multiples of sysClockRateGet().
31const int kSendsPerCycle = 10;
32// ::aos::control_loops::kLoopFrequency / kSendsPerCycle for
33// convenience.
34extern const time::Time kSensorSendFrequency;
35using ::aos::control_loops::kLoopFrequency;
36
37// This is the struct that actually gets sent over the UDP socket.
38template<class Values>
39struct SensorData {
40 Values values;
41 // Starts at 0 and goes up.
42 int32_t count;
43} __attribute__((packed));
44
45} // namespace sensors
46} // namespace aos
47
48#endif // AOS_COMMON_SENSORS_SENSORS_H_