blob: 0c643b42ffff8ee30df587ee5758b7c45274cdaa [file] [log] [blame]
Austin Schuh010eb812014-10-25 18:06:49 -07001#include <stdio.h>
2#include <string.h>
Austin Schuh010eb812014-10-25 18:06:49 -07003#include <unistd.h>
4#include <inttypes.h>
5
Austin Schuh8aec1ed2016-05-01 13:29:20 -07006#include <chrono>
Brian Silvermand8f403a2014-12-13 19:12:04 -05007#include <functional>
Austin Schuh8aec1ed2016-05-01 13:29:20 -07008#include <mutex>
9#include <thread>
Brian Silvermand8f403a2014-12-13 19:12:04 -050010
Austin Schuh6d5d9ae2015-10-31 19:39:57 -070011#include "Encoder.h"
12#include "Talon.h"
13#include "DriverStation.h"
14#include "AnalogInput.h"
15#include "Compressor.h"
16#include "Relay.h"
Campbell Crowleyc0cfb132015-12-30 20:58:02 -080017#include "frc971/wpilib/wpilib_robot_base.h"
Austin Schuh6d5d9ae2015-10-31 19:39:57 -070018#ifndef WPILIB2015
19#include "DigitalGlitchFilter.h"
20#endif
21#undef ERROR
22
Austin Schuh010eb812014-10-25 18:06:49 -070023#include "aos/common/logging/logging.h"
24#include "aos/common/logging/queue_logging.h"
Austin Schuh010eb812014-10-25 18:06:49 -070025#include "aos/common/time.h"
26#include "aos/common/util/log_interval.h"
27#include "aos/common/util/phased_loop.h"
28#include "aos/common/util/wrapping_counter.h"
Brian Silvermanb073f242014-09-08 16:29:57 -040029#include "aos/common/stl_mutex.h"
Austin Schuh010eb812014-10-25 18:06:49 -070030#include "aos/linux_code/init.h"
Brian Silverman699f0cb2015-02-05 19:45:01 -050031#include "aos/common/messages/robot_state.q.h"
Austin Schuh010eb812014-10-25 18:06:49 -070032
Brian Silverman335c20e2015-01-26 21:47:58 -050033#include "frc971/control_loops/control_loops.q.h"
Brian Silverman811f8ec2015-12-06 01:29:42 -050034
Austin Schuh70810b92016-11-26 14:55:34 -080035#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Brian Silvermand8f403a2014-12-13 19:12:04 -050036#include "frc971/wpilib/buffered_pcm.h"
Austin Schuh70810b92016-11-26 14:55:34 -080037#include "frc971/wpilib/buffered_solenoid.h"
Brian Silvermanb5b46ca2016-03-13 01:14:17 -050038#include "frc971/wpilib/dma.h"
Austin Schuh70810b92016-11-26 14:55:34 -080039#include "frc971/wpilib/dma_edge_counting.h"
40#include "frc971/wpilib/encoder_and_potentiometer.h"
41#include "frc971/wpilib/gyro_sender.h"
42#include "frc971/wpilib/interrupt_edge_counting.h"
43#include "frc971/wpilib/joystick_sender.h"
44#include "frc971/wpilib/logging.q.h"
45#include "frc971/wpilib/loop_output_handler.h"
46#include "frc971/wpilib/pdp_fetcher.h"
47#include "frc971/wpilib/wpilib_interface.h"
48#include "y2015/autonomous/auto.q.h"
49#include "y2015/constants.h"
50#include "y2015/control_loops/claw/claw.q.h"
51#include "y2015/control_loops/fridge/fridge.q.h"
Brian Silvermanda45b6c2014-12-28 11:36:50 -080052
Austin Schuh010eb812014-10-25 18:06:49 -070053#ifndef M_PI
54#define M_PI 3.14159265358979323846
55#endif
56
57using ::aos::util::SimpleLogInterval;
Austin Schuh88af0852016-12-04 20:31:32 -080058using ::frc971::PotAndIndexPosition;
Brian Silvermanada5f2c2015-02-01 02:41:14 -050059using ::frc971::control_loops::drivetrain_queue;
Austin Schuh88af0852016-12-04 20:31:32 -080060using ::frc971::wpilib::BufferedPcm;
61using ::frc971::wpilib::BufferedSolenoid;
62using ::frc971::wpilib::DMAEncoderAndPotentiometer;
63using ::frc971::wpilib::DMASynchronizer;
64using ::frc971::wpilib::GyroSender;
65using ::frc971::wpilib::InterruptEncoderAndPotentiometer;
66using ::frc971::wpilib::JoystickSender;
67using ::frc971::wpilib::LoopOutputHandler;
68using ::frc971::wpilib::PneumaticsToLog;
69using ::y2015::control_loops::claw_queue;
70using ::y2015::control_loops::fridge::fridge_queue;
Austin Schuhf2a50ba2016-12-24 16:16:26 -080071namespace chrono = ::std::chrono;
Austin Schuh010eb812014-10-25 18:06:49 -070072
Austin Schuh88af0852016-12-04 20:31:32 -080073namespace y2015 {
Brian Silvermanda45b6c2014-12-28 11:36:50 -080074namespace wpilib {
Austin Schuh010eb812014-10-25 18:06:49 -070075
Austin Schuh010eb812014-10-25 18:06:49 -070076double drivetrain_translate(int32_t in) {
Austin Schuhdb516032014-12-28 00:12:38 -080077 return static_cast<double>(in) /
Daniel Pettiadf38432015-01-26 17:13:35 -080078 (256.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -080079 constants::GetValues().drivetrain_encoder_ratio *
Daniel Pettiadf38432015-01-26 17:13:35 -080080 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
81}
82
Brian Silverman51091a02015-12-26 15:56:58 -080083double drivetrain_velocity_translate(double in) {
84 return (1.0 / in) / 256.0 /*cpr*/ *
85 constants::GetValues().drivetrain_encoder_ratio *
86 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
87}
88
Daniel Pettiadf38432015-01-26 17:13:35 -080089double arm_translate(int32_t in) {
Austin Schuh6246c542015-02-16 02:59:09 -080090 return -static_cast<double>(in) /
Daniel Pettiadf38432015-01-26 17:13:35 -080091 (512.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -080092 constants::GetValues().arm_encoder_ratio *
Daniel Pettiadf38432015-01-26 17:13:35 -080093 (2 * M_PI /*radians*/);
94}
95
Brian Silverman5d712fc2015-02-15 03:39:31 -050096double arm_potentiometer_translate(double voltage) {
Austin Schuh35d06612015-02-15 23:35:23 -080097 return voltage *
Daniel Pettia7827412015-02-13 20:55:57 -080098 constants::GetValues().arm_pot_ratio *
Austin Schuh35d06612015-02-15 23:35:23 -080099 (5.0 /*turns*/ / 5.0 /*volts*/) *
Daniel Pettiadf38432015-01-26 17:13:35 -0800100 (2 * M_PI /*radians*/);
101}
102
103double elevator_translate(int32_t in) {
104 return static_cast<double>(in) /
105 (512.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -0800106 constants::GetValues().elev_encoder_ratio *
107 (2 * M_PI /*radians*/) *
108 constants::GetValues().elev_distance_per_radian;
Daniel Pettiadf38432015-01-26 17:13:35 -0800109}
110
Brian Silverman5d712fc2015-02-15 03:39:31 -0500111double elevator_potentiometer_translate(double voltage) {
Austin Schuh6246c542015-02-16 02:59:09 -0800112 return -voltage *
Daniel Pettia7827412015-02-13 20:55:57 -0800113 constants::GetValues().elev_pot_ratio *
114 (2 * M_PI /*radians*/) *
115 constants::GetValues().elev_distance_per_radian *
Austin Schuh35d06612015-02-15 23:35:23 -0800116 (5.0 /*turns*/ / 5.0 /*volts*/);
Daniel Pettiadf38432015-01-26 17:13:35 -0800117}
118
119double claw_translate(int32_t in) {
120 return static_cast<double>(in) /
121 (512.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -0800122 constants::GetValues().claw_encoder_ratio *
Daniel Pettiadf38432015-01-26 17:13:35 -0800123 (2 * M_PI /*radians*/);
124}
125
Brian Silverman5d712fc2015-02-15 03:39:31 -0500126double claw_potentiometer_translate(double voltage) {
Austin Schuh6246c542015-02-16 02:59:09 -0800127 return -voltage *
Daniel Pettia7827412015-02-13 20:55:57 -0800128 constants::GetValues().claw_pot_ratio *
Austin Schuh35d06612015-02-15 23:35:23 -0800129 (5.0 /*turns*/ / 5.0 /*volts*/) *
Daniel Pettiadf38432015-01-26 17:13:35 -0800130 (2 * M_PI /*radians*/);
Austin Schuh010eb812014-10-25 18:06:49 -0700131}
132
Brian Silverman335c20e2015-01-26 21:47:58 -0500133static const double kMaximumEncoderPulsesPerSecond =
134 19500.0 /* free speed RPM */ * 12.0 / 56.0 /* belt reduction */ /
135 60.0 /* seconds / minute */ * 256.0 /* CPR */ *
136 4.0 /* index pulse = 1/4 cycle */;
137
Austin Schuh010eb812014-10-25 18:06:49 -0700138class SensorReader {
139 public:
Brian Silverman39b339e2016-01-03 13:24:22 -0800140 SensorReader() {
Brian Silverman335c20e2015-01-26 21:47:58 -0500141 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
142 // we should ever see.
143 filter_.SetPeriodNanoSeconds(
144 static_cast<int>(1 / 4.0 / kMaximumEncoderPulsesPerSecond * 1e9 + 0.5));
145 }
146
147 void set_arm_left_encoder(::std::unique_ptr<Encoder> encoder) {
148 filter_.Add(encoder.get());
149 arm_left_encoder_.set_encoder(::std::move(encoder));
150 }
151
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700152 void set_arm_left_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500153 filter_.Add(index.get());
154 arm_left_encoder_.set_index(::std::move(index));
155 }
156
157 void set_arm_left_potentiometer(
158 ::std::unique_ptr<AnalogInput> potentiometer) {
159 arm_left_encoder_.set_potentiometer(::std::move(potentiometer));
160 }
161
162 void set_arm_right_encoder(::std::unique_ptr<Encoder> encoder) {
163 filter_.Add(encoder.get());
164 arm_right_encoder_.set_encoder(::std::move(encoder));
165 }
166
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700167 void set_arm_right_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500168 filter_.Add(index.get());
169 arm_right_encoder_.set_index(::std::move(index));
170 }
171
172 void set_arm_right_potentiometer(
173 ::std::unique_ptr<AnalogInput> potentiometer) {
174 arm_right_encoder_.set_potentiometer(::std::move(potentiometer));
175 }
176
177 void set_elevator_left_encoder(::std::unique_ptr<Encoder> encoder) {
178 filter_.Add(encoder.get());
179 elevator_left_encoder_.set_encoder(::std::move(encoder));
180 }
181
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700182 void set_elevator_left_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500183 filter_.Add(index.get());
184 elevator_left_encoder_.set_index(::std::move(index));
185 }
186
187 void set_elevator_left_potentiometer(
188 ::std::unique_ptr<AnalogInput> potentiometer) {
189 elevator_left_encoder_.set_potentiometer(::std::move(potentiometer));
190 }
191
192 void set_elevator_right_encoder(::std::unique_ptr<Encoder> encoder) {
193 filter_.Add(encoder.get());
194 elevator_right_encoder_.set_encoder(::std::move(encoder));
195 }
196
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700197 void set_elevator_right_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500198 filter_.Add(index.get());
199 elevator_right_encoder_.set_index(::std::move(index));
200 }
201
202 void set_elevator_right_potentiometer(
203 ::std::unique_ptr<AnalogInput> potentiometer) {
204 elevator_right_encoder_.set_potentiometer(::std::move(potentiometer));
205 }
206
207 void set_wrist_encoder(::std::unique_ptr<Encoder> encoder) {
208 filter_.Add(encoder.get());
209 wrist_encoder_.set_encoder(::std::move(encoder));
210 }
211
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700212 void set_wrist_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500213 filter_.Add(index.get());
214 wrist_encoder_.set_index(::std::move(index));
215 }
216
217 void set_wrist_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) {
218 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
Austin Schuh010eb812014-10-25 18:06:49 -0700219 }
220
Brian Silverman1f90d672015-01-26 20:20:45 -0500221 void set_left_encoder(::std::unique_ptr<Encoder> left_encoder) {
222 left_encoder_ = ::std::move(left_encoder);
Brian Silverman51091a02015-12-26 15:56:58 -0800223 left_encoder_->SetMaxPeriod(0.005);
Brian Silverman1f90d672015-01-26 20:20:45 -0500224 }
225
226 void set_right_encoder(::std::unique_ptr<Encoder> right_encoder) {
227 right_encoder_ = ::std::move(right_encoder);
Brian Silverman51091a02015-12-26 15:56:58 -0800228 right_encoder_->SetMaxPeriod(0.005);
Brian Silverman1f90d672015-01-26 20:20:45 -0500229 }
230
Brian Silverman335c20e2015-01-26 21:47:58 -0500231 // All of the DMA-related set_* calls must be made before this, and it doesn't
232 // hurt to do all of them.
233 void set_dma(::std::unique_ptr<DMA> dma) {
234 dma_synchronizer_.reset(new DMASynchronizer(::std::move(dma)));
235 dma_synchronizer_->Add(&arm_left_encoder_);
Brian Silverman335c20e2015-01-26 21:47:58 -0500236 dma_synchronizer_->Add(&elevator_left_encoder_);
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800237 dma_synchronizer_->Add(&arm_right_encoder_);
Brian Silverman335c20e2015-01-26 21:47:58 -0500238 dma_synchronizer_->Add(&elevator_right_encoder_);
239 }
240
Austin Schuh010eb812014-10-25 18:06:49 -0700241 void operator()() {
Brian Silverman2fe007c2014-12-28 12:20:01 -0800242 ::aos::SetCurrentThreadName("SensorReader");
243
Brian Silverman699f0cb2015-02-05 19:45:01 -0500244 my_pid_ = getpid();
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700245 ds_ =
246#ifdef WPILIB2015
247 DriverStation::GetInstance();
248#else
249 &DriverStation::GetInstance();
250#endif
Brian Silverman699f0cb2015-02-05 19:45:01 -0500251
Brian Silverman335c20e2015-01-26 21:47:58 -0500252 wrist_encoder_.Start();
253 dma_synchronizer_->Start();
Austin Schuh010eb812014-10-25 18:06:49 -0700254
Austin Schuhf2a50ba2016-12-24 16:16:26 -0800255 ::aos::time::PhasedLoop phased_loop(chrono::milliseconds(5),
256 chrono::milliseconds(4));
Brian Silverman5090c432016-01-02 14:44:26 -0800257
258 ::aos::SetCurrentThreadRealtimePriority(40);
Austin Schuh010eb812014-10-25 18:06:49 -0700259 while (run_) {
Brian Silverman5090c432016-01-02 14:44:26 -0800260 {
261 const int iterations = phased_loop.SleepUntilNext();
262 if (iterations != 1) {
263 LOG(WARNING, "SensorReader skipped %d iterations\n", iterations - 1);
264 }
265 }
Austin Schuh010eb812014-10-25 18:06:49 -0700266 RunIteration();
Austin Schuh010eb812014-10-25 18:06:49 -0700267 }
Brian Silverman335c20e2015-01-26 21:47:58 -0500268
269 wrist_encoder_.Stop();
Austin Schuh010eb812014-10-25 18:06:49 -0700270 }
271
272 void RunIteration() {
Brian Silverman39b339e2016-01-03 13:24:22 -0800273 ::frc971::wpilib::SendRobotState(my_pid_, ds_);
Austin Schuh010eb812014-10-25 18:06:49 -0700274
Austin Schuh35d06612015-02-15 23:35:23 -0800275 {
276 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
277 drivetrain_message->right_encoder =
Austin Schuh2e0d2be2015-02-20 22:12:43 -0800278 -drivetrain_translate(right_encoder_->GetRaw());
Austin Schuh35d06612015-02-15 23:35:23 -0800279 drivetrain_message->left_encoder =
Austin Schuh2e0d2be2015-02-20 22:12:43 -0800280 drivetrain_translate(left_encoder_->GetRaw());
Brian Silverman51091a02015-12-26 15:56:58 -0800281 drivetrain_message->left_speed =
282 drivetrain_velocity_translate(left_encoder_->GetPeriod());
283 drivetrain_message->right_speed =
284 drivetrain_velocity_translate(right_encoder_->GetPeriod());
Austin Schuh35d06612015-02-15 23:35:23 -0800285
286 drivetrain_message.Send();
287 }
Brian Silverman335c20e2015-01-26 21:47:58 -0500288
289 dma_synchronizer_->RunIteration();
290
Philipp Schrader82c65072015-02-16 00:47:09 +0000291 const auto &values = constants::GetValues();
Brian Silverman5d712fc2015-02-15 03:39:31 -0500292
Brian Silverman335c20e2015-01-26 21:47:58 -0500293 {
294 auto fridge_message = fridge_queue.position.MakeMessage();
295 CopyPotAndIndexPosition(arm_left_encoder_, &fridge_message->arm.left,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500296 arm_translate, arm_potentiometer_translate, false,
Austin Schuh6246c542015-02-16 02:59:09 -0800297 values.fridge.left_arm_potentiometer_offset);
Brian Silverman5d712fc2015-02-15 03:39:31 -0500298 CopyPotAndIndexPosition(
299 arm_right_encoder_, &fridge_message->arm.right, arm_translate,
300 arm_potentiometer_translate, true,
Austin Schuh6246c542015-02-16 02:59:09 -0800301 values.fridge.right_arm_potentiometer_offset);
Brian Silverman335c20e2015-01-26 21:47:58 -0500302 CopyPotAndIndexPosition(
303 elevator_left_encoder_, &fridge_message->elevator.left,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500304 elevator_translate, elevator_potentiometer_translate, false,
Austin Schuh6246c542015-02-16 02:59:09 -0800305 values.fridge.left_elevator_potentiometer_offset);
Brian Silverman5d712fc2015-02-15 03:39:31 -0500306 CopyPotAndIndexPosition(
307 elevator_right_encoder_, &fridge_message->elevator.right,
308 elevator_translate, elevator_potentiometer_translate, true,
Austin Schuh6246c542015-02-16 02:59:09 -0800309 values.fridge.right_elevator_potentiometer_offset);
Brian Silverman335c20e2015-01-26 21:47:58 -0500310 fridge_message.Send();
311 }
312
313 {
314 auto claw_message = claw_queue.position.MakeMessage();
315 CopyPotAndIndexPosition(wrist_encoder_, &claw_message->joint,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500316 claw_translate, claw_potentiometer_translate,
317 false, values.claw.potentiometer_offset);
Brian Silverman335c20e2015-01-26 21:47:58 -0500318 claw_message.Send();
319 }
Austin Schuh010eb812014-10-25 18:06:49 -0700320 }
321
322 void Quit() { run_ = false; }
323
324 private:
Brian Silverman699f0cb2015-02-05 19:45:01 -0500325 int32_t my_pid_;
326 DriverStation *ds_;
327
Brian Silverman335c20e2015-01-26 21:47:58 -0500328 void CopyPotAndIndexPosition(
329 const DMAEncoderAndPotentiometer &encoder, PotAndIndexPosition *position,
330 ::std::function<double(int32_t)> encoder_translate,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500331 ::std::function<double(double)> potentiometer_translate, bool reverse,
332 double potentiometer_offset) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500333 const double multiplier = reverse ? -1.0 : 1.0;
334 position->encoder =
335 multiplier * encoder_translate(encoder.polled_encoder_value());
Brian Silverman5d712fc2015-02-15 03:39:31 -0500336 position->pot = multiplier * potentiometer_translate(
337 encoder.polled_potentiometer_voltage()) +
338 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500339 position->latched_encoder =
340 multiplier * encoder_translate(encoder.last_encoder_value());
341 position->latched_pot =
Brian Silverman5d712fc2015-02-15 03:39:31 -0500342 multiplier *
343 potentiometer_translate(encoder.last_potentiometer_voltage()) +
344 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500345 position->index_pulses = encoder.index_posedge_count();
346 }
347
348 void CopyPotAndIndexPosition(
349 const InterruptEncoderAndPotentiometer &encoder,
350 PotAndIndexPosition *position,
351 ::std::function<double(int32_t)> encoder_translate,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500352 ::std::function<double(double)> potentiometer_translate, bool reverse,
353 double potentiometer_offset) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500354 const double multiplier = reverse ? -1.0 : 1.0;
355 position->encoder =
356 multiplier * encoder_translate(encoder.encoder()->GetRaw());
Brian Silverman5d712fc2015-02-15 03:39:31 -0500357 position->pot = multiplier * potentiometer_translate(
358 encoder.potentiometer()->GetVoltage()) +
359 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500360 position->latched_encoder =
361 multiplier * encoder_translate(encoder.last_encoder_value());
362 position->latched_pot =
Brian Silverman5d712fc2015-02-15 03:39:31 -0500363 multiplier *
364 potentiometer_translate(encoder.last_potentiometer_voltage()) +
365 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500366 position->index_pulses = encoder.index_posedge_count();
367 }
368
Brian Silverman335c20e2015-01-26 21:47:58 -0500369 ::std::unique_ptr<DMASynchronizer> dma_synchronizer_;
370
371 DMAEncoderAndPotentiometer arm_left_encoder_, arm_right_encoder_,
372 elevator_left_encoder_, elevator_right_encoder_;
373
Brian Silverman5090c432016-01-02 14:44:26 -0800374 InterruptEncoderAndPotentiometer wrist_encoder_{55};
Brian Silverman335c20e2015-01-26 21:47:58 -0500375
Austin Schuh010eb812014-10-25 18:06:49 -0700376 ::std::unique_ptr<Encoder> left_encoder_;
377 ::std::unique_ptr<Encoder> right_encoder_;
Austin Schuh010eb812014-10-25 18:06:49 -0700378
Brian Silverman1f90d672015-01-26 20:20:45 -0500379 ::std::atomic<bool> run_{true};
Austin Schuh010eb812014-10-25 18:06:49 -0700380 DigitalGlitchFilter filter_;
381};
382
Brian Silvermand8f403a2014-12-13 19:12:04 -0500383class SolenoidWriter {
Austin Schuh010eb812014-10-25 18:06:49 -0700384 public:
Brian Silvermand8f403a2014-12-13 19:12:04 -0500385 SolenoidWriter(const ::std::unique_ptr<BufferedPcm> &pcm)
Daniel Pettiadf38432015-01-26 17:13:35 -0800386 : pcm_(pcm),
Austin Schuh88af0852016-12-04 20:31:32 -0800387 fridge_(".y2015.control_loops.fridge.fridge_queue.output"),
388 claw_(".y2015.control_loops.claw_queue.output") {}
Austin Schuh17a2a492015-02-20 22:12:24 -0800389
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700390 void set_pressure_switch(::std::unique_ptr<DigitalInput> pressure_switch) {
Austin Schuh17a2a492015-02-20 22:12:24 -0800391 pressure_switch_ = ::std::move(pressure_switch);
392 }
393
394 void set_compressor_relay(::std::unique_ptr<Relay> compressor_relay) {
395 compressor_relay_ = ::std::move(compressor_relay);
396 }
Brian Silvermand8f403a2014-12-13 19:12:04 -0500397
Daniel Pettiadf38432015-01-26 17:13:35 -0800398 void set_fridge_grabbers_top_front(::std::unique_ptr<BufferedSolenoid> s) {
399 fridge_grabbers_top_front_ = ::std::move(s);
Austin Schuh010eb812014-10-25 18:06:49 -0700400 }
401
Daniel Pettiadf38432015-01-26 17:13:35 -0800402 void set_fridge_grabbers_top_back(::std::unique_ptr<BufferedSolenoid> s) {
403 fridge_grabbers_top_back_ = ::std::move(s);
404 }
405
406 void set_fridge_grabbers_bottom_front(
407 ::std::unique_ptr<BufferedSolenoid> s) {
408 fridge_grabbers_bottom_front_ = ::std::move(s);
409 }
410
411 void set_fridge_grabbers_bottom_back(
412 ::std::unique_ptr<BufferedSolenoid> s) {
413 fridge_grabbers_bottom_back_ = ::std::move(s);
414 }
415
416 void set_claw_pinchers(::std::unique_ptr<BufferedSolenoid> s) {
417 claw_pinchers_ = ::std::move(s);
Brian Silvermand8f403a2014-12-13 19:12:04 -0500418 }
Austin Schuh010eb812014-10-25 18:06:49 -0700419
Brian Silverman93936f72015-03-19 23:38:30 -0700420 void set_grabber_latch_release(::std::unique_ptr<BufferedSolenoid> s) {
421 grabber_latch_release_ = ::std::move(s);
422 }
423
424 void set_grabber_fold_up(::std::unique_ptr<BufferedSolenoid> s) {
425 grabber_fold_up_ = ::std::move(s);
426 }
427
Brian Silvermand8f403a2014-12-13 19:12:04 -0500428 void operator()() {
429 ::aos::SetCurrentThreadName("Solenoids");
Brian Silverman5090c432016-01-02 14:44:26 -0800430 ::aos::SetCurrentThreadRealtimePriority(27);
431
Austin Schuhf2a50ba2016-12-24 16:16:26 -0800432 ::aos::time::PhasedLoop phased_loop(chrono::milliseconds(20),
433 chrono::milliseconds(1));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500434
435 while (run_) {
Brian Silverman5090c432016-01-02 14:44:26 -0800436 {
437 const int iterations = phased_loop.SleepUntilNext();
438 if (iterations != 1) {
439 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
440 }
441 }
Brian Silvermand8f403a2014-12-13 19:12:04 -0500442
443 {
Daniel Pettiadf38432015-01-26 17:13:35 -0800444 fridge_.FetchLatest();
445 if (fridge_.get()) {
446 LOG_STRUCT(DEBUG, "solenoids", *fridge_);
Austin Schuh8ab58492015-02-22 21:32:29 -0800447 fridge_grabbers_top_front_->Set(!fridge_->grabbers.top_front);
448 fridge_grabbers_top_back_->Set(!fridge_->grabbers.top_back);
449 fridge_grabbers_bottom_front_->Set(!fridge_->grabbers.bottom_front);
450 fridge_grabbers_bottom_back_->Set(!fridge_->grabbers.bottom_back);
Daniel Pettiadf38432015-01-26 17:13:35 -0800451 }
452 }
453
454 {
455 claw_.FetchLatest();
456 if (claw_.get()) {
457 LOG_STRUCT(DEBUG, "solenoids", *claw_);
Austin Schuh8ab58492015-02-22 21:32:29 -0800458 claw_pinchers_->Set(claw_->rollers_closed);
Brian Silvermand8f403a2014-12-13 19:12:04 -0500459 }
460 }
461
Brian Silverman93936f72015-03-19 23:38:30 -0700462 ::aos::joystick_state.FetchLatest();
463 grabber_latch_release_->Set(::aos::joystick_state.get() != nullptr &&
464 ::aos::joystick_state->autonomous);
465 grabber_fold_up_->Set(::aos::joystick_state.get() != nullptr &&
466 ::aos::joystick_state->joysticks[1].buttons & 1);
467
Brian Silverman87541532015-03-19 23:35:12 -0700468 {
469 PneumaticsToLog to_log;
470 {
471 const bool compressor_on = !pressure_switch_->Get();
472 to_log.compressor_on = compressor_on;
473 if (compressor_on) {
474 compressor_relay_->Set(Relay::kForward);
475 } else {
476 compressor_relay_->Set(Relay::kOff);
477 }
478 }
479
480 pcm_->Flush();
481 to_log.read_solenoids = pcm_->GetAll();
482 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
483 }
Austin Schuh010eb812014-10-25 18:06:49 -0700484 }
485 }
486
Brian Silvermand8f403a2014-12-13 19:12:04 -0500487 void Quit() { run_ = false; }
Austin Schuh010eb812014-10-25 18:06:49 -0700488
Brian Silvermand8f403a2014-12-13 19:12:04 -0500489 private:
490 const ::std::unique_ptr<BufferedPcm> &pcm_;
Daniel Pettiadf38432015-01-26 17:13:35 -0800491 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_top_front_;
492 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_top_back_;
493 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_bottom_front_;
494 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_bottom_back_;
495 ::std::unique_ptr<BufferedSolenoid> claw_pinchers_;
Brian Silverman93936f72015-03-19 23:38:30 -0700496 ::std::unique_ptr<BufferedSolenoid> grabber_latch_release_;
497 ::std::unique_ptr<BufferedSolenoid> grabber_fold_up_;
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700498 ::std::unique_ptr<DigitalInput> pressure_switch_;
Austin Schuh17a2a492015-02-20 22:12:24 -0800499 ::std::unique_ptr<Relay> compressor_relay_;
Austin Schuh010eb812014-10-25 18:06:49 -0700500
Austin Schuh88af0852016-12-04 20:31:32 -0800501 ::aos::Queue<::y2015::control_loops::fridge::FridgeQueue::Output> fridge_;
502 ::aos::Queue<::y2015::control_loops::ClawQueue::Output> claw_;
Austin Schuh010eb812014-10-25 18:06:49 -0700503
Brian Silvermand8f403a2014-12-13 19:12:04 -0500504 ::std::atomic<bool> run_{true};
505};
506
Austin Schuhbb227f82015-09-06 15:27:52 -0700507class CanWriter : public LoopOutputHandler {
508 public:
Austin Schuhf2a50ba2016-12-24 16:16:26 -0800509 CanWriter() : LoopOutputHandler(chrono::milliseconds(100)) {}
Austin Schuhbb227f82015-09-06 15:27:52 -0700510
511 void set_can_talon(::std::unique_ptr<Talon> t) {
512 can_talon_ = ::std::move(t);
513 }
514
515 private:
516 virtual void Read() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800517 ::y2015::autonomous::can_control.FetchAnother();
Austin Schuhbb227f82015-09-06 15:27:52 -0700518 }
519
520 virtual void Write() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800521 auto &queue = ::y2015::autonomous::can_control;
Austin Schuhbb227f82015-09-06 15:27:52 -0700522 LOG_STRUCT(DEBUG, "will output", *queue);
523 can_talon_->Set(queue->can_voltage / 12.0);
524 }
525
526 virtual void Stop() override {
527 LOG(WARNING, "Can output too old\n");
528 can_talon_->Disable();
529 }
530
531 ::std::unique_ptr<Talon> can_talon_;
532};
533
Brian Silvermand8f403a2014-12-13 19:12:04 -0500534class DrivetrainWriter : public LoopOutputHandler {
535 public:
536 void set_left_drivetrain_talon(::std::unique_ptr<Talon> t) {
537 left_drivetrain_talon_ = ::std::move(t);
Austin Schuh010eb812014-10-25 18:06:49 -0700538 }
539
Brian Silvermand8f403a2014-12-13 19:12:04 -0500540 void set_right_drivetrain_talon(::std::unique_ptr<Talon> t) {
541 right_drivetrain_talon_ = ::std::move(t);
542 }
Austin Schuh010eb812014-10-25 18:06:49 -0700543
Brian Silvermand8f403a2014-12-13 19:12:04 -0500544 private:
545 virtual void Read() override {
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500546 ::frc971::control_loops::drivetrain_queue.output.FetchAnother();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500547 }
548
549 virtual void Write() override {
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500550 auto &queue = ::frc971::control_loops::drivetrain_queue.output;
Brian Silvermand8f403a2014-12-13 19:12:04 -0500551 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuha004b0c2015-02-16 17:06:30 -0800552 left_drivetrain_talon_->Set(queue->left_voltage / 12.0);
553 right_drivetrain_talon_->Set(-queue->right_voltage / 12.0);
Brian Silvermand8f403a2014-12-13 19:12:04 -0500554 }
555
556 virtual void Stop() override {
557 LOG(WARNING, "drivetrain output too old\n");
558 left_drivetrain_talon_->Disable();
559 right_drivetrain_talon_->Disable();
560 }
561
Austin Schuh010eb812014-10-25 18:06:49 -0700562 ::std::unique_ptr<Talon> left_drivetrain_talon_;
Brian Silvermand8f403a2014-12-13 19:12:04 -0500563 ::std::unique_ptr<Talon> right_drivetrain_talon_;
564};
565
Daniel Pettiadf38432015-01-26 17:13:35 -0800566class FridgeWriter : public LoopOutputHandler {
567 public:
568 void set_left_arm_talon(::std::unique_ptr<Talon> t) {
569 left_arm_talon_ = ::std::move(t);
570 }
571
572 void set_right_arm_talon(::std::unique_ptr<Talon> t) {
573 right_arm_talon_ = ::std::move(t);
574 }
575
576 void set_left_elevator_talon(::std::unique_ptr<Talon> t) {
577 left_elevator_talon_ = ::std::move(t);
578 }
579
580 void set_right_elevator_talon(::std::unique_ptr<Talon> t) {
581 right_elevator_talon_ = ::std::move(t);
582 }
583
584 private:
585 virtual void Read() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800586 ::y2015::control_loops::fridge::fridge_queue.output.FetchAnother();
Daniel Pettiadf38432015-01-26 17:13:35 -0800587 }
588
589 virtual void Write() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800590 auto &queue = ::y2015::control_loops::fridge::fridge_queue.output;
Daniel Pettiadf38432015-01-26 17:13:35 -0800591 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuh859a9302015-02-16 15:45:45 -0800592 left_arm_talon_->Set(queue->left_arm / 12.0);
593 right_arm_talon_->Set(-queue->right_arm / 12.0);
594 left_elevator_talon_->Set(queue->left_elevator / 12.0);
595 right_elevator_talon_->Set(-queue->right_elevator / 12.0);
Daniel Pettiadf38432015-01-26 17:13:35 -0800596 }
597
598 virtual void Stop() override {
599 LOG(WARNING, "Fridge output too old.\n");
600 left_arm_talon_->Disable();
601 right_arm_talon_->Disable();
602 left_elevator_talon_->Disable();
603 right_elevator_talon_->Disable();
604 }
605
606 ::std::unique_ptr<Talon> left_arm_talon_;
607 ::std::unique_ptr<Talon> right_arm_talon_;
608 ::std::unique_ptr<Talon> left_elevator_talon_;
609 ::std::unique_ptr<Talon> right_elevator_talon_;
610};
611
612class ClawWriter : public LoopOutputHandler {
613 public:
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800614 void set_left_intake_talon(::std::unique_ptr<Talon> t) {
615 left_intake_talon_ = ::std::move(t);
616 }
617
618 void set_right_intake_talon(::std::unique_ptr<Talon> t) {
619 right_intake_talon_ = ::std::move(t);
Daniel Pettiadf38432015-01-26 17:13:35 -0800620 }
621
622 void set_wrist_talon(::std::unique_ptr<Talon> t) {
623 wrist_talon_ = ::std::move(t);
624 }
625
626 private:
627 virtual void Read() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800628 ::y2015::control_loops::claw_queue.output.FetchAnother();
Daniel Pettiadf38432015-01-26 17:13:35 -0800629 }
630
631 virtual void Write() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800632 auto &queue = ::y2015::control_loops::claw_queue.output;
Daniel Pettiadf38432015-01-26 17:13:35 -0800633 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800634 left_intake_talon_->Set(queue->intake_voltage / 12.0);
Austin Schuh8a436e82015-02-16 23:31:28 -0800635 right_intake_talon_->Set(-queue->intake_voltage / 12.0);
636 wrist_talon_->Set(-queue->voltage / 12.0);
Daniel Pettiadf38432015-01-26 17:13:35 -0800637 }
638
639 virtual void Stop() override {
640 LOG(WARNING, "Claw output too old.\n");
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800641 left_intake_talon_->Disable();
642 right_intake_talon_->Disable();
Daniel Pettiadf38432015-01-26 17:13:35 -0800643 wrist_talon_->Disable();
644 }
645
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800646 ::std::unique_ptr<Talon> left_intake_talon_;
647 ::std::unique_ptr<Talon> right_intake_talon_;
Daniel Pettiadf38432015-01-26 17:13:35 -0800648 ::std::unique_ptr<Talon> wrist_talon_;
649};
650
Brian Silverman1f90d672015-01-26 20:20:45 -0500651// TODO(brian): Replace this with ::std::make_unique once all our toolchains
652// have support.
653template <class T, class... U>
654std::unique_ptr<T> make_unique(U &&... u) {
655 return std::unique_ptr<T>(new T(std::forward<U>(u)...));
656}
657
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800658class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
Austin Schuh010eb812014-10-25 18:06:49 -0700659 public:
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800660 ::std::unique_ptr<Encoder> encoder(int index) {
661 return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false,
662 Encoder::k4X);
663 }
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800664 virtual void Run() {
Brian Silvermand8f403a2014-12-13 19:12:04 -0500665 ::aos::InitNRT();
Brian Silverman2fe007c2014-12-28 12:20:01 -0800666 ::aos::SetCurrentThreadName("StartCompetition");
Brian Silvermand8f403a2014-12-13 19:12:04 -0500667
Brian Silverman98f6ee22015-01-26 17:50:12 -0500668 JoystickSender joystick_sender;
Austin Schuh010eb812014-10-25 18:06:49 -0700669 ::std::thread joystick_thread(::std::ref(joystick_sender));
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800670 // TODO(austin): Compressor needs to use a spike.
Brian Silvermand8f403a2014-12-13 19:12:04 -0500671
Brian Silverman425492b2015-12-30 15:23:55 -0800672 ::frc971::wpilib::PDPFetcher pdp_fetcher;
673 ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
674
Brian Silverman39b339e2016-01-03 13:24:22 -0800675 SensorReader reader;
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800676 reader.set_arm_left_encoder(encoder(1));
677 reader.set_arm_left_index(make_unique<DigitalInput>(1));
678 reader.set_arm_left_potentiometer(make_unique<AnalogInput>(1));
679
680 reader.set_arm_right_encoder(encoder(5));
681 reader.set_arm_right_index(make_unique<DigitalInput>(5));
682 reader.set_arm_right_potentiometer(make_unique<AnalogInput>(5));
683
684 reader.set_elevator_left_encoder(encoder(0));
685 reader.set_elevator_left_index(make_unique<DigitalInput>(0));
686 reader.set_elevator_left_potentiometer(make_unique<AnalogInput>(0));
687
688 reader.set_elevator_right_encoder(encoder(4));
689 reader.set_elevator_right_index(make_unique<DigitalInput>(4));
690 reader.set_elevator_right_potentiometer(make_unique<AnalogInput>(4));
691
692 reader.set_wrist_encoder(encoder(6));
693 reader.set_wrist_index(make_unique<DigitalInput>(6));
694 reader.set_wrist_potentiometer(make_unique<AnalogInput>(6));
695
696 reader.set_left_encoder(encoder(2));
697 reader.set_right_encoder(encoder(3));
Brian Silverman335c20e2015-01-26 21:47:58 -0500698 reader.set_dma(make_unique<DMA>());
Brian Silverman98f6ee22015-01-26 17:50:12 -0500699 ::std::thread reader_thread(::std::ref(reader));
700 GyroSender gyro_sender;
701 ::std::thread gyro_thread(::std::ref(gyro_sender));
702
703 DrivetrainWriter drivetrain_writer;
Brian Silvermand8f403a2014-12-13 19:12:04 -0500704 drivetrain_writer.set_left_drivetrain_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800705 ::std::unique_ptr<Talon>(new Talon(8)));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500706 drivetrain_writer.set_right_drivetrain_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800707 ::std::unique_ptr<Talon>(new Talon(0)));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500708 ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
709
Austin Schuhbb227f82015-09-06 15:27:52 -0700710 CanWriter can_writer;
711 can_writer.set_can_talon(::std::unique_ptr<Talon>(new Talon(9)));
712 ::std::thread can_writer_thread(::std::ref(can_writer));
713
Daniel Pettiadf38432015-01-26 17:13:35 -0800714 // TODO(sensors): Get real PWM output and relay numbers for the fridge and
715 // claw.
716 FridgeWriter fridge_writer;
717 fridge_writer.set_left_arm_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800718 ::std::unique_ptr<Talon>(new Talon(6)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800719 fridge_writer.set_right_arm_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800720 ::std::unique_ptr<Talon>(new Talon(2)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800721 fridge_writer.set_left_elevator_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800722 ::std::unique_ptr<Talon>(new Talon(7)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800723 fridge_writer.set_right_elevator_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800724 ::std::unique_ptr<Talon>(new Talon(1)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800725 ::std::thread fridge_writer_thread(::std::ref(fridge_writer));
726
727 ClawWriter claw_writer;
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800728 claw_writer.set_left_intake_talon(
729 ::std::unique_ptr<Talon>(new Talon(5)));
730 claw_writer.set_right_intake_talon(
731 ::std::unique_ptr<Talon>(new Talon(3)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800732 claw_writer.set_wrist_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800733 ::std::unique_ptr<Talon>(new Talon(4)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800734 ::std::thread claw_writer_thread(::std::ref(claw_writer));
735
736 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
737 new ::frc971::wpilib::BufferedPcm());
Brian Silverman98f6ee22015-01-26 17:50:12 -0500738 SolenoidWriter solenoid_writer(pcm);
Austin Schuh17a2a492015-02-20 22:12:24 -0800739 solenoid_writer.set_fridge_grabbers_top_front(pcm->MakeSolenoid(0));
740 solenoid_writer.set_fridge_grabbers_top_back(pcm->MakeSolenoid(0));
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800741 solenoid_writer.set_fridge_grabbers_bottom_front(pcm->MakeSolenoid(2));
Austin Schuh17a2a492015-02-20 22:12:24 -0800742 solenoid_writer.set_fridge_grabbers_bottom_back(pcm->MakeSolenoid(1));
743 solenoid_writer.set_claw_pinchers(pcm->MakeSolenoid(4));
Brian Silverman93936f72015-03-19 23:38:30 -0700744 solenoid_writer.set_grabber_latch_release(pcm->MakeSolenoid(7));
745 solenoid_writer.set_grabber_fold_up(pcm->MakeSolenoid(5));
Austin Schuh17a2a492015-02-20 22:12:24 -0800746
747 solenoid_writer.set_pressure_switch(make_unique<DigitalInput>(9));
748 solenoid_writer.set_compressor_relay(make_unique<Relay>(0));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500749 ::std::thread solenoid_thread(::std::ref(solenoid_writer));
750
751 // Wait forever. Not much else to do...
Brian Silverman5090c432016-01-02 14:44:26 -0800752 while (true) {
753 const int r = select(0, nullptr, nullptr, nullptr, nullptr);
754 if (r != 0) {
755 PLOG(WARNING, "infinite select failed");
756 } else {
757 PLOG(WARNING, "infinite select succeeded??\n");
758 }
759 }
Brian Silvermand8f403a2014-12-13 19:12:04 -0500760
Austin Schuh010eb812014-10-25 18:06:49 -0700761 LOG(ERROR, "Exiting WPILibRobot\n");
Brian Silverman07ec88e2014-12-28 00:13:08 -0800762
Austin Schuh010eb812014-10-25 18:06:49 -0700763 joystick_sender.Quit();
764 joystick_thread.join();
Brian Silverman425492b2015-12-30 15:23:55 -0800765 pdp_fetcher.Quit();
766 pdp_fetcher_thread.join();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500767 reader.Quit();
768 reader_thread.join();
Brian Silverman07ec88e2014-12-28 00:13:08 -0800769 gyro_sender.Quit();
770 gyro_thread.join();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500771
772 drivetrain_writer.Quit();
773 drivetrain_writer_thread.join();
Austin Schuhbb227f82015-09-06 15:27:52 -0700774 can_writer.Quit();
775 can_writer_thread.join();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500776 solenoid_writer.Quit();
777 solenoid_thread.join();
778
Austin Schuh010eb812014-10-25 18:06:49 -0700779 ::aos::Cleanup();
780 }
781};
782
Brian Silverman98f6ee22015-01-26 17:50:12 -0500783} // namespace wpilib
Austin Schuh88af0852016-12-04 20:31:32 -0800784} // namespace y2015
Austin Schuhdb516032014-12-28 00:12:38 -0800785
Brian Silverman98f6ee22015-01-26 17:50:12 -0500786
Austin Schuh88af0852016-12-04 20:31:32 -0800787AOS_ROBOT_CLASS(::y2015::wpilib::WPILibRobot);