blob: a6dab4d999c3f2de80ddb76908f71db77d8502ee [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 Schuh010eb812014-10-25 18:06:49 -070071
Austin Schuh88af0852016-12-04 20:31:32 -080072namespace y2015 {
Brian Silvermanda45b6c2014-12-28 11:36:50 -080073namespace wpilib {
Austin Schuh010eb812014-10-25 18:06:49 -070074
Austin Schuh010eb812014-10-25 18:06:49 -070075double drivetrain_translate(int32_t in) {
Austin Schuhdb516032014-12-28 00:12:38 -080076 return static_cast<double>(in) /
Daniel Pettiadf38432015-01-26 17:13:35 -080077 (256.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -080078 constants::GetValues().drivetrain_encoder_ratio *
Daniel Pettiadf38432015-01-26 17:13:35 -080079 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
80}
81
Brian Silverman51091a02015-12-26 15:56:58 -080082double drivetrain_velocity_translate(double in) {
83 return (1.0 / in) / 256.0 /*cpr*/ *
84 constants::GetValues().drivetrain_encoder_ratio *
85 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
86}
87
Daniel Pettiadf38432015-01-26 17:13:35 -080088double arm_translate(int32_t in) {
Austin Schuh6246c542015-02-16 02:59:09 -080089 return -static_cast<double>(in) /
Daniel Pettiadf38432015-01-26 17:13:35 -080090 (512.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -080091 constants::GetValues().arm_encoder_ratio *
Daniel Pettiadf38432015-01-26 17:13:35 -080092 (2 * M_PI /*radians*/);
93}
94
Brian Silverman5d712fc2015-02-15 03:39:31 -050095double arm_potentiometer_translate(double voltage) {
Austin Schuh35d06612015-02-15 23:35:23 -080096 return voltage *
Daniel Pettia7827412015-02-13 20:55:57 -080097 constants::GetValues().arm_pot_ratio *
Austin Schuh35d06612015-02-15 23:35:23 -080098 (5.0 /*turns*/ / 5.0 /*volts*/) *
Daniel Pettiadf38432015-01-26 17:13:35 -080099 (2 * M_PI /*radians*/);
100}
101
102double elevator_translate(int32_t in) {
103 return static_cast<double>(in) /
104 (512.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -0800105 constants::GetValues().elev_encoder_ratio *
106 (2 * M_PI /*radians*/) *
107 constants::GetValues().elev_distance_per_radian;
Daniel Pettiadf38432015-01-26 17:13:35 -0800108}
109
Brian Silverman5d712fc2015-02-15 03:39:31 -0500110double elevator_potentiometer_translate(double voltage) {
Austin Schuh6246c542015-02-16 02:59:09 -0800111 return -voltage *
Daniel Pettia7827412015-02-13 20:55:57 -0800112 constants::GetValues().elev_pot_ratio *
113 (2 * M_PI /*radians*/) *
114 constants::GetValues().elev_distance_per_radian *
Austin Schuh35d06612015-02-15 23:35:23 -0800115 (5.0 /*turns*/ / 5.0 /*volts*/);
Daniel Pettiadf38432015-01-26 17:13:35 -0800116}
117
118double claw_translate(int32_t in) {
119 return static_cast<double>(in) /
120 (512.0 /*cpr*/ * 4.0 /*4x*/) *
Daniel Pettia7827412015-02-13 20:55:57 -0800121 constants::GetValues().claw_encoder_ratio *
Daniel Pettiadf38432015-01-26 17:13:35 -0800122 (2 * M_PI /*radians*/);
123}
124
Brian Silverman5d712fc2015-02-15 03:39:31 -0500125double claw_potentiometer_translate(double voltage) {
Austin Schuh6246c542015-02-16 02:59:09 -0800126 return -voltage *
Daniel Pettia7827412015-02-13 20:55:57 -0800127 constants::GetValues().claw_pot_ratio *
Austin Schuh35d06612015-02-15 23:35:23 -0800128 (5.0 /*turns*/ / 5.0 /*volts*/) *
Daniel Pettiadf38432015-01-26 17:13:35 -0800129 (2 * M_PI /*radians*/);
Austin Schuh010eb812014-10-25 18:06:49 -0700130}
131
Brian Silverman335c20e2015-01-26 21:47:58 -0500132static const double kMaximumEncoderPulsesPerSecond =
133 19500.0 /* free speed RPM */ * 12.0 / 56.0 /* belt reduction */ /
134 60.0 /* seconds / minute */ * 256.0 /* CPR */ *
135 4.0 /* index pulse = 1/4 cycle */;
136
Austin Schuh010eb812014-10-25 18:06:49 -0700137class SensorReader {
138 public:
Brian Silverman39b339e2016-01-03 13:24:22 -0800139 SensorReader() {
Brian Silverman335c20e2015-01-26 21:47:58 -0500140 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
141 // we should ever see.
142 filter_.SetPeriodNanoSeconds(
143 static_cast<int>(1 / 4.0 / kMaximumEncoderPulsesPerSecond * 1e9 + 0.5));
144 }
145
146 void set_arm_left_encoder(::std::unique_ptr<Encoder> encoder) {
147 filter_.Add(encoder.get());
148 arm_left_encoder_.set_encoder(::std::move(encoder));
149 }
150
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700151 void set_arm_left_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500152 filter_.Add(index.get());
153 arm_left_encoder_.set_index(::std::move(index));
154 }
155
156 void set_arm_left_potentiometer(
157 ::std::unique_ptr<AnalogInput> potentiometer) {
158 arm_left_encoder_.set_potentiometer(::std::move(potentiometer));
159 }
160
161 void set_arm_right_encoder(::std::unique_ptr<Encoder> encoder) {
162 filter_.Add(encoder.get());
163 arm_right_encoder_.set_encoder(::std::move(encoder));
164 }
165
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700166 void set_arm_right_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500167 filter_.Add(index.get());
168 arm_right_encoder_.set_index(::std::move(index));
169 }
170
171 void set_arm_right_potentiometer(
172 ::std::unique_ptr<AnalogInput> potentiometer) {
173 arm_right_encoder_.set_potentiometer(::std::move(potentiometer));
174 }
175
176 void set_elevator_left_encoder(::std::unique_ptr<Encoder> encoder) {
177 filter_.Add(encoder.get());
178 elevator_left_encoder_.set_encoder(::std::move(encoder));
179 }
180
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700181 void set_elevator_left_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500182 filter_.Add(index.get());
183 elevator_left_encoder_.set_index(::std::move(index));
184 }
185
186 void set_elevator_left_potentiometer(
187 ::std::unique_ptr<AnalogInput> potentiometer) {
188 elevator_left_encoder_.set_potentiometer(::std::move(potentiometer));
189 }
190
191 void set_elevator_right_encoder(::std::unique_ptr<Encoder> encoder) {
192 filter_.Add(encoder.get());
193 elevator_right_encoder_.set_encoder(::std::move(encoder));
194 }
195
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700196 void set_elevator_right_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500197 filter_.Add(index.get());
198 elevator_right_encoder_.set_index(::std::move(index));
199 }
200
201 void set_elevator_right_potentiometer(
202 ::std::unique_ptr<AnalogInput> potentiometer) {
203 elevator_right_encoder_.set_potentiometer(::std::move(potentiometer));
204 }
205
206 void set_wrist_encoder(::std::unique_ptr<Encoder> encoder) {
207 filter_.Add(encoder.get());
208 wrist_encoder_.set_encoder(::std::move(encoder));
209 }
210
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700211 void set_wrist_index(::std::unique_ptr<DigitalInput> index) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500212 filter_.Add(index.get());
213 wrist_encoder_.set_index(::std::move(index));
214 }
215
216 void set_wrist_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) {
217 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
Austin Schuh010eb812014-10-25 18:06:49 -0700218 }
219
Brian Silverman1f90d672015-01-26 20:20:45 -0500220 void set_left_encoder(::std::unique_ptr<Encoder> left_encoder) {
221 left_encoder_ = ::std::move(left_encoder);
Brian Silverman51091a02015-12-26 15:56:58 -0800222 left_encoder_->SetMaxPeriod(0.005);
Brian Silverman1f90d672015-01-26 20:20:45 -0500223 }
224
225 void set_right_encoder(::std::unique_ptr<Encoder> right_encoder) {
226 right_encoder_ = ::std::move(right_encoder);
Brian Silverman51091a02015-12-26 15:56:58 -0800227 right_encoder_->SetMaxPeriod(0.005);
Brian Silverman1f90d672015-01-26 20:20:45 -0500228 }
229
Brian Silverman335c20e2015-01-26 21:47:58 -0500230 // All of the DMA-related set_* calls must be made before this, and it doesn't
231 // hurt to do all of them.
232 void set_dma(::std::unique_ptr<DMA> dma) {
233 dma_synchronizer_.reset(new DMASynchronizer(::std::move(dma)));
234 dma_synchronizer_->Add(&arm_left_encoder_);
Brian Silverman335c20e2015-01-26 21:47:58 -0500235 dma_synchronizer_->Add(&elevator_left_encoder_);
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800236 dma_synchronizer_->Add(&arm_right_encoder_);
Brian Silverman335c20e2015-01-26 21:47:58 -0500237 dma_synchronizer_->Add(&elevator_right_encoder_);
238 }
239
Austin Schuh010eb812014-10-25 18:06:49 -0700240 void operator()() {
Brian Silverman2fe007c2014-12-28 12:20:01 -0800241 ::aos::SetCurrentThreadName("SensorReader");
242
Brian Silverman699f0cb2015-02-05 19:45:01 -0500243 my_pid_ = getpid();
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700244 ds_ =
245#ifdef WPILIB2015
246 DriverStation::GetInstance();
247#else
248 &DriverStation::GetInstance();
249#endif
Brian Silverman699f0cb2015-02-05 19:45:01 -0500250
Brian Silverman335c20e2015-01-26 21:47:58 -0500251 wrist_encoder_.Start();
252 dma_synchronizer_->Start();
Austin Schuh010eb812014-10-25 18:06:49 -0700253
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700254 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
255 ::std::chrono::milliseconds(4));
Brian Silverman5090c432016-01-02 14:44:26 -0800256
257 ::aos::SetCurrentThreadRealtimePriority(40);
Austin Schuh010eb812014-10-25 18:06:49 -0700258 while (run_) {
Brian Silverman5090c432016-01-02 14:44:26 -0800259 {
260 const int iterations = phased_loop.SleepUntilNext();
261 if (iterations != 1) {
262 LOG(WARNING, "SensorReader skipped %d iterations\n", iterations - 1);
263 }
264 }
Austin Schuh010eb812014-10-25 18:06:49 -0700265 RunIteration();
Austin Schuh010eb812014-10-25 18:06:49 -0700266 }
Brian Silverman335c20e2015-01-26 21:47:58 -0500267
268 wrist_encoder_.Stop();
Austin Schuh010eb812014-10-25 18:06:49 -0700269 }
270
271 void RunIteration() {
Brian Silverman39b339e2016-01-03 13:24:22 -0800272 ::frc971::wpilib::SendRobotState(my_pid_, ds_);
Austin Schuh010eb812014-10-25 18:06:49 -0700273
Austin Schuh35d06612015-02-15 23:35:23 -0800274 {
275 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
276 drivetrain_message->right_encoder =
Austin Schuh2e0d2be2015-02-20 22:12:43 -0800277 -drivetrain_translate(right_encoder_->GetRaw());
Austin Schuh35d06612015-02-15 23:35:23 -0800278 drivetrain_message->left_encoder =
Austin Schuh2e0d2be2015-02-20 22:12:43 -0800279 drivetrain_translate(left_encoder_->GetRaw());
Brian Silverman51091a02015-12-26 15:56:58 -0800280 drivetrain_message->left_speed =
281 drivetrain_velocity_translate(left_encoder_->GetPeriod());
282 drivetrain_message->right_speed =
283 drivetrain_velocity_translate(right_encoder_->GetPeriod());
Austin Schuh35d06612015-02-15 23:35:23 -0800284
285 drivetrain_message.Send();
286 }
Brian Silverman335c20e2015-01-26 21:47:58 -0500287
288 dma_synchronizer_->RunIteration();
289
Philipp Schrader82c65072015-02-16 00:47:09 +0000290 const auto &values = constants::GetValues();
Brian Silverman5d712fc2015-02-15 03:39:31 -0500291
Brian Silverman335c20e2015-01-26 21:47:58 -0500292 {
293 auto fridge_message = fridge_queue.position.MakeMessage();
294 CopyPotAndIndexPosition(arm_left_encoder_, &fridge_message->arm.left,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500295 arm_translate, arm_potentiometer_translate, false,
Austin Schuh6246c542015-02-16 02:59:09 -0800296 values.fridge.left_arm_potentiometer_offset);
Brian Silverman5d712fc2015-02-15 03:39:31 -0500297 CopyPotAndIndexPosition(
298 arm_right_encoder_, &fridge_message->arm.right, arm_translate,
299 arm_potentiometer_translate, true,
Austin Schuh6246c542015-02-16 02:59:09 -0800300 values.fridge.right_arm_potentiometer_offset);
Brian Silverman335c20e2015-01-26 21:47:58 -0500301 CopyPotAndIndexPosition(
302 elevator_left_encoder_, &fridge_message->elevator.left,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500303 elevator_translate, elevator_potentiometer_translate, false,
Austin Schuh6246c542015-02-16 02:59:09 -0800304 values.fridge.left_elevator_potentiometer_offset);
Brian Silverman5d712fc2015-02-15 03:39:31 -0500305 CopyPotAndIndexPosition(
306 elevator_right_encoder_, &fridge_message->elevator.right,
307 elevator_translate, elevator_potentiometer_translate, true,
Austin Schuh6246c542015-02-16 02:59:09 -0800308 values.fridge.right_elevator_potentiometer_offset);
Brian Silverman335c20e2015-01-26 21:47:58 -0500309 fridge_message.Send();
310 }
311
312 {
313 auto claw_message = claw_queue.position.MakeMessage();
314 CopyPotAndIndexPosition(wrist_encoder_, &claw_message->joint,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500315 claw_translate, claw_potentiometer_translate,
316 false, values.claw.potentiometer_offset);
Brian Silverman335c20e2015-01-26 21:47:58 -0500317 claw_message.Send();
318 }
Austin Schuh010eb812014-10-25 18:06:49 -0700319 }
320
321 void Quit() { run_ = false; }
322
323 private:
Brian Silverman699f0cb2015-02-05 19:45:01 -0500324 int32_t my_pid_;
325 DriverStation *ds_;
326
Brian Silverman335c20e2015-01-26 21:47:58 -0500327 void CopyPotAndIndexPosition(
328 const DMAEncoderAndPotentiometer &encoder, PotAndIndexPosition *position,
329 ::std::function<double(int32_t)> encoder_translate,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500330 ::std::function<double(double)> potentiometer_translate, bool reverse,
331 double potentiometer_offset) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500332 const double multiplier = reverse ? -1.0 : 1.0;
333 position->encoder =
334 multiplier * encoder_translate(encoder.polled_encoder_value());
Brian Silverman5d712fc2015-02-15 03:39:31 -0500335 position->pot = multiplier * potentiometer_translate(
336 encoder.polled_potentiometer_voltage()) +
337 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500338 position->latched_encoder =
339 multiplier * encoder_translate(encoder.last_encoder_value());
340 position->latched_pot =
Brian Silverman5d712fc2015-02-15 03:39:31 -0500341 multiplier *
342 potentiometer_translate(encoder.last_potentiometer_voltage()) +
343 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500344 position->index_pulses = encoder.index_posedge_count();
345 }
346
347 void CopyPotAndIndexPosition(
348 const InterruptEncoderAndPotentiometer &encoder,
349 PotAndIndexPosition *position,
350 ::std::function<double(int32_t)> encoder_translate,
Brian Silverman5d712fc2015-02-15 03:39:31 -0500351 ::std::function<double(double)> potentiometer_translate, bool reverse,
352 double potentiometer_offset) {
Brian Silverman335c20e2015-01-26 21:47:58 -0500353 const double multiplier = reverse ? -1.0 : 1.0;
354 position->encoder =
355 multiplier * encoder_translate(encoder.encoder()->GetRaw());
Brian Silverman5d712fc2015-02-15 03:39:31 -0500356 position->pot = multiplier * potentiometer_translate(
357 encoder.potentiometer()->GetVoltage()) +
358 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500359 position->latched_encoder =
360 multiplier * encoder_translate(encoder.last_encoder_value());
361 position->latched_pot =
Brian Silverman5d712fc2015-02-15 03:39:31 -0500362 multiplier *
363 potentiometer_translate(encoder.last_potentiometer_voltage()) +
364 potentiometer_offset;
Brian Silverman335c20e2015-01-26 21:47:58 -0500365 position->index_pulses = encoder.index_posedge_count();
366 }
367
Brian Silverman335c20e2015-01-26 21:47:58 -0500368 ::std::unique_ptr<DMASynchronizer> dma_synchronizer_;
369
370 DMAEncoderAndPotentiometer arm_left_encoder_, arm_right_encoder_,
371 elevator_left_encoder_, elevator_right_encoder_;
372
Brian Silverman5090c432016-01-02 14:44:26 -0800373 InterruptEncoderAndPotentiometer wrist_encoder_{55};
Brian Silverman335c20e2015-01-26 21:47:58 -0500374
Austin Schuh010eb812014-10-25 18:06:49 -0700375 ::std::unique_ptr<Encoder> left_encoder_;
376 ::std::unique_ptr<Encoder> right_encoder_;
Austin Schuh010eb812014-10-25 18:06:49 -0700377
Brian Silverman1f90d672015-01-26 20:20:45 -0500378 ::std::atomic<bool> run_{true};
Austin Schuh010eb812014-10-25 18:06:49 -0700379 DigitalGlitchFilter filter_;
380};
381
Brian Silvermand8f403a2014-12-13 19:12:04 -0500382class SolenoidWriter {
Austin Schuh010eb812014-10-25 18:06:49 -0700383 public:
Brian Silvermand8f403a2014-12-13 19:12:04 -0500384 SolenoidWriter(const ::std::unique_ptr<BufferedPcm> &pcm)
Daniel Pettiadf38432015-01-26 17:13:35 -0800385 : pcm_(pcm),
Austin Schuh88af0852016-12-04 20:31:32 -0800386 fridge_(".y2015.control_loops.fridge.fridge_queue.output"),
387 claw_(".y2015.control_loops.claw_queue.output") {}
Austin Schuh17a2a492015-02-20 22:12:24 -0800388
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700389 void set_pressure_switch(::std::unique_ptr<DigitalInput> pressure_switch) {
Austin Schuh17a2a492015-02-20 22:12:24 -0800390 pressure_switch_ = ::std::move(pressure_switch);
391 }
392
393 void set_compressor_relay(::std::unique_ptr<Relay> compressor_relay) {
394 compressor_relay_ = ::std::move(compressor_relay);
395 }
Brian Silvermand8f403a2014-12-13 19:12:04 -0500396
Daniel Pettiadf38432015-01-26 17:13:35 -0800397 void set_fridge_grabbers_top_front(::std::unique_ptr<BufferedSolenoid> s) {
398 fridge_grabbers_top_front_ = ::std::move(s);
Austin Schuh010eb812014-10-25 18:06:49 -0700399 }
400
Daniel Pettiadf38432015-01-26 17:13:35 -0800401 void set_fridge_grabbers_top_back(::std::unique_ptr<BufferedSolenoid> s) {
402 fridge_grabbers_top_back_ = ::std::move(s);
403 }
404
405 void set_fridge_grabbers_bottom_front(
406 ::std::unique_ptr<BufferedSolenoid> s) {
407 fridge_grabbers_bottom_front_ = ::std::move(s);
408 }
409
410 void set_fridge_grabbers_bottom_back(
411 ::std::unique_ptr<BufferedSolenoid> s) {
412 fridge_grabbers_bottom_back_ = ::std::move(s);
413 }
414
415 void set_claw_pinchers(::std::unique_ptr<BufferedSolenoid> s) {
416 claw_pinchers_ = ::std::move(s);
Brian Silvermand8f403a2014-12-13 19:12:04 -0500417 }
Austin Schuh010eb812014-10-25 18:06:49 -0700418
Brian Silverman93936f72015-03-19 23:38:30 -0700419 void set_grabber_latch_release(::std::unique_ptr<BufferedSolenoid> s) {
420 grabber_latch_release_ = ::std::move(s);
421 }
422
423 void set_grabber_fold_up(::std::unique_ptr<BufferedSolenoid> s) {
424 grabber_fold_up_ = ::std::move(s);
425 }
426
Brian Silvermand8f403a2014-12-13 19:12:04 -0500427 void operator()() {
428 ::aos::SetCurrentThreadName("Solenoids");
Brian Silverman5090c432016-01-02 14:44:26 -0800429 ::aos::SetCurrentThreadRealtimePriority(27);
430
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700431 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(20),
432 ::std::chrono::milliseconds(1));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500433
434 while (run_) {
Brian Silverman5090c432016-01-02 14:44:26 -0800435 {
436 const int iterations = phased_loop.SleepUntilNext();
437 if (iterations != 1) {
438 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
439 }
440 }
Brian Silvermand8f403a2014-12-13 19:12:04 -0500441
442 {
Daniel Pettiadf38432015-01-26 17:13:35 -0800443 fridge_.FetchLatest();
444 if (fridge_.get()) {
445 LOG_STRUCT(DEBUG, "solenoids", *fridge_);
Austin Schuh8ab58492015-02-22 21:32:29 -0800446 fridge_grabbers_top_front_->Set(!fridge_->grabbers.top_front);
447 fridge_grabbers_top_back_->Set(!fridge_->grabbers.top_back);
448 fridge_grabbers_bottom_front_->Set(!fridge_->grabbers.bottom_front);
449 fridge_grabbers_bottom_back_->Set(!fridge_->grabbers.bottom_back);
Daniel Pettiadf38432015-01-26 17:13:35 -0800450 }
451 }
452
453 {
454 claw_.FetchLatest();
455 if (claw_.get()) {
456 LOG_STRUCT(DEBUG, "solenoids", *claw_);
Austin Schuh8ab58492015-02-22 21:32:29 -0800457 claw_pinchers_->Set(claw_->rollers_closed);
Brian Silvermand8f403a2014-12-13 19:12:04 -0500458 }
459 }
460
Brian Silverman93936f72015-03-19 23:38:30 -0700461 ::aos::joystick_state.FetchLatest();
462 grabber_latch_release_->Set(::aos::joystick_state.get() != nullptr &&
463 ::aos::joystick_state->autonomous);
464 grabber_fold_up_->Set(::aos::joystick_state.get() != nullptr &&
465 ::aos::joystick_state->joysticks[1].buttons & 1);
466
Brian Silverman87541532015-03-19 23:35:12 -0700467 {
468 PneumaticsToLog to_log;
469 {
470 const bool compressor_on = !pressure_switch_->Get();
471 to_log.compressor_on = compressor_on;
472 if (compressor_on) {
473 compressor_relay_->Set(Relay::kForward);
474 } else {
475 compressor_relay_->Set(Relay::kOff);
476 }
477 }
478
479 pcm_->Flush();
480 to_log.read_solenoids = pcm_->GetAll();
481 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
482 }
Austin Schuh010eb812014-10-25 18:06:49 -0700483 }
484 }
485
Brian Silvermand8f403a2014-12-13 19:12:04 -0500486 void Quit() { run_ = false; }
Austin Schuh010eb812014-10-25 18:06:49 -0700487
Brian Silvermand8f403a2014-12-13 19:12:04 -0500488 private:
489 const ::std::unique_ptr<BufferedPcm> &pcm_;
Daniel Pettiadf38432015-01-26 17:13:35 -0800490 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_top_front_;
491 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_top_back_;
492 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_bottom_front_;
493 ::std::unique_ptr<BufferedSolenoid> fridge_grabbers_bottom_back_;
494 ::std::unique_ptr<BufferedSolenoid> claw_pinchers_;
Brian Silverman93936f72015-03-19 23:38:30 -0700495 ::std::unique_ptr<BufferedSolenoid> grabber_latch_release_;
496 ::std::unique_ptr<BufferedSolenoid> grabber_fold_up_;
Austin Schuh3b5b69b2015-10-31 18:55:47 -0700497 ::std::unique_ptr<DigitalInput> pressure_switch_;
Austin Schuh17a2a492015-02-20 22:12:24 -0800498 ::std::unique_ptr<Relay> compressor_relay_;
Austin Schuh010eb812014-10-25 18:06:49 -0700499
Austin Schuh88af0852016-12-04 20:31:32 -0800500 ::aos::Queue<::y2015::control_loops::fridge::FridgeQueue::Output> fridge_;
501 ::aos::Queue<::y2015::control_loops::ClawQueue::Output> claw_;
Austin Schuh010eb812014-10-25 18:06:49 -0700502
Brian Silvermand8f403a2014-12-13 19:12:04 -0500503 ::std::atomic<bool> run_{true};
504};
505
Austin Schuhbb227f82015-09-06 15:27:52 -0700506class CanWriter : public LoopOutputHandler {
507 public:
508 CanWriter() : LoopOutputHandler(::aos::time::Time::InSeconds(0.10)) {}
509
510 void set_can_talon(::std::unique_ptr<Talon> t) {
511 can_talon_ = ::std::move(t);
512 }
513
514 private:
515 virtual void Read() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800516 ::y2015::autonomous::can_control.FetchAnother();
Austin Schuhbb227f82015-09-06 15:27:52 -0700517 }
518
519 virtual void Write() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800520 auto &queue = ::y2015::autonomous::can_control;
Austin Schuhbb227f82015-09-06 15:27:52 -0700521 LOG_STRUCT(DEBUG, "will output", *queue);
522 can_talon_->Set(queue->can_voltage / 12.0);
523 }
524
525 virtual void Stop() override {
526 LOG(WARNING, "Can output too old\n");
527 can_talon_->Disable();
528 }
529
530 ::std::unique_ptr<Talon> can_talon_;
531};
532
Brian Silvermand8f403a2014-12-13 19:12:04 -0500533class DrivetrainWriter : public LoopOutputHandler {
534 public:
535 void set_left_drivetrain_talon(::std::unique_ptr<Talon> t) {
536 left_drivetrain_talon_ = ::std::move(t);
Austin Schuh010eb812014-10-25 18:06:49 -0700537 }
538
Brian Silvermand8f403a2014-12-13 19:12:04 -0500539 void set_right_drivetrain_talon(::std::unique_ptr<Talon> t) {
540 right_drivetrain_talon_ = ::std::move(t);
541 }
Austin Schuh010eb812014-10-25 18:06:49 -0700542
Brian Silvermand8f403a2014-12-13 19:12:04 -0500543 private:
544 virtual void Read() override {
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500545 ::frc971::control_loops::drivetrain_queue.output.FetchAnother();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500546 }
547
548 virtual void Write() override {
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500549 auto &queue = ::frc971::control_loops::drivetrain_queue.output;
Brian Silvermand8f403a2014-12-13 19:12:04 -0500550 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuha004b0c2015-02-16 17:06:30 -0800551 left_drivetrain_talon_->Set(queue->left_voltage / 12.0);
552 right_drivetrain_talon_->Set(-queue->right_voltage / 12.0);
Brian Silvermand8f403a2014-12-13 19:12:04 -0500553 }
554
555 virtual void Stop() override {
556 LOG(WARNING, "drivetrain output too old\n");
557 left_drivetrain_talon_->Disable();
558 right_drivetrain_talon_->Disable();
559 }
560
Austin Schuh010eb812014-10-25 18:06:49 -0700561 ::std::unique_ptr<Talon> left_drivetrain_talon_;
Brian Silvermand8f403a2014-12-13 19:12:04 -0500562 ::std::unique_ptr<Talon> right_drivetrain_talon_;
563};
564
Daniel Pettiadf38432015-01-26 17:13:35 -0800565class FridgeWriter : public LoopOutputHandler {
566 public:
567 void set_left_arm_talon(::std::unique_ptr<Talon> t) {
568 left_arm_talon_ = ::std::move(t);
569 }
570
571 void set_right_arm_talon(::std::unique_ptr<Talon> t) {
572 right_arm_talon_ = ::std::move(t);
573 }
574
575 void set_left_elevator_talon(::std::unique_ptr<Talon> t) {
576 left_elevator_talon_ = ::std::move(t);
577 }
578
579 void set_right_elevator_talon(::std::unique_ptr<Talon> t) {
580 right_elevator_talon_ = ::std::move(t);
581 }
582
583 private:
584 virtual void Read() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800585 ::y2015::control_loops::fridge::fridge_queue.output.FetchAnother();
Daniel Pettiadf38432015-01-26 17:13:35 -0800586 }
587
588 virtual void Write() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800589 auto &queue = ::y2015::control_loops::fridge::fridge_queue.output;
Daniel Pettiadf38432015-01-26 17:13:35 -0800590 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuh859a9302015-02-16 15:45:45 -0800591 left_arm_talon_->Set(queue->left_arm / 12.0);
592 right_arm_talon_->Set(-queue->right_arm / 12.0);
593 left_elevator_talon_->Set(queue->left_elevator / 12.0);
594 right_elevator_talon_->Set(-queue->right_elevator / 12.0);
Daniel Pettiadf38432015-01-26 17:13:35 -0800595 }
596
597 virtual void Stop() override {
598 LOG(WARNING, "Fridge output too old.\n");
599 left_arm_talon_->Disable();
600 right_arm_talon_->Disable();
601 left_elevator_talon_->Disable();
602 right_elevator_talon_->Disable();
603 }
604
605 ::std::unique_ptr<Talon> left_arm_talon_;
606 ::std::unique_ptr<Talon> right_arm_talon_;
607 ::std::unique_ptr<Talon> left_elevator_talon_;
608 ::std::unique_ptr<Talon> right_elevator_talon_;
609};
610
611class ClawWriter : public LoopOutputHandler {
612 public:
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800613 void set_left_intake_talon(::std::unique_ptr<Talon> t) {
614 left_intake_talon_ = ::std::move(t);
615 }
616
617 void set_right_intake_talon(::std::unique_ptr<Talon> t) {
618 right_intake_talon_ = ::std::move(t);
Daniel Pettiadf38432015-01-26 17:13:35 -0800619 }
620
621 void set_wrist_talon(::std::unique_ptr<Talon> t) {
622 wrist_talon_ = ::std::move(t);
623 }
624
625 private:
626 virtual void Read() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800627 ::y2015::control_loops::claw_queue.output.FetchAnother();
Daniel Pettiadf38432015-01-26 17:13:35 -0800628 }
629
630 virtual void Write() override {
Austin Schuh88af0852016-12-04 20:31:32 -0800631 auto &queue = ::y2015::control_loops::claw_queue.output;
Daniel Pettiadf38432015-01-26 17:13:35 -0800632 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800633 left_intake_talon_->Set(queue->intake_voltage / 12.0);
Austin Schuh8a436e82015-02-16 23:31:28 -0800634 right_intake_talon_->Set(-queue->intake_voltage / 12.0);
635 wrist_talon_->Set(-queue->voltage / 12.0);
Daniel Pettiadf38432015-01-26 17:13:35 -0800636 }
637
638 virtual void Stop() override {
639 LOG(WARNING, "Claw output too old.\n");
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800640 left_intake_talon_->Disable();
641 right_intake_talon_->Disable();
Daniel Pettiadf38432015-01-26 17:13:35 -0800642 wrist_talon_->Disable();
643 }
644
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800645 ::std::unique_ptr<Talon> left_intake_talon_;
646 ::std::unique_ptr<Talon> right_intake_talon_;
Daniel Pettiadf38432015-01-26 17:13:35 -0800647 ::std::unique_ptr<Talon> wrist_talon_;
648};
649
Brian Silverman1f90d672015-01-26 20:20:45 -0500650// TODO(brian): Replace this with ::std::make_unique once all our toolchains
651// have support.
652template <class T, class... U>
653std::unique_ptr<T> make_unique(U &&... u) {
654 return std::unique_ptr<T>(new T(std::forward<U>(u)...));
655}
656
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800657class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
Austin Schuh010eb812014-10-25 18:06:49 -0700658 public:
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800659 ::std::unique_ptr<Encoder> encoder(int index) {
660 return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false,
661 Encoder::k4X);
662 }
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800663 virtual void Run() {
Brian Silvermand8f403a2014-12-13 19:12:04 -0500664 ::aos::InitNRT();
Brian Silverman2fe007c2014-12-28 12:20:01 -0800665 ::aos::SetCurrentThreadName("StartCompetition");
Brian Silvermand8f403a2014-12-13 19:12:04 -0500666
Brian Silverman98f6ee22015-01-26 17:50:12 -0500667 JoystickSender joystick_sender;
Austin Schuh010eb812014-10-25 18:06:49 -0700668 ::std::thread joystick_thread(::std::ref(joystick_sender));
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800669 // TODO(austin): Compressor needs to use a spike.
Brian Silvermand8f403a2014-12-13 19:12:04 -0500670
Brian Silverman425492b2015-12-30 15:23:55 -0800671 ::frc971::wpilib::PDPFetcher pdp_fetcher;
672 ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
673
Brian Silverman39b339e2016-01-03 13:24:22 -0800674 SensorReader reader;
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800675 reader.set_arm_left_encoder(encoder(1));
676 reader.set_arm_left_index(make_unique<DigitalInput>(1));
677 reader.set_arm_left_potentiometer(make_unique<AnalogInput>(1));
678
679 reader.set_arm_right_encoder(encoder(5));
680 reader.set_arm_right_index(make_unique<DigitalInput>(5));
681 reader.set_arm_right_potentiometer(make_unique<AnalogInput>(5));
682
683 reader.set_elevator_left_encoder(encoder(0));
684 reader.set_elevator_left_index(make_unique<DigitalInput>(0));
685 reader.set_elevator_left_potentiometer(make_unique<AnalogInput>(0));
686
687 reader.set_elevator_right_encoder(encoder(4));
688 reader.set_elevator_right_index(make_unique<DigitalInput>(4));
689 reader.set_elevator_right_potentiometer(make_unique<AnalogInput>(4));
690
691 reader.set_wrist_encoder(encoder(6));
692 reader.set_wrist_index(make_unique<DigitalInput>(6));
693 reader.set_wrist_potentiometer(make_unique<AnalogInput>(6));
694
695 reader.set_left_encoder(encoder(2));
696 reader.set_right_encoder(encoder(3));
Brian Silverman335c20e2015-01-26 21:47:58 -0500697 reader.set_dma(make_unique<DMA>());
Brian Silverman98f6ee22015-01-26 17:50:12 -0500698 ::std::thread reader_thread(::std::ref(reader));
699 GyroSender gyro_sender;
700 ::std::thread gyro_thread(::std::ref(gyro_sender));
701
702 DrivetrainWriter drivetrain_writer;
Brian Silvermand8f403a2014-12-13 19:12:04 -0500703 drivetrain_writer.set_left_drivetrain_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800704 ::std::unique_ptr<Talon>(new Talon(8)));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500705 drivetrain_writer.set_right_drivetrain_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800706 ::std::unique_ptr<Talon>(new Talon(0)));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500707 ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
708
Austin Schuhbb227f82015-09-06 15:27:52 -0700709 CanWriter can_writer;
710 can_writer.set_can_talon(::std::unique_ptr<Talon>(new Talon(9)));
711 ::std::thread can_writer_thread(::std::ref(can_writer));
712
Daniel Pettiadf38432015-01-26 17:13:35 -0800713 // TODO(sensors): Get real PWM output and relay numbers for the fridge and
714 // claw.
715 FridgeWriter fridge_writer;
716 fridge_writer.set_left_arm_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800717 ::std::unique_ptr<Talon>(new Talon(6)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800718 fridge_writer.set_right_arm_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800719 ::std::unique_ptr<Talon>(new Talon(2)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800720 fridge_writer.set_left_elevator_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800721 ::std::unique_ptr<Talon>(new Talon(7)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800722 fridge_writer.set_right_elevator_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800723 ::std::unique_ptr<Talon>(new Talon(1)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800724 ::std::thread fridge_writer_thread(::std::ref(fridge_writer));
725
726 ClawWriter claw_writer;
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800727 claw_writer.set_left_intake_talon(
728 ::std::unique_ptr<Talon>(new Talon(5)));
729 claw_writer.set_right_intake_talon(
730 ::std::unique_ptr<Talon>(new Talon(3)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800731 claw_writer.set_wrist_talon(
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800732 ::std::unique_ptr<Talon>(new Talon(4)));
Daniel Pettiadf38432015-01-26 17:13:35 -0800733 ::std::thread claw_writer_thread(::std::ref(claw_writer));
734
735 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
736 new ::frc971::wpilib::BufferedPcm());
Brian Silverman98f6ee22015-01-26 17:50:12 -0500737 SolenoidWriter solenoid_writer(pcm);
Austin Schuh17a2a492015-02-20 22:12:24 -0800738 solenoid_writer.set_fridge_grabbers_top_front(pcm->MakeSolenoid(0));
739 solenoid_writer.set_fridge_grabbers_top_back(pcm->MakeSolenoid(0));
Austin Schuh58d8cdf2015-02-15 21:04:42 -0800740 solenoid_writer.set_fridge_grabbers_bottom_front(pcm->MakeSolenoid(2));
Austin Schuh17a2a492015-02-20 22:12:24 -0800741 solenoid_writer.set_fridge_grabbers_bottom_back(pcm->MakeSolenoid(1));
742 solenoid_writer.set_claw_pinchers(pcm->MakeSolenoid(4));
Brian Silverman93936f72015-03-19 23:38:30 -0700743 solenoid_writer.set_grabber_latch_release(pcm->MakeSolenoid(7));
744 solenoid_writer.set_grabber_fold_up(pcm->MakeSolenoid(5));
Austin Schuh17a2a492015-02-20 22:12:24 -0800745
746 solenoid_writer.set_pressure_switch(make_unique<DigitalInput>(9));
747 solenoid_writer.set_compressor_relay(make_unique<Relay>(0));
Brian Silvermand8f403a2014-12-13 19:12:04 -0500748 ::std::thread solenoid_thread(::std::ref(solenoid_writer));
749
750 // Wait forever. Not much else to do...
Brian Silverman5090c432016-01-02 14:44:26 -0800751 while (true) {
752 const int r = select(0, nullptr, nullptr, nullptr, nullptr);
753 if (r != 0) {
754 PLOG(WARNING, "infinite select failed");
755 } else {
756 PLOG(WARNING, "infinite select succeeded??\n");
757 }
758 }
Brian Silvermand8f403a2014-12-13 19:12:04 -0500759
Austin Schuh010eb812014-10-25 18:06:49 -0700760 LOG(ERROR, "Exiting WPILibRobot\n");
Brian Silverman07ec88e2014-12-28 00:13:08 -0800761
Austin Schuh010eb812014-10-25 18:06:49 -0700762 joystick_sender.Quit();
763 joystick_thread.join();
Brian Silverman425492b2015-12-30 15:23:55 -0800764 pdp_fetcher.Quit();
765 pdp_fetcher_thread.join();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500766 reader.Quit();
767 reader_thread.join();
Brian Silverman07ec88e2014-12-28 00:13:08 -0800768 gyro_sender.Quit();
769 gyro_thread.join();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500770
771 drivetrain_writer.Quit();
772 drivetrain_writer_thread.join();
Austin Schuhbb227f82015-09-06 15:27:52 -0700773 can_writer.Quit();
774 can_writer_thread.join();
Brian Silvermand8f403a2014-12-13 19:12:04 -0500775 solenoid_writer.Quit();
776 solenoid_thread.join();
777
Austin Schuh010eb812014-10-25 18:06:49 -0700778 ::aos::Cleanup();
779 }
780};
781
Brian Silverman98f6ee22015-01-26 17:50:12 -0500782} // namespace wpilib
Austin Schuh88af0852016-12-04 20:31:32 -0800783} // namespace y2015
Austin Schuhdb516032014-12-28 00:12:38 -0800784
Brian Silverman98f6ee22015-01-26 17:50:12 -0500785
Austin Schuh88af0852016-12-04 20:31:32 -0800786AOS_ROBOT_CLASS(::y2015::wpilib::WPILibRobot);