blob: 5e98b52b287adbca373cef432c9fc6ed1dc9da53 [file] [log] [blame]
Comran Morshed9a9948c2016-01-16 15:58:04 +00001#include <stdio.h>
2#include <string.h>
3#include <unistd.h>
4#include <inttypes.h>
5
Austin Schuh8aec1ed2016-05-01 13:29:20 -07006#include <chrono>
Comran Morshed9a9948c2016-01-16 15:58:04 +00007#include <thread>
8#include <mutex>
9#include <functional>
Brian Silverman68cb5c22016-03-20 18:11:14 -070010#include <array>
Comran Morshed9a9948c2016-01-16 15:58:04 +000011
12#include "Encoder.h"
13#include "Talon.h"
Austin Schuh8b89d332016-03-24 20:19:12 -070014#include "Relay.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000015#include "DriverStation.h"
16#include "AnalogInput.h"
17#include "Compressor.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000018#include "frc971/wpilib/wpilib_robot_base.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000019#ifndef WPILIB2015
20#include "DigitalGlitchFilter.h"
21#endif
22#undef ERROR
23
24#include "aos/common/logging/logging.h"
25#include "aos/common/logging/queue_logging.h"
26#include "aos/common/time.h"
27#include "aos/common/util/log_interval.h"
28#include "aos/common/util/phased_loop.h"
29#include "aos/common/util/wrapping_counter.h"
30#include "aos/common/stl_mutex.h"
31#include "aos/linux_code/init.h"
32#include "aos/common/messages/robot_state.q.h"
Austin Schuhcaa1ee92016-02-27 14:45:37 -080033#include "aos/common/commonmath.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000034
Philipp Schrader4bd29b12017-02-22 04:42:27 +000035#include "frc971/autonomous/auto.q.h"
Comran Morshed225f0b92016-02-10 20:34:27 +000036#include "frc971/control_loops/control_loops.q.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000037#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Comran Morshedb79c4242016-02-06 18:27:26 +000038#include "y2016/control_loops/shooter/shooter.q.h"
Comran Morshed6c6a0a92016-01-17 12:45:16 +000039#include "y2016/constants.h"
Comran Morshed5bb12112016-02-16 13:48:57 +000040#include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Comran Morshed225f0b92016-02-10 20:34:27 +000041#include "y2016/control_loops/shooter/shooter.q.h"
42#include "y2016/control_loops/superstructure/superstructure.q.h"
Comran Morshedaa0573c2016-03-05 19:05:54 +000043#include "y2016/queues/ball_detector.q.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000044
45#include "frc971/wpilib/joystick_sender.h"
46#include "frc971/wpilib/loop_output_handler.h"
47#include "frc971/wpilib/buffered_solenoid.h"
48#include "frc971/wpilib/buffered_pcm.h"
49#include "frc971/wpilib/gyro_sender.h"
50#include "frc971/wpilib/dma_edge_counting.h"
51#include "frc971/wpilib/interrupt_edge_counting.h"
52#include "frc971/wpilib/encoder_and_potentiometer.h"
53#include "frc971/wpilib/logging.q.h"
54#include "frc971/wpilib/wpilib_interface.h"
55#include "frc971/wpilib/pdp_fetcher.h"
Brian Silverman5f17a972016-02-28 01:49:32 -050056#include "frc971/wpilib/ADIS16448.h"
Brian Silvermanb5b46ca2016-03-13 01:14:17 -050057#include "frc971/wpilib/dma.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000058
59#ifndef M_PI
60#define M_PI 3.14159265358979323846
61#endif
62
63using ::frc971::control_loops::drivetrain_queue;
Comran Morshed225f0b92016-02-10 20:34:27 +000064using ::y2016::control_loops::shooter::shooter_queue;
65using ::y2016::control_loops::superstructure_queue;
Comran Morshed9a9948c2016-01-16 15:58:04 +000066
Comran Morshed6c6a0a92016-01-17 12:45:16 +000067namespace y2016 {
Comran Morshed9a9948c2016-01-16 15:58:04 +000068namespace wpilib {
Austin Schuha9992ff2016-02-28 21:59:23 -080069namespace {
70constexpr double kMaxBringupPower = 12.0;
71} // namespace
Comran Morshed9a9948c2016-01-16 15:58:04 +000072
73// TODO(Brian): Fix the interpretation of the result of GetRaw here and in the
74// DMA stuff and then removing the * 2.0 in *_translate.
75// The low bit is direction.
76
77// TODO(brian): Replace this with ::std::make_unique once all our toolchains
78// have support.
79template <class T, class... U>
80std::unique_ptr<T> make_unique(U &&... u) {
81 return std::unique_ptr<T>(new T(std::forward<U>(u)...));
82}
83
Comran Morshed225f0b92016-02-10 20:34:27 +000084// Translates for the sensor values to convert raw index pulses into something
85// with proper units.
86
87// TODO(comran): Template these methods since there is a lot of repetition here.
88double hall_translate(double in) {
89 // Turn voltage from our 3-state halls into a ratio that the loop can use.
90 return in / 5.0;
91}
92
Comran Morshed9a9948c2016-01-16 15:58:04 +000093double drivetrain_translate(int32_t in) {
Comran Morshed6c6a0a92016-01-17 12:45:16 +000094 return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +000095 constants::Values::kDrivetrainEncoderRatio *
Austin Schuh9f77fd22016-02-21 02:53:58 -080096 control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
Comran Morshed9a9948c2016-01-16 15:58:04 +000097}
98
99double drivetrain_velocity_translate(double in) {
100 return (1.0 / in) / 256.0 /*cpr*/ *
Comran Morshed225f0b92016-02-10 20:34:27 +0000101 constants::Values::kDrivetrainEncoderRatio *
Austin Schuh9f77fd22016-02-21 02:53:58 -0800102 control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000103}
104
Comran Morshed225f0b92016-02-10 20:34:27 +0000105double shooter_translate(int32_t in) {
Comran Morshed5bb12112016-02-16 13:48:57 +0000106 return -static_cast<double>(in) / (128.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +0000107 constants::Values::kShooterEncoderRatio * (2 * M_PI /*radians*/);
108}
Comran Morshed9a9948c2016-01-16 15:58:04 +0000109
Comran Morshed225f0b92016-02-10 20:34:27 +0000110double intake_translate(int32_t in) {
Austin Schuh9f77fd22016-02-21 02:53:58 -0800111 return static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +0000112 constants::Values::kIntakeEncoderRatio * (2 * M_PI /*radians*/);
113}
114
115double shoulder_translate(int32_t in) {
116 return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
117 constants::Values::kShoulderEncoderRatio * (2 * M_PI /*radians*/);
118}
119
120double wrist_translate(int32_t in) {
121 return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
122 constants::Values::kWristEncoderRatio * (2 * M_PI /*radians*/);
123}
124
125double intake_pot_translate(double voltage) {
126 return voltage * constants::Values::kIntakePotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000127 (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed225f0b92016-02-10 20:34:27 +0000128}
129
130double shoulder_pot_translate(double voltage) {
131 return voltage * constants::Values::kShoulderPotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000132 (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed225f0b92016-02-10 20:34:27 +0000133}
134
135double wrist_pot_translate(double voltage) {
136 return voltage * constants::Values::kWristPotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000137 (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000138}
139
Comran Morshed1b764322016-02-14 20:18:12 +0000140constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
141 5600.0 /* CIM free speed RPM */ * 14.0 / 48.0 /* 1st reduction */ * 28.0 /
142 50.0 /* 2nd reduction (high gear) */ * 30.0 / 44.0 /* encoder gears */ /
143 60.0 /* seconds per minute */ * 256.0 /* CPR */ * 4 /* edges per cycle */;
144
145constexpr double kMaxShooterEncoderPulsesPerSecond =
146 18700.0 /* 775pro free speed RPM */ * 12.0 /
147 18.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ *
148 128.0 /* CPR */ * 4 /* edges per cycle */;
149
150double kMaxDrivetrainShooterEncoderPulsesPerSecond = ::std::max(
151 kMaxDrivetrainEncoderPulsesPerSecond, kMaxShooterEncoderPulsesPerSecond);
152
153constexpr double kMaxSuperstructureEncoderPulsesPerSecond =
154 18700.0 /* 775pro free speed RPM */ * 12.0 /
155 56.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ *
156 512.0 /* CPR */ * 4 /* index pulse every quarter cycle */;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000157
Comran Morshed225f0b92016-02-10 20:34:27 +0000158// Class to send position messages with sensor readings to our loops.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000159class SensorReader {
160 public:
161 SensorReader() {
162 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
163 // we should ever see.
Comran Morshed1b764322016-02-14 20:18:12 +0000164 drivetrain_shooter_encoder_filter_.SetPeriodNanoSeconds(
165 static_cast<int>(1 / 4.0 /* built-in tolerance */ /
166 kMaxDrivetrainShooterEncoderPulsesPerSecond * 1e9 +
167 0.5));
168 superstructure_encoder_filter_.SetPeriodNanoSeconds(
169 static_cast<int>(1 / 4.0 /* built-in tolerance */ /
170 kMaxSuperstructureEncoderPulsesPerSecond * 1e9 +
171 0.5));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000172 hall_filter_.SetPeriodNanoSeconds(100000);
173 }
174
Comran Morshed225f0b92016-02-10 20:34:27 +0000175 // Drivetrain setters.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000176 void set_drivetrain_left_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000177 drivetrain_shooter_encoder_filter_.Add(encoder.get());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000178 drivetrain_left_encoder_ = ::std::move(encoder);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000179 }
180
181 void set_drivetrain_right_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000182 drivetrain_shooter_encoder_filter_.Add(encoder.get());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000183 drivetrain_right_encoder_ = ::std::move(encoder);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000184 }
185
Comran Morshed225f0b92016-02-10 20:34:27 +0000186 void set_drivetrain_left_hall(::std::unique_ptr<AnalogInput> analog) {
187 drivetrain_left_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000188 }
189
Comran Morshed225f0b92016-02-10 20:34:27 +0000190 void set_drivetrain_right_hall(::std::unique_ptr<AnalogInput> analog) {
191 drivetrain_right_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000192 }
193
Comran Morshed225f0b92016-02-10 20:34:27 +0000194 // Shooter setters.
195 void set_shooter_left_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000196 drivetrain_shooter_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000197 shooter_left_encoder_ = ::std::move(encoder);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000198 }
199
Comran Morshed225f0b92016-02-10 20:34:27 +0000200 void set_shooter_right_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000201 drivetrain_shooter_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000202 shooter_right_encoder_ = ::std::move(encoder);
203 }
204
205 // Intake setters.
206 void set_intake_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000207 superstructure_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000208 intake_encoder_.set_encoder(::std::move(encoder));
209 }
210
211 void set_intake_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) {
212 intake_encoder_.set_potentiometer(::std::move(potentiometer));
213 }
214
215 void set_intake_index(::std::unique_ptr<DigitalInput> index) {
Comran Morshed1b764322016-02-14 20:18:12 +0000216 superstructure_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000217 intake_encoder_.set_index(::std::move(index));
218 }
219
220 // Shoulder setters.
221 void set_shoulder_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000222 superstructure_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000223 shoulder_encoder_.set_encoder(::std::move(encoder));
224 }
225
226 void set_shoulder_potentiometer(
227 ::std::unique_ptr<AnalogInput> potentiometer) {
228 shoulder_encoder_.set_potentiometer(::std::move(potentiometer));
229 }
230
231 void set_shoulder_index(::std::unique_ptr<DigitalInput> index) {
Comran Morshed1b764322016-02-14 20:18:12 +0000232 superstructure_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000233 shoulder_encoder_.set_index(::std::move(index));
234 }
235
236 // Wrist setters.
237 void set_wrist_encoder(::std::unique_ptr<Encoder> encoder) {
Comran Morshed1b764322016-02-14 20:18:12 +0000238 superstructure_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000239 wrist_encoder_.set_encoder(::std::move(encoder));
240 }
241
242 void set_wrist_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) {
243 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
244 }
245
246 void set_wrist_index(::std::unique_ptr<DigitalInput> index) {
Comran Morshed1b764322016-02-14 20:18:12 +0000247 superstructure_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000248 wrist_encoder_.set_index(::std::move(index));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000249 }
250
Comran Morshedaa0573c2016-03-05 19:05:54 +0000251 // Ball detector setter.
252 void set_ball_detector(::std::unique_ptr<AnalogInput> analog) {
253 ball_detector_ = ::std::move(analog);
254 }
255
Brian Silverman68cb5c22016-03-20 18:11:14 -0700256 // Autonomous mode switch setter.
257 void set_autonomous_mode(int i, ::std::unique_ptr<DigitalInput> sensor) {
258 autonomous_modes_.at(i) = ::std::move(sensor);
259 }
260
Comran Morshedaa0573c2016-03-05 19:05:54 +0000261
Comran Morshed9a9948c2016-01-16 15:58:04 +0000262 // All of the DMA-related set_* calls must be made before this, and it doesn't
263 // hurt to do all of them.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000264
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000265 void set_dma(::std::unique_ptr<DMA> dma) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000266 dma_synchronizer_.reset(
267 new ::frc971::wpilib::DMASynchronizer(::std::move(dma)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000268 dma_synchronizer_->Add(&intake_encoder_);
269 dma_synchronizer_->Add(&shoulder_encoder_);
270 dma_synchronizer_->Add(&wrist_encoder_);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000271 }
272
273 void operator()() {
274 ::aos::SetCurrentThreadName("SensorReader");
275
276 my_pid_ = getpid();
277 ds_ =
278#ifdef WPILIB2015
279 DriverStation::GetInstance();
280#else
281 &DriverStation::GetInstance();
282#endif
283
Comran Morshed9a9948c2016-01-16 15:58:04 +0000284 dma_synchronizer_->Start();
285
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700286 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
287 ::std::chrono::milliseconds(4));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000288
289 ::aos::SetCurrentThreadRealtimePriority(40);
290 while (run_) {
291 {
292 const int iterations = phased_loop.SleepUntilNext();
293 if (iterations != 1) {
294 LOG(WARNING, "SensorReader skipped %d iterations\n", iterations - 1);
295 }
296 }
297 RunIteration();
298 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000299 }
300
301 void RunIteration() {
302 ::frc971::wpilib::SendRobotState(my_pid_, ds_);
303
304 const auto &values = constants::GetValues();
305
306 {
307 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
308 drivetrain_message->right_encoder =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800309 drivetrain_translate(-drivetrain_right_encoder_->GetRaw());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000310 drivetrain_message->left_encoder =
311 -drivetrain_translate(drivetrain_left_encoder_->GetRaw());
312 drivetrain_message->left_speed =
313 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
314 drivetrain_message->right_speed =
315 drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod());
316
Comran Morshed9a9948c2016-01-16 15:58:04 +0000317 drivetrain_message->left_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000318 hall_translate(drivetrain_left_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000319 drivetrain_message->right_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000320 hall_translate(drivetrain_right_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000321
322 drivetrain_message.Send();
323 }
324
Comran Morshed9a9948c2016-01-16 15:58:04 +0000325 dma_synchronizer_->RunIteration();
Comran Morshed225f0b92016-02-10 20:34:27 +0000326
327 {
328 auto shooter_message = shooter_queue.position.MakeMessage();
329 shooter_message->theta_left =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800330 shooter_translate(-shooter_left_encoder_->GetRaw());
Comran Morshed225f0b92016-02-10 20:34:27 +0000331 shooter_message->theta_right =
332 shooter_translate(shooter_right_encoder_->GetRaw());
333 shooter_message.Send();
334 }
335
336 {
337 auto superstructure_message = superstructure_queue.position.MakeMessage();
338 CopyPotAndIndexPosition(intake_encoder_, &superstructure_message->intake,
339 intake_translate, intake_pot_translate, false,
340 values.intake.pot_offset);
341 CopyPotAndIndexPosition(shoulder_encoder_,
342 &superstructure_message->shoulder,
343 shoulder_translate, shoulder_pot_translate, false,
344 values.shoulder.pot_offset);
345 CopyPotAndIndexPosition(wrist_encoder_, &superstructure_message->wrist,
Austin Schuh9f77fd22016-02-21 02:53:58 -0800346 wrist_translate, wrist_pot_translate, true,
Comran Morshed225f0b92016-02-10 20:34:27 +0000347 values.wrist.pot_offset);
348
349 superstructure_message.Send();
350 }
Comran Morshedaa0573c2016-03-05 19:05:54 +0000351
352 {
353 auto ball_detector_message =
354 ::y2016::sensors::ball_detector.MakeMessage();
355 ball_detector_message->voltage = ball_detector_->GetVoltage();
356 LOG_STRUCT(DEBUG, "ball detector", *ball_detector_message);
357 ball_detector_message.Send();
358 }
Brian Silverman68cb5c22016-03-20 18:11:14 -0700359
360 {
Philipp Schrader4bd29b12017-02-22 04:42:27 +0000361 auto auto_mode_message = ::frc971::autonomous::auto_mode.MakeMessage();
Brian Silverman68cb5c22016-03-20 18:11:14 -0700362 auto_mode_message->mode = 0;
363 for (size_t i = 0; i < autonomous_modes_.size(); ++i) {
364 if (autonomous_modes_[i]->Get()) {
365 auto_mode_message->mode |= 1 << i;
366 }
367 }
368 LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message);
369 auto_mode_message.Send();
370 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000371 }
372
373 void Quit() { run_ = false; }
374
375 private:
Comran Morshed225f0b92016-02-10 20:34:27 +0000376 void CopyPotAndIndexPosition(
377 const ::frc971::wpilib::DMAEncoderAndPotentiometer &encoder,
378 ::frc971::PotAndIndexPosition *position,
379 ::std::function<double(int32_t)> encoder_translate,
380 ::std::function<double(double)> potentiometer_translate, bool reverse,
381 double pot_offset) {
382 const double multiplier = reverse ? -1.0 : 1.0;
383 position->encoder =
384 multiplier * encoder_translate(encoder.polled_encoder_value());
385 position->pot = multiplier * potentiometer_translate(
386 encoder.polled_potentiometer_voltage()) +
387 pot_offset;
388 position->latched_encoder =
389 multiplier * encoder_translate(encoder.last_encoder_value());
390 position->latched_pot =
391 multiplier *
392 potentiometer_translate(encoder.last_potentiometer_voltage()) +
393 pot_offset;
394 position->index_pulses = encoder.index_posedge_count();
395 }
396
Comran Morshed9a9948c2016-01-16 15:58:04 +0000397 int32_t my_pid_;
398 DriverStation *ds_;
399
400 ::std::unique_ptr<::frc971::wpilib::DMASynchronizer> dma_synchronizer_;
401
Comran Morshed225f0b92016-02-10 20:34:27 +0000402 ::std::unique_ptr<Encoder> drivetrain_left_encoder_,
403 drivetrain_right_encoder_;
404 ::std::unique_ptr<AnalogInput> drivetrain_left_hall_, drivetrain_right_hall_;
405
406 ::std::unique_ptr<Encoder> shooter_left_encoder_, shooter_right_encoder_;
Comran Morshedb79c4242016-02-06 18:27:26 +0000407 ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_,
408 shoulder_encoder_, wrist_encoder_;
Comran Morshedaa0573c2016-03-05 19:05:54 +0000409 ::std::unique_ptr<AnalogInput> ball_detector_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000410
Brian Silverman68cb5c22016-03-20 18:11:14 -0700411 ::std::array<::std::unique_ptr<DigitalInput>, 4> autonomous_modes_;
412
Comran Morshed9a9948c2016-01-16 15:58:04 +0000413 ::std::atomic<bool> run_{true};
Comran Morshed1b764322016-02-14 20:18:12 +0000414 DigitalGlitchFilter drivetrain_shooter_encoder_filter_, hall_filter_,
415 superstructure_encoder_filter_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000416};
417
418class SolenoidWriter {
419 public:
420 SolenoidWriter(const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
421 : pcm_(pcm),
Comran Morshedb79c4242016-02-06 18:27:26 +0000422 drivetrain_(".frc971.control_loops.drivetrain_queue.output"),
Austin Schuh843412b2016-03-20 16:48:46 -0700423 shooter_(".y2016.control_loops.shooter.shooter_queue.output"),
424 superstructure_(
425 ".y2016.control_loops.superstructure_queue.output") {
426 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000427
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800428 void set_compressor(::std::unique_ptr<Compressor> compressor) {
429 compressor_ = ::std::move(compressor);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000430 }
431
Comran Morshed71466fe2016-04-21 20:21:14 -0700432 void set_drivetrain_shifter(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000433 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700434 drivetrain_shifter_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000435 }
436
Comran Morshed71466fe2016-04-21 20:21:14 -0700437 void set_climber_trigger(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000438 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700439 climber_trigger_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000440 }
441
Austin Schuh843412b2016-03-20 16:48:46 -0700442 void set_traverse(
443 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
444 traverse_ = ::std::move(s);
445 }
446
447 void set_traverse_latch(
448 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
449 traverse_latch_ = ::std::move(s);
450 }
451
Comran Morshedb79c4242016-02-06 18:27:26 +0000452 void set_shooter_clamp(
453 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
454 shooter_clamp_ = ::std::move(s);
455 }
456
457 void set_shooter_pusher(
458 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
459 shooter_pusher_ = ::std::move(s);
460 }
461
Austin Schuhe0729a62016-03-12 21:54:17 -0800462 void set_lights(
463 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
464 lights_ = ::std::move(s);
465 }
466
Austin Schuh8b89d332016-03-24 20:19:12 -0700467 void set_flashlight(::std::unique_ptr<Relay> relay) {
468 flashlight_ = ::std::move(relay);
469 }
470
Comran Morshed9a9948c2016-01-16 15:58:04 +0000471 void operator()() {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800472 compressor_->Start();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000473 ::aos::SetCurrentThreadName("Solenoids");
474 ::aos::SetCurrentThreadRealtimePriority(27);
475
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700476 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(20),
477 ::std::chrono::milliseconds(1));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000478
479 while (run_) {
480 {
481 const int iterations = phased_loop.SleepUntilNext();
482 if (iterations != 1) {
483 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
484 }
485 }
486
487 {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000488 drivetrain_.FetchLatest();
489 if (drivetrain_.get()) {
490 LOG_STRUCT(DEBUG, "solenoids", *drivetrain_);
Comran Morshed71466fe2016-04-21 20:21:14 -0700491 drivetrain_shifter_->Set(
492 !(drivetrain_->left_high || drivetrain_->right_high));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000493 }
494 }
495
496 {
Comran Morshedb79c4242016-02-06 18:27:26 +0000497 shooter_.FetchLatest();
498 if (shooter_.get()) {
499 LOG_STRUCT(DEBUG, "solenoids", *shooter_);
500 shooter_clamp_->Set(shooter_->clamp_open);
501 shooter_pusher_->Set(shooter_->push_to_shooter);
Austin Schuhe0729a62016-03-12 21:54:17 -0800502 lights_->Set(shooter_->lights_on);
Austin Schuhb2c33382016-04-03 16:09:17 -0700503 if (shooter_->forwards_flashlight) {
504 if (shooter_->backwards_flashlight) {
505 flashlight_->Set(Relay::kOn);
506 } else {
507 flashlight_->Set(Relay::kReverse);
508 }
509 } else {
510 if (shooter_->backwards_flashlight) {
511 flashlight_->Set(Relay::kForward);
512 } else {
513 flashlight_->Set(Relay::kOff);
514 }
515 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000516 }
517 }
518
519 {
Austin Schuh843412b2016-03-20 16:48:46 -0700520 superstructure_.FetchLatest();
521 if (superstructure_.get()) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700522 LOG_STRUCT(DEBUG, "solenoids", *superstructure_);
523
524 climber_trigger_->Set(superstructure_->unfold_climber);
525
Austin Schuh843412b2016-03-20 16:48:46 -0700526 traverse_->Set(superstructure_->traverse_down);
527 traverse_latch_->Set(superstructure_->traverse_unlatched);
528 }
529 }
530
531 {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000532 ::frc971::wpilib::PneumaticsToLog to_log;
533 {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800534 to_log.compressor_on = compressor_->Enabled();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000535 }
536
537 pcm_->Flush();
538 to_log.read_solenoids = pcm_->GetAll();
539 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
540 }
541 }
542 }
543
544 void Quit() { run_ = false; }
545
546 private:
547 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
548
Comran Morshed71466fe2016-04-21 20:21:14 -0700549 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_,
550 shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_,
551 climber_trigger_;
Austin Schuh8b89d332016-03-24 20:19:12 -0700552 ::std::unique_ptr<Relay> flashlight_;
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800553 ::std::unique_ptr<Compressor> compressor_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000554
Comran Morshed9a9948c2016-01-16 15:58:04 +0000555 ::aos::Queue<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
Comran Morshed3263e8f2016-02-14 17:55:45 +0000556 ::aos::Queue<::y2016::control_loops::shooter::ShooterQueue::Output> shooter_;
Austin Schuh843412b2016-03-20 16:48:46 -0700557 ::aos::Queue<
558 ::y2016::control_loops::SuperstructureQueue::Output>
559 superstructure_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000560
561 ::std::atomic<bool> run_{true};
562};
563
564class DrivetrainWriter : public ::frc971::wpilib::LoopOutputHandler {
565 public:
Comran Morshed225f0b92016-02-10 20:34:27 +0000566 void set_drivetrain_left_talon(::std::unique_ptr<Talon> t) {
567 drivetrain_left_talon_ = ::std::move(t);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000568 }
569
Comran Morshed225f0b92016-02-10 20:34:27 +0000570 void set_drivetrain_right_talon(::std::unique_ptr<Talon> t) {
571 drivetrain_right_talon_ = ::std::move(t);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000572 }
573
574 private:
575 virtual void Read() override {
576 ::frc971::control_loops::drivetrain_queue.output.FetchAnother();
577 }
578
579 virtual void Write() override {
580 auto &queue = ::frc971::control_loops::drivetrain_queue.output;
581 LOG_STRUCT(DEBUG, "will output", *queue);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800582 drivetrain_left_talon_->SetSpeed(queue->left_voltage / 12.0);
583 drivetrain_right_talon_->SetSpeed(-queue->right_voltage / 12.0);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000584 }
585
586 virtual void Stop() override {
587 LOG(WARNING, "drivetrain output too old\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800588 drivetrain_left_talon_->SetDisabled();
589 drivetrain_right_talon_->SetDisabled();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000590 }
591
Comran Morshed225f0b92016-02-10 20:34:27 +0000592 ::std::unique_ptr<Talon> drivetrain_left_talon_, drivetrain_right_talon_;
593};
594
595class ShooterWriter : public ::frc971::wpilib::LoopOutputHandler {
596 public:
597 void set_shooter_left_talon(::std::unique_ptr<Talon> t) {
598 shooter_left_talon_ = ::std::move(t);
599 }
600
601 void set_shooter_right_talon(::std::unique_ptr<Talon> t) {
602 shooter_right_talon_ = ::std::move(t);
603 }
604
605 private:
606 virtual void Read() override {
607 ::y2016::control_loops::shooter::shooter_queue.output.FetchAnother();
608 }
609
610 virtual void Write() override {
611 auto &queue = ::y2016::control_loops::shooter::shooter_queue.output;
612 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800613
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800614 shooter_left_talon_->SetSpeed(queue->voltage_left / 12.0);
615 shooter_right_talon_->SetSpeed(-queue->voltage_right / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000616 }
617
618 virtual void Stop() override {
619 LOG(WARNING, "Shooter output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800620 shooter_left_talon_->SetDisabled();
621 shooter_right_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000622 }
623
624 ::std::unique_ptr<Talon> shooter_left_talon_, shooter_right_talon_;
625};
626
627class SuperstructureWriter : public ::frc971::wpilib::LoopOutputHandler {
628 public:
629 void set_intake_talon(::std::unique_ptr<Talon> t) {
630 intake_talon_ = ::std::move(t);
631 }
632
633 void set_shoulder_talon(::std::unique_ptr<Talon> t) {
634 shoulder_talon_ = ::std::move(t);
635 }
636
637 void set_wrist_talon(::std::unique_ptr<Talon> t) {
638 wrist_talon_ = ::std::move(t);
639 }
640
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800641 void set_top_rollers_talon(::std::unique_ptr<Talon> t) {
642 top_rollers_talon_ = ::std::move(t);
643 }
644
645 void set_bottom_rollers_talon(::std::unique_ptr<Talon> t) {
646 bottom_rollers_talon_ = ::std::move(t);
Comran Morshedf4cd7642016-02-15 20:40:49 +0000647 }
648
Comran Morshed71466fe2016-04-21 20:21:14 -0700649 void set_climber_talon(::std::unique_ptr<Talon> t) {
650 climber_talon_ = ::std::move(t);
651 }
652
Comran Morshed225f0b92016-02-10 20:34:27 +0000653 private:
654 virtual void Read() override {
655 ::y2016::control_loops::superstructure_queue.output.FetchAnother();
656 }
657
658 virtual void Write() override {
659 auto &queue = ::y2016::control_loops::superstructure_queue.output;
660 LOG_STRUCT(DEBUG, "will output", *queue);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800661 intake_talon_->SetSpeed(::aos::Clip(queue->voltage_intake,
662 -kMaxBringupPower, kMaxBringupPower) /
663 12.0);
664 shoulder_talon_->SetSpeed(::aos::Clip(-queue->voltage_shoulder,
665 -kMaxBringupPower, kMaxBringupPower) /
666 12.0);
667 wrist_talon_->SetSpeed(
Austin Schuha9992ff2016-02-28 21:59:23 -0800668 ::aos::Clip(queue->voltage_wrist, -kMaxBringupPower, kMaxBringupPower) /
669 12.0);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800670 top_rollers_talon_->SetSpeed(-queue->voltage_top_rollers / 12.0);
671 bottom_rollers_talon_->SetSpeed(-queue->voltage_bottom_rollers / 12.0);
672 climber_talon_->SetSpeed(-queue->voltage_climber / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000673 }
674
675 virtual void Stop() override {
676 LOG(WARNING, "Superstructure output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800677 intake_talon_->SetDisabled();
678 shoulder_talon_->SetDisabled();
679 wrist_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000680 }
681
Comran Morshedf4cd7642016-02-15 20:40:49 +0000682 ::std::unique_ptr<Talon> intake_talon_, shoulder_talon_, wrist_talon_,
Comran Morshed71466fe2016-04-21 20:21:14 -0700683 top_rollers_talon_, bottom_rollers_talon_, climber_talon_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000684};
685
Comran Morshed9a9948c2016-01-16 15:58:04 +0000686class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
687 public:
688 ::std::unique_ptr<Encoder> make_encoder(int index) {
689 return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false,
690 Encoder::k4X);
691 }
692
693 void Run() override {
694 ::aos::InitNRT();
695 ::aos::SetCurrentThreadName("StartCompetition");
696
697 ::frc971::wpilib::JoystickSender joystick_sender;
698 ::std::thread joystick_thread(::std::ref(joystick_sender));
699
700 ::frc971::wpilib::PDPFetcher pdp_fetcher;
701 ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
702 SensorReader reader;
703
Austin Schuh9f77fd22016-02-21 02:53:58 -0800704 reader.set_drivetrain_left_encoder(make_encoder(5));
705 reader.set_drivetrain_right_encoder(make_encoder(6));
706 reader.set_drivetrain_left_hall(make_unique<AnalogInput>(5));
707 reader.set_drivetrain_right_hall(make_unique<AnalogInput>(6));
Comran Morshed225f0b92016-02-10 20:34:27 +0000708
Austin Schuhf0c05762016-04-03 16:06:49 -0700709 reader.set_shooter_left_encoder(make_encoder(7));
710 reader.set_shooter_right_encoder(make_encoder(-3));
Comran Morshed225f0b92016-02-10 20:34:27 +0000711
712 reader.set_intake_encoder(make_encoder(0));
713 reader.set_intake_index(make_unique<DigitalInput>(0));
714 reader.set_intake_potentiometer(make_unique<AnalogInput>(0));
715
Austin Schuhf0c05762016-04-03 16:06:49 -0700716 reader.set_shoulder_encoder(make_encoder(4));
Austin Schuh9f77fd22016-02-21 02:53:58 -0800717 reader.set_shoulder_index(make_unique<DigitalInput>(2));
718 reader.set_shoulder_potentiometer(make_unique<AnalogInput>(2));
Comran Morshed225f0b92016-02-10 20:34:27 +0000719
Austin Schuh9f77fd22016-02-21 02:53:58 -0800720 reader.set_wrist_encoder(make_encoder(1));
721 reader.set_wrist_index(make_unique<DigitalInput>(1));
722 reader.set_wrist_potentiometer(make_unique<AnalogInput>(1));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000723
Comran Morshedaa0573c2016-03-05 19:05:54 +0000724 reader.set_ball_detector(make_unique<AnalogInput>(7));
725
Brian Silverman68cb5c22016-03-20 18:11:14 -0700726 reader.set_autonomous_mode(0, make_unique<DigitalInput>(9));
727 reader.set_autonomous_mode(1, make_unique<DigitalInput>(8));
728 reader.set_autonomous_mode(2, make_unique<DigitalInput>(7));
729 reader.set_autonomous_mode(3, make_unique<DigitalInput>(6));
730
Comran Morshed9a9948c2016-01-16 15:58:04 +0000731 reader.set_dma(make_unique<DMA>());
732 ::std::thread reader_thread(::std::ref(reader));
733
734 ::frc971::wpilib::GyroSender gyro_sender;
735 ::std::thread gyro_thread(::std::ref(gyro_sender));
736
Austin Schuhf0c05762016-04-03 16:06:49 -0700737 auto imu_trigger = make_unique<DigitalInput>(3);
738 ::frc971::wpilib::ADIS16448 imu(SPI::Port::kMXP, imu_trigger.get());
Brian Silverman5f17a972016-02-28 01:49:32 -0500739 ::std::thread imu_thread(::std::ref(imu));
Brian Silverman5f17a972016-02-28 01:49:32 -0500740
Comran Morshed9a9948c2016-01-16 15:58:04 +0000741 DrivetrainWriter drivetrain_writer;
Comran Morshed225f0b92016-02-10 20:34:27 +0000742 drivetrain_writer.set_drivetrain_left_talon(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000743 ::std::unique_ptr<Talon>(new Talon(5)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000744 drivetrain_writer.set_drivetrain_right_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800745 ::std::unique_ptr<Talon>(new Talon(4)));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000746 ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
747
Comran Morshed225f0b92016-02-10 20:34:27 +0000748 ShooterWriter shooter_writer;
749 shooter_writer.set_shooter_left_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800750 ::std::unique_ptr<Talon>(new Talon(9)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000751 shooter_writer.set_shooter_right_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800752 ::std::unique_ptr<Talon>(new Talon(8)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000753 ::std::thread shooter_writer_thread(::std::ref(shooter_writer));
754
755 SuperstructureWriter superstructure_writer;
756 superstructure_writer.set_intake_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800757 ::std::unique_ptr<Talon>(new Talon(3)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000758 superstructure_writer.set_shoulder_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800759 ::std::unique_ptr<Talon>(new Talon(6)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000760 superstructure_writer.set_wrist_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800761 ::std::unique_ptr<Talon>(new Talon(2)));
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800762 superstructure_writer.set_top_rollers_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800763 ::std::unique_ptr<Talon>(new Talon(1)));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800764 superstructure_writer.set_bottom_rollers_talon(
765 ::std::unique_ptr<Talon>(new Talon(0)));
Comran Morshed71466fe2016-04-21 20:21:14 -0700766 superstructure_writer.set_climber_talon(
767 ::std::unique_ptr<Talon>(new Talon(7)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000768 ::std::thread superstructure_writer_thread(
769 ::std::ref(superstructure_writer));
770
Comran Morshed9a9948c2016-01-16 15:58:04 +0000771 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
772 new ::frc971::wpilib::BufferedPcm());
773 SolenoidWriter solenoid_writer(pcm);
Comran Morshed71466fe2016-04-21 20:21:14 -0700774 solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0));
Austin Schuh843412b2016-03-20 16:48:46 -0700775 solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2));
776 solenoid_writer.set_traverse(pcm->MakeSolenoid(3));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800777 solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4));
778 solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5));
Austin Schuhe0729a62016-03-12 21:54:17 -0800779 solenoid_writer.set_lights(pcm->MakeSolenoid(6));
Comran Morshed71466fe2016-04-21 20:21:14 -0700780 solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1));
Austin Schuh8b89d332016-03-24 20:19:12 -0700781 solenoid_writer.set_flashlight(make_unique<Relay>(0));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000782
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800783 solenoid_writer.set_compressor(make_unique<Compressor>());
784
Comran Morshed9a9948c2016-01-16 15:58:04 +0000785 ::std::thread solenoid_thread(::std::ref(solenoid_writer));
786
787 // Wait forever. Not much else to do...
788 while (true) {
789 const int r = select(0, nullptr, nullptr, nullptr, nullptr);
790 if (r != 0) {
791 PLOG(WARNING, "infinite select failed");
792 } else {
793 PLOG(WARNING, "infinite select succeeded??\n");
794 }
795 }
796
797 LOG(ERROR, "Exiting WPILibRobot\n");
798
799 joystick_sender.Quit();
800 joystick_thread.join();
801 pdp_fetcher.Quit();
802 pdp_fetcher_thread.join();
803 reader.Quit();
804 reader_thread.join();
805 gyro_sender.Quit();
806 gyro_thread.join();
Brian Silverman5f17a972016-02-28 01:49:32 -0500807 imu.Quit();
808 imu_thread.join();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000809
810 drivetrain_writer.Quit();
811 drivetrain_writer_thread.join();
Comran Morshed225f0b92016-02-10 20:34:27 +0000812 shooter_writer.Quit();
813 shooter_writer_thread.join();
814 superstructure_writer.Quit();
815 superstructure_writer_thread.join();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000816 solenoid_writer.Quit();
817 solenoid_thread.join();
818
819 ::aos::Cleanup();
820 }
821};
822
823} // namespace wpilib
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000824} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000825
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000826AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot);