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