Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 1 | #ifndef FRC971_INPUT_SENSOR_PACKER_H_ |
| 2 | #define FRC971_INPUT_SENSOR_PACKER_H_ |
| 3 | |
Brian Silverman | c6aa51a | 2013-03-15 17:06:27 -0700 | [diff] [blame] | 4 | #include "aos/common/libstdc++/memory" |
| 5 | |
Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 6 | #include "WPILib/Task.h" |
| 7 | #include "WPILib/Encoder.h" |
| 8 | #include "WPILib/DigitalInput.h" |
| 9 | #include "WPILib/Counter.h" |
Brian Silverman | c6aa51a | 2013-03-15 17:06:27 -0700 | [diff] [blame] | 10 | #include "WPILib/CounterBase.h" |
| 11 | #include "WPILib/AnalogChannel.h" |
| 12 | #include "WPILib/AnalogTrigger.h" |
| 13 | |
| 14 | #include "aos/common/mutex.h" |
| 15 | #include "aos/crio/shared_libs/interrupt_notifier.h" |
| 16 | #include "aos/common/sensors/sensor_packer.h" |
| 17 | #include "aos/crio/hardware/counter.h" |
| 18 | #include "aos/crio/hardware/digital_source.h" |
Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 19 | |
| 20 | #include "frc971/queues/sensor_values.h" |
| 21 | |
| 22 | namespace frc971 { |
| 23 | |
| 24 | class SensorPacker |
| 25 | : public ::aos::sensors::SensorPackerInterface<sensor_values> { |
| 26 | public: |
| 27 | SensorPacker(); |
| 28 | |
| 29 | virtual void PackInto(sensor_values *values); |
| 30 | |
| 31 | private: |
Brian Silverman | c6aa51a | 2013-03-15 17:06:27 -0700 | [diff] [blame] | 32 | // Used for passing ReadEncoder all of the information that it needs. |
| 33 | struct EncoderReadData { |
| 34 | EncoderReadData(::aos::crio::hardware::Counter *counter, |
| 35 | int32_t *output, |
| 36 | ::aos::Mutex *sync) |
| 37 | : counter(counter), output(output), sync(sync) {} |
| 38 | |
| 39 | ::aos::crio::hardware::Counter *const counter; |
| 40 | int32_t *const output; |
| 41 | ::aos::Mutex *const sync; |
| 42 | }; |
| 43 | |
| 44 | // Handler function for an ::aos::crio::InterruptNotifier that reads an |
| 45 | // encoder and (synchronized on a ::aos::Mutex) writes the value into a |
| 46 | // pointer. |
| 47 | static void ReadEncoder(EncoderReadData *data); |
| 48 | |
| 49 | // A whole day. |
| 50 | // Used for passing to WPILib's WaitForInterrupts. |
| 51 | static const float kInterruptTimeout = 60 * 60 * 24; |
| 52 | |
| 53 | static void StaticTopDiscEdgeReader(void *self) { |
| 54 | static_cast<SensorPacker *>(self)->TopDiscEdgeReader(); |
| 55 | } |
| 56 | static void StaticBottomDiscEdgeReader(void *self) { |
| 57 | static_cast<SensorPacker *>(self)->BottomDiscEdgeReader(); |
| 58 | } |
| 59 | |
| 60 | void TopDiscEdgeReader(); |
| 61 | void BottomDiscEdgeReader(); |
| 62 | |
| 63 | ::std::unique_ptr< ::aos::crio::hardware::Counter> drive_left_counter_; |
| 64 | ::std::unique_ptr< ::aos::crio::hardware::Counter> drive_right_counter_; |
| 65 | |
| 66 | ::std::unique_ptr< ::aos::crio::hardware::Counter> wrist_counter_; |
| 67 | ::std::unique_ptr< ::aos::crio::hardware::DigitalSource> wrist_hall_effect_; |
| 68 | int32_t wrist_edge_position_; |
| 69 | ::aos::Mutex wrist_sync_; |
| 70 | ::aos::crio::InterruptNotifier<EncoderReadData> wrist_notifier_; |
| 71 | |
| 72 | ::std::unique_ptr< ::aos::crio::hardware::Counter> angle_adjust_counter_; |
| 73 | ::std::unique_ptr< ::aos::crio::hardware::DigitalSource> angle_adjust_middle_hall_effect_; |
| 74 | ::std::unique_ptr< ::aos::crio::hardware::DigitalSource> angle_adjust_bottom_hall_effect_; |
| 75 | int32_t angle_adjust_middle_edge_position_; |
| 76 | int32_t angle_adjust_bottom_edge_position_; |
| 77 | ::aos::Mutex angle_adjust_sync_; |
| 78 | ::aos::crio::InterruptNotifier<EncoderReadData> |
| 79 | angle_adjust_middle_notifier_; |
| 80 | ::aos::crio::InterruptNotifier<EncoderReadData> |
| 81 | angle_adjust_bottom_notifier_; |
| 82 | |
| 83 | ::std::unique_ptr< ::aos::crio::hardware::Counter> shooter_counter_; |
| 84 | |
| 85 | ::std::unique_ptr< ::aos::crio::hardware::CounterCounter> index_counter_; |
| 86 | Task top_disc_edge_task_; |
| 87 | ::aos::Mutex top_disc_edge_sync_; |
| 88 | ::std::unique_ptr< ::AnalogTrigger> top_disc_; |
| 89 | ::std::unique_ptr< ::aos::crio::hardware::DigitalSource> top_disc_posedge_output_; |
| 90 | ::std::unique_ptr< ::aos::crio::hardware::DigitalSource> top_disc_negedge_output_; |
| 91 | int32_t top_disc_posedge_count_; |
| 92 | int32_t top_disc_negedge_count_; |
| 93 | int32_t top_disc_posedge_position_; |
| 94 | int32_t top_disc_negedge_position_; |
| 95 | Task bottom_disc_edge_task_; |
| 96 | ::aos::Mutex bottom_disc_edge_sync_; |
| 97 | ::std::unique_ptr< ::aos::crio::hardware::DigitalSource> bottom_disc_; |
| 98 | int32_t bottom_disc_posedge_count_; |
| 99 | int32_t bottom_disc_negedge_count_; |
| 100 | int32_t bottom_disc_negedge_wait_count_; |
| 101 | int32_t bottom_disc_negedge_wait_position_; |
Brian Silverman | 3204dd8 | 2013-03-12 18:42:01 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace frc971 |
| 105 | |
| 106 | #endif // FRC971_INPUT_SENSOR_PACKER_H_ |