Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 1 | #ifndef AOS_COMMON_SENSORS_SENSORS_H_ |
| 2 | #define AOS_COMMON_SENSORS_SENSORS_H_ |
| 3 | |
| 4 | #include "aos/common/time.h" |
Brian Silverman | ffe3d71 | 2013-03-15 21:35:59 -0700 | [diff] [blame^] | 5 | #include "aos/common/byteorder.h" |
Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 6 | |
| 7 | #include "aos/common/control_loop/ControlLoop.h" |
| 8 | |
| 9 | namespace 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. |
| 27 | namespace 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(). |
| 32 | const int kSendsPerCycle = 10; |
| 33 | // ::aos::control_loops::kLoopFrequency / kSendsPerCycle for |
| 34 | // convenience. |
| 35 | extern const time::Time kSensorSendFrequency; |
| 36 | using ::aos::control_loops::kLoopFrequency; |
| 37 | |
| 38 | // This is the struct that actually gets sent over the UDP socket. |
| 39 | template<class Values> |
| 40 | struct SensorData { |
| 41 | Values values; |
| 42 | // Starts at 0 and goes up. |
| 43 | int32_t count; |
Brian Silverman | ffe3d71 | 2013-03-15 21:35:59 -0700 | [diff] [blame^] | 44 | |
| 45 | void NetworkToHost() { |
| 46 | count = ntoh(count); |
| 47 | } |
Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 48 | } __attribute__((packed)); |
| 49 | |
| 50 | } // namespace sensors |
| 51 | } // namespace aos |
| 52 | |
| 53 | #endif // AOS_COMMON_SENSORS_SENSORS_H_ |