blob: 2f37bcba0264afe308adfcde34d613448202b412 [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();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000277
Comran Morshed9a9948c2016-01-16 15:58:04 +0000278 dma_synchronizer_->Start();
279
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700280 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
281 ::std::chrono::milliseconds(4));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000282
283 ::aos::SetCurrentThreadRealtimePriority(40);
284 while (run_) {
285 {
286 const int iterations = phased_loop.SleepUntilNext();
287 if (iterations != 1) {
288 LOG(WARNING, "SensorReader skipped %d iterations\n", iterations - 1);
289 }
290 }
291 RunIteration();
292 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000293 }
294
295 void RunIteration() {
Austin Schuh94f51e92017-10-30 19:25:32 -0700296 ::frc971::wpilib::SendRobotState(my_pid_);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000297
298 const auto &values = constants::GetValues();
299
300 {
301 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
302 drivetrain_message->right_encoder =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800303 drivetrain_translate(-drivetrain_right_encoder_->GetRaw());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000304 drivetrain_message->left_encoder =
305 -drivetrain_translate(drivetrain_left_encoder_->GetRaw());
306 drivetrain_message->left_speed =
307 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
308 drivetrain_message->right_speed =
309 drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod());
310
Comran Morshed9a9948c2016-01-16 15:58:04 +0000311 drivetrain_message->left_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000312 hall_translate(drivetrain_left_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000313 drivetrain_message->right_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000314 hall_translate(drivetrain_right_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000315
316 drivetrain_message.Send();
317 }
318
Comran Morshed9a9948c2016-01-16 15:58:04 +0000319 dma_synchronizer_->RunIteration();
Comran Morshed225f0b92016-02-10 20:34:27 +0000320
321 {
322 auto shooter_message = shooter_queue.position.MakeMessage();
323 shooter_message->theta_left =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800324 shooter_translate(-shooter_left_encoder_->GetRaw());
Comran Morshed225f0b92016-02-10 20:34:27 +0000325 shooter_message->theta_right =
326 shooter_translate(shooter_right_encoder_->GetRaw());
327 shooter_message.Send();
328 }
329
330 {
331 auto superstructure_message = superstructure_queue.position.MakeMessage();
332 CopyPotAndIndexPosition(intake_encoder_, &superstructure_message->intake,
333 intake_translate, intake_pot_translate, false,
334 values.intake.pot_offset);
335 CopyPotAndIndexPosition(shoulder_encoder_,
336 &superstructure_message->shoulder,
337 shoulder_translate, shoulder_pot_translate, false,
338 values.shoulder.pot_offset);
339 CopyPotAndIndexPosition(wrist_encoder_, &superstructure_message->wrist,
Austin Schuh9f77fd22016-02-21 02:53:58 -0800340 wrist_translate, wrist_pot_translate, true,
Comran Morshed225f0b92016-02-10 20:34:27 +0000341 values.wrist.pot_offset);
342
343 superstructure_message.Send();
344 }
Comran Morshedaa0573c2016-03-05 19:05:54 +0000345
346 {
347 auto ball_detector_message =
348 ::y2016::sensors::ball_detector.MakeMessage();
349 ball_detector_message->voltage = ball_detector_->GetVoltage();
350 LOG_STRUCT(DEBUG, "ball detector", *ball_detector_message);
351 ball_detector_message.Send();
352 }
Brian Silverman68cb5c22016-03-20 18:11:14 -0700353
354 {
Philipp Schrader4bd29b12017-02-22 04:42:27 +0000355 auto auto_mode_message = ::frc971::autonomous::auto_mode.MakeMessage();
Brian Silverman68cb5c22016-03-20 18:11:14 -0700356 auto_mode_message->mode = 0;
357 for (size_t i = 0; i < autonomous_modes_.size(); ++i) {
358 if (autonomous_modes_[i]->Get()) {
359 auto_mode_message->mode |= 1 << i;
360 }
361 }
362 LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message);
363 auto_mode_message.Send();
364 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000365 }
366
367 void Quit() { run_ = false; }
368
369 private:
Comran Morshed225f0b92016-02-10 20:34:27 +0000370 void CopyPotAndIndexPosition(
371 const ::frc971::wpilib::DMAEncoderAndPotentiometer &encoder,
372 ::frc971::PotAndIndexPosition *position,
373 ::std::function<double(int32_t)> encoder_translate,
374 ::std::function<double(double)> potentiometer_translate, bool reverse,
375 double pot_offset) {
376 const double multiplier = reverse ? -1.0 : 1.0;
377 position->encoder =
378 multiplier * encoder_translate(encoder.polled_encoder_value());
379 position->pot = multiplier * potentiometer_translate(
380 encoder.polled_potentiometer_voltage()) +
381 pot_offset;
382 position->latched_encoder =
383 multiplier * encoder_translate(encoder.last_encoder_value());
384 position->latched_pot =
385 multiplier *
386 potentiometer_translate(encoder.last_potentiometer_voltage()) +
387 pot_offset;
388 position->index_pulses = encoder.index_posedge_count();
389 }
390
Comran Morshed9a9948c2016-01-16 15:58:04 +0000391 int32_t my_pid_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000392
393 ::std::unique_ptr<::frc971::wpilib::DMASynchronizer> dma_synchronizer_;
394
Comran Morshed225f0b92016-02-10 20:34:27 +0000395 ::std::unique_ptr<Encoder> drivetrain_left_encoder_,
396 drivetrain_right_encoder_;
397 ::std::unique_ptr<AnalogInput> drivetrain_left_hall_, drivetrain_right_hall_;
398
399 ::std::unique_ptr<Encoder> shooter_left_encoder_, shooter_right_encoder_;
Comran Morshedb79c4242016-02-06 18:27:26 +0000400 ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_,
401 shoulder_encoder_, wrist_encoder_;
Comran Morshedaa0573c2016-03-05 19:05:54 +0000402 ::std::unique_ptr<AnalogInput> ball_detector_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000403
Brian Silverman68cb5c22016-03-20 18:11:14 -0700404 ::std::array<::std::unique_ptr<DigitalInput>, 4> autonomous_modes_;
405
Comran Morshed9a9948c2016-01-16 15:58:04 +0000406 ::std::atomic<bool> run_{true};
Comran Morshed1b764322016-02-14 20:18:12 +0000407 DigitalGlitchFilter drivetrain_shooter_encoder_filter_, hall_filter_,
408 superstructure_encoder_filter_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000409};
410
411class SolenoidWriter {
412 public:
413 SolenoidWriter(const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
414 : pcm_(pcm),
Comran Morshedb79c4242016-02-06 18:27:26 +0000415 drivetrain_(".frc971.control_loops.drivetrain_queue.output"),
Austin Schuh843412b2016-03-20 16:48:46 -0700416 shooter_(".y2016.control_loops.shooter.shooter_queue.output"),
417 superstructure_(
418 ".y2016.control_loops.superstructure_queue.output") {
419 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000420
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800421 void set_compressor(::std::unique_ptr<Compressor> compressor) {
422 compressor_ = ::std::move(compressor);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000423 }
424
Comran Morshed71466fe2016-04-21 20:21:14 -0700425 void set_drivetrain_shifter(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000426 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700427 drivetrain_shifter_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000428 }
429
Comran Morshed71466fe2016-04-21 20:21:14 -0700430 void set_climber_trigger(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000431 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700432 climber_trigger_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000433 }
434
Austin Schuh843412b2016-03-20 16:48:46 -0700435 void set_traverse(
436 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
437 traverse_ = ::std::move(s);
438 }
439
440 void set_traverse_latch(
441 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
442 traverse_latch_ = ::std::move(s);
443 }
444
Comran Morshedb79c4242016-02-06 18:27:26 +0000445 void set_shooter_clamp(
446 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
447 shooter_clamp_ = ::std::move(s);
448 }
449
450 void set_shooter_pusher(
451 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
452 shooter_pusher_ = ::std::move(s);
453 }
454
Austin Schuhe0729a62016-03-12 21:54:17 -0800455 void set_lights(
456 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
457 lights_ = ::std::move(s);
458 }
459
Austin Schuh8b89d332016-03-24 20:19:12 -0700460 void set_flashlight(::std::unique_ptr<Relay> relay) {
461 flashlight_ = ::std::move(relay);
462 }
463
Comran Morshed9a9948c2016-01-16 15:58:04 +0000464 void operator()() {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800465 compressor_->Start();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000466 ::aos::SetCurrentThreadName("Solenoids");
467 ::aos::SetCurrentThreadRealtimePriority(27);
468
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700469 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(20),
470 ::std::chrono::milliseconds(1));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000471
472 while (run_) {
473 {
474 const int iterations = phased_loop.SleepUntilNext();
475 if (iterations != 1) {
476 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
477 }
478 }
479
480 {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000481 drivetrain_.FetchLatest();
482 if (drivetrain_.get()) {
483 LOG_STRUCT(DEBUG, "solenoids", *drivetrain_);
Comran Morshed71466fe2016-04-21 20:21:14 -0700484 drivetrain_shifter_->Set(
485 !(drivetrain_->left_high || drivetrain_->right_high));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000486 }
487 }
488
489 {
Comran Morshedb79c4242016-02-06 18:27:26 +0000490 shooter_.FetchLatest();
491 if (shooter_.get()) {
492 LOG_STRUCT(DEBUG, "solenoids", *shooter_);
493 shooter_clamp_->Set(shooter_->clamp_open);
494 shooter_pusher_->Set(shooter_->push_to_shooter);
Austin Schuhe0729a62016-03-12 21:54:17 -0800495 lights_->Set(shooter_->lights_on);
Austin Schuhb2c33382016-04-03 16:09:17 -0700496 if (shooter_->forwards_flashlight) {
497 if (shooter_->backwards_flashlight) {
498 flashlight_->Set(Relay::kOn);
499 } else {
500 flashlight_->Set(Relay::kReverse);
501 }
502 } else {
503 if (shooter_->backwards_flashlight) {
504 flashlight_->Set(Relay::kForward);
505 } else {
506 flashlight_->Set(Relay::kOff);
507 }
508 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000509 }
510 }
511
512 {
Austin Schuh843412b2016-03-20 16:48:46 -0700513 superstructure_.FetchLatest();
514 if (superstructure_.get()) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700515 LOG_STRUCT(DEBUG, "solenoids", *superstructure_);
516
517 climber_trigger_->Set(superstructure_->unfold_climber);
518
Austin Schuh843412b2016-03-20 16:48:46 -0700519 traverse_->Set(superstructure_->traverse_down);
520 traverse_latch_->Set(superstructure_->traverse_unlatched);
521 }
522 }
523
524 {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000525 ::frc971::wpilib::PneumaticsToLog to_log;
526 {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800527 to_log.compressor_on = compressor_->Enabled();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000528 }
529
530 pcm_->Flush();
531 to_log.read_solenoids = pcm_->GetAll();
532 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
533 }
534 }
535 }
536
537 void Quit() { run_ = false; }
538
539 private:
540 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
541
Comran Morshed71466fe2016-04-21 20:21:14 -0700542 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_,
543 shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_,
544 climber_trigger_;
Austin Schuh8b89d332016-03-24 20:19:12 -0700545 ::std::unique_ptr<Relay> flashlight_;
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800546 ::std::unique_ptr<Compressor> compressor_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000547
Comran Morshed9a9948c2016-01-16 15:58:04 +0000548 ::aos::Queue<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
Comran Morshed3263e8f2016-02-14 17:55:45 +0000549 ::aos::Queue<::y2016::control_loops::shooter::ShooterQueue::Output> shooter_;
Austin Schuh843412b2016-03-20 16:48:46 -0700550 ::aos::Queue<
551 ::y2016::control_loops::SuperstructureQueue::Output>
552 superstructure_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000553
554 ::std::atomic<bool> run_{true};
555};
556
557class DrivetrainWriter : public ::frc971::wpilib::LoopOutputHandler {
558 public:
Comran Morshed225f0b92016-02-10 20:34:27 +0000559 void set_drivetrain_left_talon(::std::unique_ptr<Talon> t) {
560 drivetrain_left_talon_ = ::std::move(t);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000561 }
562
Comran Morshed225f0b92016-02-10 20:34:27 +0000563 void set_drivetrain_right_talon(::std::unique_ptr<Talon> t) {
564 drivetrain_right_talon_ = ::std::move(t);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000565 }
566
567 private:
568 virtual void Read() override {
569 ::frc971::control_loops::drivetrain_queue.output.FetchAnother();
570 }
571
572 virtual void Write() override {
573 auto &queue = ::frc971::control_loops::drivetrain_queue.output;
574 LOG_STRUCT(DEBUG, "will output", *queue);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800575 drivetrain_left_talon_->SetSpeed(queue->left_voltage / 12.0);
576 drivetrain_right_talon_->SetSpeed(-queue->right_voltage / 12.0);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000577 }
578
579 virtual void Stop() override {
580 LOG(WARNING, "drivetrain output too old\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800581 drivetrain_left_talon_->SetDisabled();
582 drivetrain_right_talon_->SetDisabled();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000583 }
584
Comran Morshed225f0b92016-02-10 20:34:27 +0000585 ::std::unique_ptr<Talon> drivetrain_left_talon_, drivetrain_right_talon_;
586};
587
588class ShooterWriter : public ::frc971::wpilib::LoopOutputHandler {
589 public:
590 void set_shooter_left_talon(::std::unique_ptr<Talon> t) {
591 shooter_left_talon_ = ::std::move(t);
592 }
593
594 void set_shooter_right_talon(::std::unique_ptr<Talon> t) {
595 shooter_right_talon_ = ::std::move(t);
596 }
597
598 private:
599 virtual void Read() override {
600 ::y2016::control_loops::shooter::shooter_queue.output.FetchAnother();
601 }
602
603 virtual void Write() override {
604 auto &queue = ::y2016::control_loops::shooter::shooter_queue.output;
605 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800606
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800607 shooter_left_talon_->SetSpeed(queue->voltage_left / 12.0);
608 shooter_right_talon_->SetSpeed(-queue->voltage_right / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000609 }
610
611 virtual void Stop() override {
612 LOG(WARNING, "Shooter output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800613 shooter_left_talon_->SetDisabled();
614 shooter_right_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000615 }
616
617 ::std::unique_ptr<Talon> shooter_left_talon_, shooter_right_talon_;
618};
619
620class SuperstructureWriter : public ::frc971::wpilib::LoopOutputHandler {
621 public:
622 void set_intake_talon(::std::unique_ptr<Talon> t) {
623 intake_talon_ = ::std::move(t);
624 }
625
626 void set_shoulder_talon(::std::unique_ptr<Talon> t) {
627 shoulder_talon_ = ::std::move(t);
628 }
629
630 void set_wrist_talon(::std::unique_ptr<Talon> t) {
631 wrist_talon_ = ::std::move(t);
632 }
633
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800634 void set_top_rollers_talon(::std::unique_ptr<Talon> t) {
635 top_rollers_talon_ = ::std::move(t);
636 }
637
638 void set_bottom_rollers_talon(::std::unique_ptr<Talon> t) {
639 bottom_rollers_talon_ = ::std::move(t);
Comran Morshedf4cd7642016-02-15 20:40:49 +0000640 }
641
Comran Morshed71466fe2016-04-21 20:21:14 -0700642 void set_climber_talon(::std::unique_ptr<Talon> t) {
643 climber_talon_ = ::std::move(t);
644 }
645
Comran Morshed225f0b92016-02-10 20:34:27 +0000646 private:
647 virtual void Read() override {
648 ::y2016::control_loops::superstructure_queue.output.FetchAnother();
649 }
650
651 virtual void Write() override {
652 auto &queue = ::y2016::control_loops::superstructure_queue.output;
653 LOG_STRUCT(DEBUG, "will output", *queue);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800654 intake_talon_->SetSpeed(::aos::Clip(queue->voltage_intake,
655 -kMaxBringupPower, kMaxBringupPower) /
656 12.0);
657 shoulder_talon_->SetSpeed(::aos::Clip(-queue->voltage_shoulder,
658 -kMaxBringupPower, kMaxBringupPower) /
659 12.0);
660 wrist_talon_->SetSpeed(
Austin Schuha9992ff2016-02-28 21:59:23 -0800661 ::aos::Clip(queue->voltage_wrist, -kMaxBringupPower, kMaxBringupPower) /
662 12.0);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800663 top_rollers_talon_->SetSpeed(-queue->voltage_top_rollers / 12.0);
664 bottom_rollers_talon_->SetSpeed(-queue->voltage_bottom_rollers / 12.0);
665 climber_talon_->SetSpeed(-queue->voltage_climber / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000666 }
667
668 virtual void Stop() override {
669 LOG(WARNING, "Superstructure output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800670 intake_talon_->SetDisabled();
671 shoulder_talon_->SetDisabled();
672 wrist_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000673 }
674
Comran Morshedf4cd7642016-02-15 20:40:49 +0000675 ::std::unique_ptr<Talon> intake_talon_, shoulder_talon_, wrist_talon_,
Comran Morshed71466fe2016-04-21 20:21:14 -0700676 top_rollers_talon_, bottom_rollers_talon_, climber_talon_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000677};
678
Comran Morshed9a9948c2016-01-16 15:58:04 +0000679class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
680 public:
681 ::std::unique_ptr<Encoder> make_encoder(int index) {
682 return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false,
683 Encoder::k4X);
684 }
685
686 void Run() override {
687 ::aos::InitNRT();
688 ::aos::SetCurrentThreadName("StartCompetition");
689
690 ::frc971::wpilib::JoystickSender joystick_sender;
691 ::std::thread joystick_thread(::std::ref(joystick_sender));
692
693 ::frc971::wpilib::PDPFetcher pdp_fetcher;
694 ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
695 SensorReader reader;
696
Austin Schuh9f77fd22016-02-21 02:53:58 -0800697 reader.set_drivetrain_left_encoder(make_encoder(5));
698 reader.set_drivetrain_right_encoder(make_encoder(6));
699 reader.set_drivetrain_left_hall(make_unique<AnalogInput>(5));
700 reader.set_drivetrain_right_hall(make_unique<AnalogInput>(6));
Comran Morshed225f0b92016-02-10 20:34:27 +0000701
Austin Schuhf0c05762016-04-03 16:06:49 -0700702 reader.set_shooter_left_encoder(make_encoder(7));
703 reader.set_shooter_right_encoder(make_encoder(-3));
Comran Morshed225f0b92016-02-10 20:34:27 +0000704
705 reader.set_intake_encoder(make_encoder(0));
706 reader.set_intake_index(make_unique<DigitalInput>(0));
707 reader.set_intake_potentiometer(make_unique<AnalogInput>(0));
708
Austin Schuhf0c05762016-04-03 16:06:49 -0700709 reader.set_shoulder_encoder(make_encoder(4));
Austin Schuh9f77fd22016-02-21 02:53:58 -0800710 reader.set_shoulder_index(make_unique<DigitalInput>(2));
711 reader.set_shoulder_potentiometer(make_unique<AnalogInput>(2));
Comran Morshed225f0b92016-02-10 20:34:27 +0000712
Austin Schuh9f77fd22016-02-21 02:53:58 -0800713 reader.set_wrist_encoder(make_encoder(1));
714 reader.set_wrist_index(make_unique<DigitalInput>(1));
715 reader.set_wrist_potentiometer(make_unique<AnalogInput>(1));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000716
Comran Morshedaa0573c2016-03-05 19:05:54 +0000717 reader.set_ball_detector(make_unique<AnalogInput>(7));
718
Brian Silverman68cb5c22016-03-20 18:11:14 -0700719 reader.set_autonomous_mode(0, make_unique<DigitalInput>(9));
720 reader.set_autonomous_mode(1, make_unique<DigitalInput>(8));
721 reader.set_autonomous_mode(2, make_unique<DigitalInput>(7));
722 reader.set_autonomous_mode(3, make_unique<DigitalInput>(6));
723
Comran Morshed9a9948c2016-01-16 15:58:04 +0000724 reader.set_dma(make_unique<DMA>());
725 ::std::thread reader_thread(::std::ref(reader));
726
Brian Silverman003a4732018-03-11 14:02:15 -0700727 // TODO(Brian): This interacts poorly with the SpiRxClearer in ADIS16448.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000728 ::frc971::wpilib::GyroSender gyro_sender;
729 ::std::thread gyro_thread(::std::ref(gyro_sender));
730
Austin Schuhf0c05762016-04-03 16:06:49 -0700731 auto imu_trigger = make_unique<DigitalInput>(3);
732 ::frc971::wpilib::ADIS16448 imu(SPI::Port::kMXP, imu_trigger.get());
Brian Silverman5f17a972016-02-28 01:49:32 -0500733 ::std::thread imu_thread(::std::ref(imu));
Brian Silverman5f17a972016-02-28 01:49:32 -0500734
Comran Morshed9a9948c2016-01-16 15:58:04 +0000735 DrivetrainWriter drivetrain_writer;
Comran Morshed225f0b92016-02-10 20:34:27 +0000736 drivetrain_writer.set_drivetrain_left_talon(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000737 ::std::unique_ptr<Talon>(new Talon(5)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000738 drivetrain_writer.set_drivetrain_right_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800739 ::std::unique_ptr<Talon>(new Talon(4)));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000740 ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
741
Comran Morshed225f0b92016-02-10 20:34:27 +0000742 ShooterWriter shooter_writer;
743 shooter_writer.set_shooter_left_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800744 ::std::unique_ptr<Talon>(new Talon(9)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000745 shooter_writer.set_shooter_right_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800746 ::std::unique_ptr<Talon>(new Talon(8)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000747 ::std::thread shooter_writer_thread(::std::ref(shooter_writer));
748
749 SuperstructureWriter superstructure_writer;
750 superstructure_writer.set_intake_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800751 ::std::unique_ptr<Talon>(new Talon(3)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000752 superstructure_writer.set_shoulder_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800753 ::std::unique_ptr<Talon>(new Talon(6)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000754 superstructure_writer.set_wrist_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800755 ::std::unique_ptr<Talon>(new Talon(2)));
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800756 superstructure_writer.set_top_rollers_talon(
Austin Schuh0c2b58c2016-02-21 17:23:46 -0800757 ::std::unique_ptr<Talon>(new Talon(1)));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800758 superstructure_writer.set_bottom_rollers_talon(
759 ::std::unique_ptr<Talon>(new Talon(0)));
Comran Morshed71466fe2016-04-21 20:21:14 -0700760 superstructure_writer.set_climber_talon(
761 ::std::unique_ptr<Talon>(new Talon(7)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000762 ::std::thread superstructure_writer_thread(
763 ::std::ref(superstructure_writer));
764
Comran Morshed9a9948c2016-01-16 15:58:04 +0000765 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
766 new ::frc971::wpilib::BufferedPcm());
767 SolenoidWriter solenoid_writer(pcm);
Comran Morshed71466fe2016-04-21 20:21:14 -0700768 solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0));
Austin Schuh843412b2016-03-20 16:48:46 -0700769 solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2));
770 solenoid_writer.set_traverse(pcm->MakeSolenoid(3));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800771 solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4));
772 solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5));
Austin Schuhe0729a62016-03-12 21:54:17 -0800773 solenoid_writer.set_lights(pcm->MakeSolenoid(6));
Comran Morshed71466fe2016-04-21 20:21:14 -0700774 solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1));
Austin Schuh8b89d332016-03-24 20:19:12 -0700775 solenoid_writer.set_flashlight(make_unique<Relay>(0));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000776
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800777 solenoid_writer.set_compressor(make_unique<Compressor>());
778
Comran Morshed9a9948c2016-01-16 15:58:04 +0000779 ::std::thread solenoid_thread(::std::ref(solenoid_writer));
780
781 // Wait forever. Not much else to do...
782 while (true) {
783 const int r = select(0, nullptr, nullptr, nullptr, nullptr);
784 if (r != 0) {
785 PLOG(WARNING, "infinite select failed");
786 } else {
787 PLOG(WARNING, "infinite select succeeded??\n");
788 }
789 }
790
791 LOG(ERROR, "Exiting WPILibRobot\n");
792
793 joystick_sender.Quit();
794 joystick_thread.join();
795 pdp_fetcher.Quit();
796 pdp_fetcher_thread.join();
797 reader.Quit();
798 reader_thread.join();
799 gyro_sender.Quit();
800 gyro_thread.join();
Brian Silverman5f17a972016-02-28 01:49:32 -0500801 imu.Quit();
802 imu_thread.join();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000803
804 drivetrain_writer.Quit();
805 drivetrain_writer_thread.join();
Comran Morshed225f0b92016-02-10 20:34:27 +0000806 shooter_writer.Quit();
807 shooter_writer_thread.join();
808 superstructure_writer.Quit();
809 superstructure_writer_thread.join();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000810 solenoid_writer.Quit();
811 solenoid_thread.join();
812
813 ::aos::Cleanup();
814 }
815};
816
817} // namespace wpilib
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000818} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000819
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000820AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot);