Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 1 | #ifndef FRC971_WPILIB_SENSOR_READER_H_ |
| 2 | #define FRC971_WPILIB_SENSOR_READER_H_ |
| 3 | |
| 4 | #include <atomic> |
| 5 | #include <chrono> |
| 6 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 7 | #include "aos/events/event_loop.h" |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 8 | #include "aos/events/shm_event_loop.h" |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 9 | #include "aos/stl_mutex/stl_mutex.h" |
| 10 | #include "aos/time/time.h" |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 11 | #include "frc971/control_loops/control_loops_static.h" |
Maxwell Henderson | f382b4b | 2024-01-14 12:31:41 -0800 | [diff] [blame] | 12 | #include "frc971/control_loops/drivetrain/drivetrain_position_static.h" |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 13 | #include "frc971/input/robot_state_generated.h" |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 14 | #include "frc971/wpilib/ahal/DigitalGlitchFilter.h" |
| 15 | #include "frc971/wpilib/ahal/DigitalInput.h" |
Austin Schuh | 3b010bc | 2019-02-24 17:25:37 -0800 | [diff] [blame] | 16 | #include "frc971/wpilib/ahal/DriverStation.h" |
Sabina Davis | 1ffa417 | 2019-02-01 22:38:33 -0800 | [diff] [blame] | 17 | #include "frc971/wpilib/dma.h" |
| 18 | #include "frc971/wpilib/dma_edge_counting.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 19 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 20 | |
| 21 | using ::aos::monotonic_clock; |
| 22 | namespace chrono = ::std::chrono; |
| 23 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 24 | namespace frc971::wpilib { |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 25 | |
| 26 | class SensorReader { |
| 27 | public: |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 28 | SensorReader(::aos::ShmEventLoop *event_loop); |
Austin Schuh | 2c2cc2e | 2019-02-02 20:19:45 -0800 | [diff] [blame] | 29 | virtual ~SensorReader() {} |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 30 | |
Austin Schuh | 45a549f | 2019-02-02 15:43:56 -0800 | [diff] [blame] | 31 | // Updates the fast and medium encoder filter frequencies. |
| 32 | void UpdateFastEncoderFilterHz(int hz); |
| 33 | void UpdateMediumEncoderFilterHz(int hz); |
| 34 | |
Sabina Davis | b6317b7 | 2019-02-01 22:53:23 -0800 | [diff] [blame] | 35 | // Sets the left drivetrain encoder. |
| 36 | void set_drivetrain_left_encoder(::std::unique_ptr<frc::Encoder> encoder); |
| 37 | |
| 38 | // Sets the right drivetrain encoder. |
| 39 | void set_drivetrain_right_encoder(::std::unique_ptr<frc::Encoder> encoder); |
| 40 | |
Sabina Davis | 6292bec | 2019-02-06 22:53:14 -0800 | [diff] [blame] | 41 | // Adds a sensor to DMA. |
Austin Schuh | 2c2cc2e | 2019-02-02 20:19:45 -0800 | [diff] [blame] | 42 | void AddToDMA(DMASampleHandlerInterface *handler) { |
Sabina Davis | 6292bec | 2019-02-06 22:53:14 -0800 | [diff] [blame] | 43 | if (!dma_synchronizer_) { |
| 44 | dma_synchronizer_.reset( |
| 45 | new ::frc971::wpilib::DMASynchronizer(std::make_unique<DMA>())); |
| 46 | } |
Austin Schuh | 2c2cc2e | 2019-02-02 20:19:45 -0800 | [diff] [blame] | 47 | dma_synchronizer_->Add(handler); |
| 48 | } |
| 49 | |
Austin Schuh | 3b010bc | 2019-02-24 17:25:37 -0800 | [diff] [blame] | 50 | // Sets PWM trigger mode. If true, synchronize the control loops with the PWM |
| 51 | // pulses. The sensors are sampled 50 uS after the falling edge of the PWM |
| 52 | // pulse. |
| 53 | void set_pwm_trigger(bool trigger) { pwm_trigger_ = trigger; } |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 54 | |
Sabina Davis | a42cc35 | 2019-02-01 22:55:50 -0800 | [diff] [blame] | 55 | // Stops the pwm trigger on the next iteration. |
| 56 | void Quit() { run_ = false; } |
| 57 | |
Sabina Davis | 399dbd8 | 2019-02-01 23:06:08 -0800 | [diff] [blame] | 58 | virtual void RunIteration() = 0; |
Sabina Davis | 6292bec | 2019-02-06 22:53:14 -0800 | [diff] [blame] | 59 | // Runs the DMA iteration after the synchronizer. This only gets run if a |
| 60 | // sensor has been added to DMA. |
Austin Schuh | 2c2cc2e | 2019-02-02 20:19:45 -0800 | [diff] [blame] | 61 | virtual void RunDmaIteration() {} |
Sabina Davis | 399dbd8 | 2019-02-01 23:06:08 -0800 | [diff] [blame] | 62 | |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 63 | protected: |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 64 | // Copies a DMAEncoder to a IndexPosition with the correct unit and direction |
| 65 | // changes. |
| 66 | void CopyPosition(const ::frc971::wpilib::DMAEncoder &encoder, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 67 | ::frc971::IndexPositionStatic *position, |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 68 | double encoder_counts_per_revolution, double encoder_ratio, |
| 69 | bool reverse) { |
| 70 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 71 | position->set_encoder(multiplier * |
| 72 | encoder_translate(encoder.polled_encoder_value(), |
| 73 | encoder_counts_per_revolution, |
| 74 | encoder_ratio)); |
| 75 | position->set_latched_encoder( |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 76 | multiplier * encoder_translate(encoder.last_encoder_value(), |
| 77 | encoder_counts_per_revolution, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 78 | encoder_ratio)); |
| 79 | position->set_index_pulses(encoder.index_posedge_count()); |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // Copies a AbsoluteEncoderAndPotentiometer to a PotAndAbsolutePosition with |
| 83 | // the correct unit and direction changes. |
| 84 | void CopyPosition( |
| 85 | const ::frc971::wpilib::AbsoluteEncoderAndPotentiometer &encoder, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 86 | ::frc971::PotAndAbsolutePositionStatic *position, |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 87 | double encoder_counts_per_revolution, double encoder_ratio, |
| 88 | ::std::function<double(double)> potentiometer_translate, bool reverse, |
| 89 | double pot_offset) { |
| 90 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 91 | position->set_pot(multiplier * potentiometer_translate( |
| 92 | encoder.ReadPotentiometerVoltage()) + |
| 93 | pot_offset); |
| 94 | position->set_encoder(multiplier * |
| 95 | encoder_translate(encoder.ReadRelativeEncoder(), |
| 96 | encoder_counts_per_revolution, |
| 97 | encoder_ratio)); |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 98 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 99 | position->set_absolute_encoder((reverse |
| 100 | ? (1.0 - encoder.ReadAbsoluteEncoder()) |
| 101 | : encoder.ReadAbsoluteEncoder()) * |
| 102 | encoder_ratio * (2.0 * M_PI)); |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Maxwell Henderson | 5e7b6e3 | 2024-02-20 15:30:33 -0800 | [diff] [blame] | 105 | void CopyPosition( |
| 106 | const ::frc971::wpilib::DMAAbsoluteEncoderAndPotentiometer &encoder, |
| 107 | ::frc971::PotAndAbsolutePositionStatic *position, |
| 108 | double encoder_counts_per_revolution, double encoder_ratio, |
| 109 | ::std::function<double(double)> potentiometer_translate, bool reverse, |
| 110 | double pot_offset) { |
| 111 | const double multiplier = reverse ? -1.0 : 1.0; |
| 112 | position->set_pot(multiplier * potentiometer_translate( |
| 113 | encoder.ReadPotentiometerVoltage()) + |
| 114 | pot_offset); |
| 115 | position->set_encoder(multiplier * |
| 116 | encoder_translate(encoder.ReadRelativeEncoder(), |
| 117 | encoder_counts_per_revolution, |
| 118 | encoder_ratio)); |
| 119 | |
| 120 | position->set_absolute_encoder((reverse |
| 121 | ? (1.0 - encoder.ReadAbsoluteEncoder()) |
| 122 | : encoder.ReadAbsoluteEncoder()) * |
| 123 | encoder_ratio * (2.0 * M_PI)); |
| 124 | } |
| 125 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 126 | // Copies an AbsoluteEncoderAndPotentiometer to an AbsoluteAndAbsolutePosition |
| 127 | // with the correct unit and direction changes. |
| 128 | void CopyPosition(const ::frc971::wpilib::AbsoluteAndAbsoluteEncoder &encoder, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 129 | ::frc971::AbsoluteAndAbsolutePositionStatic *position, |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 130 | double encoder_counts_per_revolution, double encoder_ratio, |
| 131 | double single_turn_encoder_ratio, bool reverse) { |
| 132 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 133 | position->set_encoder(multiplier * |
| 134 | encoder_translate(encoder.ReadRelativeEncoder(), |
| 135 | encoder_counts_per_revolution, |
| 136 | encoder_ratio)); |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 137 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 138 | position->set_absolute_encoder((reverse |
| 139 | ? (1.0 - encoder.ReadAbsoluteEncoder()) |
| 140 | : encoder.ReadAbsoluteEncoder()) * |
| 141 | encoder_ratio * (2.0 * M_PI)); |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 142 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 143 | position->set_single_turn_absolute_encoder( |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 144 | (reverse ? (1.0 - encoder.ReadSingleTurnAbsoluteEncoder()) |
| 145 | : encoder.ReadSingleTurnAbsoluteEncoder()) * |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 146 | single_turn_encoder_ratio * (2.0 * M_PI)); |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 149 | // Copies a DMAEdgeCounter to a HallEffectAndPosition with the correct unit |
| 150 | // and direction changes. |
| 151 | void CopyPosition(const ::frc971::wpilib::DMAEdgeCounter &counter, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 152 | ::frc971::HallEffectAndPositionStatic *position, |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 153 | double encoder_counts_per_revolution, double encoder_ratio, |
| 154 | bool reverse) { |
| 155 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 156 | position->set_encoder(multiplier * |
| 157 | encoder_translate(counter.polled_encoder(), |
| 158 | encoder_counts_per_revolution, |
| 159 | encoder_ratio)); |
| 160 | position->set_current(!counter.polled_value()); |
| 161 | position->set_posedge_count(counter.negative_count()); |
| 162 | position->set_negedge_count(counter.positive_count()); |
| 163 | position->set_posedge_value( |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 164 | multiplier * encoder_translate(counter.last_negative_encoder_value(), |
| 165 | encoder_counts_per_revolution, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 166 | encoder_ratio)); |
| 167 | position->set_negedge_value( |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 168 | multiplier * encoder_translate(counter.last_positive_encoder_value(), |
| 169 | encoder_counts_per_revolution, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 170 | encoder_ratio)); |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Sabina Davis | 8d8ac0a | 2019-02-06 23:51:07 -0800 | [diff] [blame] | 173 | // Copies a Absolute Encoder with the correct unit |
| 174 | // and direction changes. |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 175 | void CopyPosition(const ::frc971::wpilib::AbsoluteEncoder &encoder, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 176 | ::frc971::AbsolutePositionStatic *position, |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 177 | double encoder_counts_per_revolution, double encoder_ratio, |
| 178 | bool reverse) { |
Sabina Davis | 8d8ac0a | 2019-02-06 23:51:07 -0800 | [diff] [blame] | 179 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 180 | position->set_encoder(multiplier * |
| 181 | encoder_translate(encoder.ReadRelativeEncoder(), |
| 182 | encoder_counts_per_revolution, |
| 183 | encoder_ratio)); |
Sabina Davis | 8d8ac0a | 2019-02-06 23:51:07 -0800 | [diff] [blame] | 184 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 185 | position->set_absolute_encoder((reverse |
| 186 | ? (1.0 - encoder.ReadAbsoluteEncoder()) |
| 187 | : encoder.ReadAbsoluteEncoder()) * |
| 188 | encoder_ratio * (2.0 * M_PI)); |
Sabina Davis | 8d8ac0a | 2019-02-06 23:51:07 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 191 | void CopyPosition(const ::frc971::wpilib::DMAEncoderAndPotentiometer &encoder, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 192 | ::frc971::PotAndIndexPositionStatic *position, |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 193 | ::std::function<double(int32_t)> encoder_translate, |
| 194 | ::std::function<double(double)> potentiometer_translate, |
| 195 | bool reverse, double pot_offset) { |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 196 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 197 | position->set_encoder(multiplier * |
| 198 | encoder_translate(encoder.polled_encoder_value())); |
| 199 | position->set_pot(multiplier * potentiometer_translate( |
| 200 | encoder.polled_potentiometer_voltage()) + |
| 201 | pot_offset); |
| 202 | position->set_latched_encoder( |
| 203 | multiplier * encoder_translate(encoder.last_encoder_value())); |
| 204 | position->set_latched_pot( |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 205 | multiplier * |
| 206 | potentiometer_translate(encoder.last_potentiometer_voltage()) + |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 207 | pot_offset); |
| 208 | position->set_index_pulses(encoder.index_posedge_count()); |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 211 | // Copies a relative digital encoder. |
Alex Perry | 2712c10 | 2020-02-17 19:17:11 -0800 | [diff] [blame] | 212 | void CopyPosition(const ::frc::Encoder &encoder, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 213 | ::frc971::RelativePositionStatic *position, |
Alex Perry | 2712c10 | 2020-02-17 19:17:11 -0800 | [diff] [blame] | 214 | double encoder_counts_per_revolution, double encoder_ratio, |
| 215 | bool reverse) { |
| 216 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 217 | position->set_encoder(multiplier * |
| 218 | encoder_translate(encoder.GetRaw(), |
| 219 | encoder_counts_per_revolution, |
| 220 | encoder_ratio)); |
Alex Perry | 2712c10 | 2020-02-17 19:17:11 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 223 | // Copies a potentiometer |
| 224 | void CopyPosition(const ::frc::AnalogInput &input, |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 225 | ::frc971::RelativePositionStatic *position, |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 226 | ::std::function<double(double)> potentiometer_translate, |
| 227 | bool reverse, double pot_offset) { |
| 228 | const double multiplier = reverse ? -1.0 : 1.0; |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 229 | position->set_encoder( |
| 230 | multiplier * potentiometer_translate(input.GetVoltage()) + pot_offset); |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 233 | double encoder_translate(int32_t value, double counts_per_revolution, |
| 234 | double ratio) { |
| 235 | return static_cast<double>(value) / counts_per_revolution * ratio * |
| 236 | (2.0 * M_PI); |
| 237 | } |
| 238 | |
Maxwell Henderson | d5ae85b | 2024-01-08 16:14:28 -0800 | [diff] [blame] | 239 | void SendDrivetrainPosition( |
Maxwell Henderson | f382b4b | 2024-01-14 12:31:41 -0800 | [diff] [blame] | 240 | aos::Sender<control_loops::drivetrain::PositionStatic>::StaticBuilder |
| 241 | builder, |
Maxwell Henderson | d5ae85b | 2024-01-08 16:14:28 -0800 | [diff] [blame] | 242 | std::function<double(double input)> velocity_translate, |
| 243 | std::function<double(double input)> encoder_to_meters, bool left_inverted, |
| 244 | bool right_inverted); |
| 245 | |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 246 | ::aos::EventLoop *event_loop_; |
| 247 | ::aos::Sender<::aos::RobotState> robot_state_sender_; |
| 248 | |
Austin Schuh | 45a549f | 2019-02-02 15:43:56 -0800 | [diff] [blame] | 249 | frc::DigitalGlitchFilter fast_encoder_filter_, medium_encoder_filter_; |
| 250 | |
| 251 | ::std::unique_ptr<frc::Encoder> drivetrain_left_encoder_, |
| 252 | drivetrain_right_encoder_; |
| 253 | |
| 254 | private: |
Austin Schuh | 2c2cc2e | 2019-02-02 20:19:45 -0800 | [diff] [blame] | 255 | // Gets called right before the DMA synchronizer is up and running. |
| 256 | virtual void Start() {} |
| 257 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 258 | // Sets up everything during startup. |
| 259 | void DoStart(); |
| 260 | |
| 261 | // Runs a single iteration. |
milind-u | 61227f2 | 2021-08-29 15:58:33 -0700 | [diff] [blame] | 262 | void Loop(); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 263 | |
Austin Schuh | 3b010bc | 2019-02-24 17:25:37 -0800 | [diff] [blame] | 264 | // Returns the monotonic time of the start of the first PWM cycle. |
| 265 | // Returns min_time if no start time could be calculated. |
| 266 | monotonic_clock::time_point GetPWMStartTime(); |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 267 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 268 | bool pwm_trigger_ = false; |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 269 | |
Sabina Davis | 1ffa417 | 2019-02-01 22:38:33 -0800 | [diff] [blame] | 270 | ::std::unique_ptr<::frc971::wpilib::DMASynchronizer> dma_synchronizer_; |
| 271 | |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 272 | ::std::atomic<bool> run_{true}; |
Austin Schuh | 3b010bc | 2019-02-24 17:25:37 -0800 | [diff] [blame] | 273 | ::frc::DriverStation *ds_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 274 | |
| 275 | const int32_t my_pid_; |
| 276 | |
milind-u | 61227f2 | 2021-08-29 15:58:33 -0700 | [diff] [blame] | 277 | // Pointer to the timer handler used to modify the wakeup. |
| 278 | ::aos::TimerHandler *timer_handler_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 279 | |
| 280 | // Last time we got called. |
| 281 | ::aos::monotonic_clock::time_point last_monotonic_now_ = |
| 282 | ::aos::monotonic_clock::min_time; |
| 283 | // The current period. |
| 284 | chrono::microseconds period_ = chrono::microseconds(5000); |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 285 | }; |
| 286 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 287 | } // namespace frc971::wpilib |
Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame] | 288 | |
| 289 | #endif // FRC971_WPILIB_SENSOR_READER_H_ |