blob: 650911a96e0ff4fad30e11f75d1849cf9b0255fc [file] [log] [blame]
Brian Silverman17f503e2015-08-02 18:17:18 -07001#include <stdio.h>
2#include <string.h>
3#include <unistd.h>
4#include <inttypes.h>
5
6#include <thread>
Austin Schuh8aec1ed2016-05-01 13:29:20 -07007#include <chrono>
Brian Silverman17f503e2015-08-02 18:17:18 -07008#include <mutex>
9#include <functional>
10
Parker Schuhd3b7a8872018-02-19 16:42:27 -080011#include "frc971/wpilib/ahal/AnalogInput.h"
12#include "frc971/wpilib/ahal/Compressor.h"
13#include "frc971/wpilib/ahal/DigitalGlitchFilter.h"
14#include "frc971/wpilib/ahal/DriverStation.h"
15#include "frc971/wpilib/ahal/Encoder.h"
16#include "frc971/wpilib/ahal/Relay.h"
17#include "frc971/wpilib/ahal/Talon.h"
Campbell Crowleyc0cfb132015-12-30 20:58:02 -080018#include "frc971/wpilib/wpilib_robot_base.h"
Austin Schuh6d5d9ae2015-10-31 19:39:57 -070019#undef ERROR
20
Brian Silvermanf819b442019-01-20 16:51:04 -080021#include "aos/init.h"
John Park33858a32018-09-28 23:05:48 -070022#include "aos/logging/logging.h"
23#include "aos/logging/queue_logging.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080024#include "aos/make_unique.h"
25#include "aos/robot_state/robot_state.q.h"
26#include "aos/stl_mutex/stl_mutex.h"
John Park33858a32018-09-28 23:05:48 -070027#include "aos/time/time.h"
28#include "aos/util/log_interval.h"
29#include "aos/util/phased_loop.h"
30#include "aos/util/wrapping_counter.h"
Comran Morshed5323ecb2015-12-26 20:50:55 +000031#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Austin Schuh2c2cc2e2019-02-02 20:19:45 -080032#include "frc971/shifter_hall_effect.h"
33#include "frc971/wpilib/buffered_pcm.h"
34#include "frc971/wpilib/buffered_solenoid.h"
35#include "frc971/wpilib/dma.h"
36#include "frc971/wpilib/dma_edge_counting.h"
Sabina Davis05f580f2019-02-03 01:17:35 -080037#include "frc971/wpilib/drivetrain_writer.h"
Austin Schuh2c2cc2e2019-02-02 20:19:45 -080038#include "frc971/wpilib/encoder_and_potentiometer.h"
39#include "frc971/wpilib/gyro_sender.h"
40#include "frc971/wpilib/interrupt_edge_counting.h"
41#include "frc971/wpilib/joystick_sender.h"
42#include "frc971/wpilib/logging.q.h"
43#include "frc971/wpilib/loop_output_handler.h"
44#include "frc971/wpilib/pdp_fetcher.h"
45#include "frc971/wpilib/sensor_reader.h"
46#include "y2014/constants.h"
Brian Silverman17f503e2015-08-02 18:17:18 -070047#include "y2014/control_loops/claw/claw.q.h"
Brian Silverman552350b2015-08-02 18:23:34 -070048#include "y2014/control_loops/shooter/shooter.q.h"
Brian Silverman552350b2015-08-02 18:23:34 -070049#include "y2014/queues/auto_mode.q.h"
Brian Silverman17f503e2015-08-02 18:17:18 -070050
Brian Silverman17f503e2015-08-02 18:17:18 -070051#ifndef M_PI
52#define M_PI 3.14159265358979323846
53#endif
54
Comran Morshed5323ecb2015-12-26 20:50:55 +000055using ::frc971::control_loops::drivetrain_queue;
Brian Silvermanb601d892015-12-20 18:24:38 -050056using ::y2014::control_loops::claw_queue;
57using ::y2014::control_loops::shooter_queue;
Parker Schuhd3b7a8872018-02-19 16:42:27 -080058using namespace frc;
Brian Silvermanf819b442019-01-20 16:51:04 -080059using aos::make_unique;
Brian Silverman17f503e2015-08-02 18:17:18 -070060
Brian Silvermanb601d892015-12-20 18:24:38 -050061namespace y2014 {
Brian Silverman17f503e2015-08-02 18:17:18 -070062namespace wpilib {
63
Brian Silverman85fbb602015-08-29 19:28:20 -070064// TODO(Brian): Fix the interpretation of the result of GetRaw here and in the
65// DMA stuff and then removing the * 2.0 in *_translate.
66// The low bit is direction.
67
Brian Silverman17f503e2015-08-02 18:17:18 -070068double drivetrain_translate(int32_t in) {
Brian Silverman85fbb602015-08-29 19:28:20 -070069 return -static_cast<double>(in) /
Brian Silverman17f503e2015-08-02 18:17:18 -070070 (256.0 /*cpr*/ * 4.0 /*4x*/) *
71 constants::GetValues().drivetrain_encoder_ratio *
Austin Schuh86f895e2015-11-08 13:40:51 -080072 (3.5 /*wheel diameter*/ * 2.54 / 100.0 * M_PI) * 2.0 / 2.0;
Brian Silverman17f503e2015-08-02 18:17:18 -070073}
74
Brian Silverman51091a02015-12-26 15:56:58 -080075double drivetrain_velocity_translate(double in) {
76 return (1.0 / in) / 256.0 /*cpr*/ *
77 constants::GetValues().drivetrain_encoder_ratio *
78 (3.5 /*wheel diameter*/ * 2.54 / 100.0 * M_PI) * 2.0 / 2.0;
79}
80
Sabina Davis415bb6c2017-10-16 23:30:52 -070081float hall_translate(const constants::DualHallShifterHallEffect &k, float in_low,
Brian Silverman552350b2015-08-02 18:23:34 -070082 float in_high) {
83 const float low_ratio =
Sabina Davis415bb6c2017-10-16 23:30:52 -070084 0.5 * (in_low - static_cast<float>(k.shifter_hall_effect.low_gear_low)) /
85 static_cast<float>(k.low_gear_middle - k.shifter_hall_effect.low_gear_low);
Brian Silverman552350b2015-08-02 18:23:34 -070086 const float high_ratio =
Sabina Davis415bb6c2017-10-16 23:30:52 -070087 0.5 +
88 0.5 * (in_high - static_cast<float>(k.high_gear_middle)) /
89 static_cast<float>(k.shifter_hall_effect.high_gear_high -
90 k.high_gear_middle);
Brian Silverman17f503e2015-08-02 18:17:18 -070091
Brian Silverman552350b2015-08-02 18:23:34 -070092 // Return low when we are below 1/2, and high when we are above 1/2.
93 if (low_ratio + high_ratio < 1.0) {
94 return low_ratio;
95 } else {
96 return high_ratio;
97 }
Brian Silverman17f503e2015-08-02 18:17:18 -070098}
99
100double claw_translate(int32_t in) {
Brian Silverman85fbb602015-08-29 19:28:20 -0700101 return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*quad*/) /
Brian Silverman552350b2015-08-02 18:23:34 -0700102 (18.0 / 48.0 /*encoder gears*/) / (12.0 / 60.0 /*chain reduction*/) *
Brian Silverman85fbb602015-08-29 19:28:20 -0700103 (M_PI / 180.0) * 2.0;
Brian Silverman17f503e2015-08-02 18:17:18 -0700104}
105
Brian Silverman552350b2015-08-02 18:23:34 -0700106double shooter_translate(int32_t in) {
107 return static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*quad*/) *
108 16 /*sprocket teeth*/ * 0.375 /*chain pitch*/
109 * (2.54 / 100.0 /*in to m*/);
Brian Silverman17f503e2015-08-02 18:17:18 -0700110}
111
112static const double kMaximumEncoderPulsesPerSecond =
Brian Silverman552350b2015-08-02 18:23:34 -0700113 5600.0 /* free speed RPM */ * 14.0 / 48.0 /* bottom gear reduction */ *
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800114 18.0 / 32.0 /* big belt reduction */ * 18.0 /
115 66.0 /* top gear reduction */ * 48.0 / 18.0 /* encoder gears */ /
116 60.0 /* seconds / minute */ * 256.0 /* CPR */ * 4.0 /* edges / pulse */;
Brian Silverman17f503e2015-08-02 18:17:18 -0700117
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800118class SensorReader : public ::frc971::wpilib::SensorReader {
Brian Silverman17f503e2015-08-02 18:17:18 -0700119 public:
Brian Silverman39b339e2016-01-03 13:24:22 -0800120 SensorReader() {
Brian Silverman17f503e2015-08-02 18:17:18 -0700121 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
122 // we should ever see.
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800123 UpdateMediumEncoderFilterHz(kMaximumEncoderPulsesPerSecond);
Brian Silverman552350b2015-08-02 18:23:34 -0700124 hall_filter_.SetPeriodNanoSeconds(100000);
Brian Silverman17f503e2015-08-02 18:17:18 -0700125 }
126
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800127 ~SensorReader() override {
128 top_reader_.Quit();
129 bottom_reader_.Quit();
130 }
131
Brian Silverman552350b2015-08-02 18:23:34 -0700132 void set_auto_selector_analog(::std::unique_ptr<AnalogInput> analog) {
133 auto_selector_analog_ = ::std::move(analog);
Brian Silverman17f503e2015-08-02 18:17:18 -0700134 }
135
Brian Silverman552350b2015-08-02 18:23:34 -0700136 void set_high_left_drive_hall(::std::unique_ptr<AnalogInput> analog) {
137 high_left_drive_hall_ = ::std::move(analog);
Brian Silverman17f503e2015-08-02 18:17:18 -0700138 }
139
Brian Silverman552350b2015-08-02 18:23:34 -0700140 void set_low_right_drive_hall(::std::unique_ptr<AnalogInput> analog) {
141 low_right_drive_hall_ = ::std::move(analog);
Brian Silverman17f503e2015-08-02 18:17:18 -0700142 }
143
Brian Silverman552350b2015-08-02 18:23:34 -0700144 void set_high_right_drive_hall(::std::unique_ptr<AnalogInput> analog) {
145 high_right_drive_hall_ = ::std::move(analog);
Brian Silverman17f503e2015-08-02 18:17:18 -0700146 }
147
Brian Silverman552350b2015-08-02 18:23:34 -0700148 void set_low_left_drive_hall(::std::unique_ptr<AnalogInput> analog) {
149 low_left_drive_hall_ = ::std::move(analog);
Brian Silverman17f503e2015-08-02 18:17:18 -0700150 }
151
Brian Silverman552350b2015-08-02 18:23:34 -0700152 void set_top_claw_encoder(::std::unique_ptr<Encoder> encoder) {
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800153 medium_encoder_filter_.Add(encoder.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700154 top_reader_.set_encoder(::std::move(encoder));
Brian Silverman17f503e2015-08-02 18:17:18 -0700155 }
156
Austin Schuhc5e36082015-10-31 13:30:46 -0700157 void set_top_claw_front_hall(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700158 hall_filter_.Add(hall.get());
159 top_reader_.set_front_hall(::std::move(hall));
Brian Silverman17f503e2015-08-02 18:17:18 -0700160 }
161
Austin Schuhc5e36082015-10-31 13:30:46 -0700162 void set_top_claw_calibration_hall(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700163 hall_filter_.Add(hall.get());
164 top_reader_.set_calibration_hall(::std::move(hall));
Brian Silverman17f503e2015-08-02 18:17:18 -0700165 }
166
Austin Schuhc5e36082015-10-31 13:30:46 -0700167 void set_top_claw_back_hall(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700168 hall_filter_.Add(hall.get());
169 top_reader_.set_back_hall(::std::move(hall));
Brian Silverman17f503e2015-08-02 18:17:18 -0700170 }
171
Brian Silverman552350b2015-08-02 18:23:34 -0700172 void set_bottom_claw_encoder(::std::unique_ptr<Encoder> encoder) {
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800173 medium_encoder_filter_.Add(encoder.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700174 bottom_reader_.set_encoder(::std::move(encoder));
Brian Silverman17f503e2015-08-02 18:17:18 -0700175 }
176
Austin Schuhc5e36082015-10-31 13:30:46 -0700177 void set_bottom_claw_front_hall(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700178 hall_filter_.Add(hall.get());
179 bottom_reader_.set_front_hall(::std::move(hall));
Brian Silverman17f503e2015-08-02 18:17:18 -0700180 }
181
Austin Schuhc5e36082015-10-31 13:30:46 -0700182 void set_bottom_claw_calibration_hall(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700183 hall_filter_.Add(hall.get());
184 bottom_reader_.set_calibration_hall(::std::move(hall));
Brian Silverman17f503e2015-08-02 18:17:18 -0700185 }
186
Austin Schuhc5e36082015-10-31 13:30:46 -0700187 void set_bottom_claw_back_hall(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700188 hall_filter_.Add(hall.get());
189 bottom_reader_.set_back_hall(::std::move(hall));
Brian Silverman17f503e2015-08-02 18:17:18 -0700190 }
191
Brian Silverman552350b2015-08-02 18:23:34 -0700192 void set_shooter_encoder(::std::unique_ptr<Encoder> encoder) {
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800193 medium_encoder_filter_.Add(encoder.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700194 shooter_encoder_ = ::std::move(encoder);
Brian Silverman17f503e2015-08-02 18:17:18 -0700195 }
196
Austin Schuhc5e36082015-10-31 13:30:46 -0700197 void set_shooter_proximal(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700198 hall_filter_.Add(hall.get());
199 shooter_proximal_ = ::std::move(hall);
200 }
201
Austin Schuhc5e36082015-10-31 13:30:46 -0700202 void set_shooter_distal(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700203 hall_filter_.Add(hall.get());
204 shooter_distal_ = ::std::move(hall);
205 }
206
Austin Schuhc5e36082015-10-31 13:30:46 -0700207 void set_shooter_plunger(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700208 hall_filter_.Add(hall.get());
209 shooter_plunger_ = ::std::move(hall);
210 shooter_plunger_reader_ =
Brian Silvermanb601d892015-12-20 18:24:38 -0500211 make_unique<::frc971::wpilib::DMADigitalReader>(shooter_plunger_.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700212 }
213
Austin Schuhc5e36082015-10-31 13:30:46 -0700214 void set_shooter_latch(::std::unique_ptr<DigitalInput> hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700215 hall_filter_.Add(hall.get());
216 shooter_latch_ = ::std::move(hall);
Brian Silvermanb601d892015-12-20 18:24:38 -0500217 shooter_latch_reader_ =
218 make_unique<::frc971::wpilib::DMADigitalReader>(shooter_latch_.get());
Brian Silverman17f503e2015-08-02 18:17:18 -0700219 }
220
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800221 void Start() override {
Brian Silvermanb601d892015-12-20 18:24:38 -0500222 shooter_proximal_counter_ = make_unique<::frc971::wpilib::DMAEdgeCounter>(
Brian Silverman552350b2015-08-02 18:23:34 -0700223 shooter_encoder_.get(), shooter_proximal_.get());
Brian Silvermanb601d892015-12-20 18:24:38 -0500224 shooter_distal_counter_ = make_unique<::frc971::wpilib::DMAEdgeCounter>(
Brian Silverman552350b2015-08-02 18:23:34 -0700225 shooter_encoder_.get(), shooter_distal_.get());
226
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800227 AddToDMA(shooter_proximal_counter_.get());
228 AddToDMA(shooter_distal_counter_.get());
229 AddToDMA(shooter_plunger_reader_.get());
230 AddToDMA(shooter_latch_reader_.get());
Brian Silverman17f503e2015-08-02 18:17:18 -0700231
Brian Silverman552350b2015-08-02 18:23:34 -0700232 top_reader_.Start();
233 bottom_reader_.Start();
Brian Silverman17f503e2015-08-02 18:17:18 -0700234 }
235
236 void RunIteration() {
Brian Silverman552350b2015-08-02 18:23:34 -0700237 const auto &values = constants::GetValues();
238
Brian Silverman17f503e2015-08-02 18:17:18 -0700239 {
240 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
241 drivetrain_message->right_encoder =
Brian Silverman552350b2015-08-02 18:23:34 -0700242 drivetrain_translate(drivetrain_right_encoder_->GetRaw());
Brian Silverman17f503e2015-08-02 18:17:18 -0700243 drivetrain_message->left_encoder =
Brian Silverman552350b2015-08-02 18:23:34 -0700244 -drivetrain_translate(drivetrain_left_encoder_->GetRaw());
Brian Silverman51091a02015-12-26 15:56:58 -0800245 drivetrain_message->left_speed =
246 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
247 drivetrain_message->right_speed =
248 drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod());
Austin Schuha0c1e152015-11-08 14:10:13 -0800249
250 drivetrain_message->low_left_hall = low_left_drive_hall_->GetVoltage();
251 drivetrain_message->high_left_hall = high_left_drive_hall_->GetVoltage();
Brian Silverman552350b2015-08-02 18:23:34 -0700252 drivetrain_message->left_shifter_position =
Austin Schuha0c1e152015-11-08 14:10:13 -0800253 hall_translate(values.left_drive, drivetrain_message->low_left_hall,
254 drivetrain_message->high_left_hall);
255
256 drivetrain_message->low_right_hall = low_right_drive_hall_->GetVoltage();
257 drivetrain_message->high_right_hall =
258 high_right_drive_hall_->GetVoltage();
259 drivetrain_message->right_shifter_position =
260 hall_translate(values.right_drive, drivetrain_message->low_right_hall,
261 drivetrain_message->high_right_hall);
Brian Silverman17f503e2015-08-02 18:17:18 -0700262
263 drivetrain_message.Send();
264 }
265
Brian Silvermanb601d892015-12-20 18:24:38 -0500266 ::y2014::sensors::auto_mode.MakeWithBuilder()
Brian Silverman552350b2015-08-02 18:23:34 -0700267 .voltage(auto_selector_analog_->GetVoltage())
268 .Send();
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800269 }
Brian Silverman552350b2015-08-02 18:23:34 -0700270
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800271 void RunDmaIteration() {
Brian Silverman17f503e2015-08-02 18:17:18 -0700272 {
Brian Silverman552350b2015-08-02 18:23:34 -0700273 auto shooter_message = shooter_queue.position.MakeMessage();
274 shooter_message->position = shooter_translate(shooter_encoder_->GetRaw());
Austin Schuh5c25ab72015-11-01 13:17:11 -0800275 shooter_message->plunger = !shooter_plunger_reader_->value();
276 shooter_message->latch = !shooter_latch_reader_->value();
Brian Silverman552350b2015-08-02 18:23:34 -0700277 CopyShooterPosedgeCounts(shooter_proximal_counter_.get(),
278 &shooter_message->pusher_proximal);
279 CopyShooterPosedgeCounts(shooter_distal_counter_.get(),
280 &shooter_message->pusher_distal);
281
282 shooter_message.Send();
Brian Silverman17f503e2015-08-02 18:17:18 -0700283 }
284
285 {
286 auto claw_message = claw_queue.position.MakeMessage();
Brian Silverman552350b2015-08-02 18:23:34 -0700287 top_reader_.RunIteration(&claw_message->top);
288 bottom_reader_.RunIteration(&claw_message->bottom);
289
Brian Silverman17f503e2015-08-02 18:17:18 -0700290 claw_message.Send();
291 }
292 }
293
Brian Silverman17f503e2015-08-02 18:17:18 -0700294 private:
Brian Silverman552350b2015-08-02 18:23:34 -0700295 class HalfClawReader {
296 public:
297 HalfClawReader(bool reversed) : reversed_(reversed) {}
298
299 void set_encoder(::std::unique_ptr<Encoder> encoder) {
300 encoder_ = ::std::move(encoder);
301 }
302
Austin Schuhc5e36082015-10-31 13:30:46 -0700303 void set_front_hall(::std::unique_ptr<DigitalInput> front_hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700304 front_hall_ = ::std::move(front_hall);
305 }
306
307 void set_calibration_hall(
Austin Schuhc5e36082015-10-31 13:30:46 -0700308 ::std::unique_ptr<DigitalInput> calibration_hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700309 calibration_hall_ = ::std::move(calibration_hall);
310 }
311
Austin Schuhc5e36082015-10-31 13:30:46 -0700312 void set_back_hall(::std::unique_ptr<DigitalInput> back_hall) {
Brian Silverman552350b2015-08-02 18:23:34 -0700313 back_hall_ = ::std::move(back_hall);
314 }
315
316 void Start() {
Brian Silvermanb601d892015-12-20 18:24:38 -0500317 front_counter_ = make_unique<::frc971::wpilib::EdgeCounter>(
318 encoder_.get(), front_hall_.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700319 synchronizer_.Add(front_counter_.get());
Brian Silvermanb601d892015-12-20 18:24:38 -0500320 calibration_counter_ = make_unique<::frc971::wpilib::EdgeCounter>(
321 encoder_.get(), calibration_hall_.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700322 synchronizer_.Add(calibration_counter_.get());
Brian Silvermanb601d892015-12-20 18:24:38 -0500323 back_counter_ = make_unique<::frc971::wpilib::EdgeCounter>(
324 encoder_.get(), back_hall_.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700325 synchronizer_.Add(back_counter_.get());
326 synchronized_encoder_ =
Brian Silvermanb601d892015-12-20 18:24:38 -0500327 make_unique<::frc971::wpilib::InterruptSynchronizedEncoder>(
328 encoder_.get());
Brian Silverman552350b2015-08-02 18:23:34 -0700329 synchronizer_.Add(synchronized_encoder_.get());
330
331 synchronizer_.Start();
332 }
333
334 void Quit() { synchronizer_.Quit(); }
335
336 void RunIteration(control_loops::HalfClawPosition *half_claw_position) {
337 const double multiplier = reversed_ ? -1.0 : 1.0;
338
339 synchronizer_.RunIteration();
340
341 CopyPosition(front_counter_.get(), &half_claw_position->front);
342 CopyPosition(calibration_counter_.get(),
343 &half_claw_position->calibration);
344 CopyPosition(back_counter_.get(), &half_claw_position->back);
345 half_claw_position->position =
346 multiplier * claw_translate(synchronized_encoder_->get());
347 }
348
349 private:
Brian Silvermanb601d892015-12-20 18:24:38 -0500350 void CopyPosition(const ::frc971::wpilib::EdgeCounter *counter,
351 ::frc971::HallEffectStruct *out) {
Brian Silverman552350b2015-08-02 18:23:34 -0700352 const double multiplier = reversed_ ? -1.0 : 1.0;
353
Austin Schuh5c25ab72015-11-01 13:17:11 -0800354 out->current = !counter->polled_value();
355 out->posedge_count = counter->negative_interrupt_count();
356 out->negedge_count = counter->positive_interrupt_count();
Brian Silverman552350b2015-08-02 18:23:34 -0700357 out->negedge_value =
Austin Schuh5c25ab72015-11-01 13:17:11 -0800358 multiplier * claw_translate(counter->last_positive_encoder_value());
359 out->posedge_value =
Brian Silverman552350b2015-08-02 18:23:34 -0700360 multiplier * claw_translate(counter->last_negative_encoder_value());
361 }
362
Brian Silverman5090c432016-01-02 14:44:26 -0800363 ::frc971::wpilib::InterruptSynchronizer synchronizer_{55};
Brian Silverman552350b2015-08-02 18:23:34 -0700364
Brian Silvermanb601d892015-12-20 18:24:38 -0500365 ::std::unique_ptr<::frc971::wpilib::EdgeCounter> front_counter_;
366 ::std::unique_ptr<::frc971::wpilib::EdgeCounter> calibration_counter_;
367 ::std::unique_ptr<::frc971::wpilib::EdgeCounter> back_counter_;
368 ::std::unique_ptr<::frc971::wpilib::InterruptSynchronizedEncoder>
369 synchronized_encoder_;
Brian Silverman552350b2015-08-02 18:23:34 -0700370
371 ::std::unique_ptr<Encoder> encoder_;
Austin Schuhc5e36082015-10-31 13:30:46 -0700372 ::std::unique_ptr<DigitalInput> front_hall_;
373 ::std::unique_ptr<DigitalInput> calibration_hall_;
374 ::std::unique_ptr<DigitalInput> back_hall_;
Brian Silverman552350b2015-08-02 18:23:34 -0700375
376 const bool reversed_;
377 };
378
Brian Silvermanb601d892015-12-20 18:24:38 -0500379 void CopyShooterPosedgeCounts(
380 const ::frc971::wpilib::DMAEdgeCounter *counter,
381 ::frc971::PosedgeOnlyCountedHallEffectStruct *output) {
Austin Schuh5c25ab72015-11-01 13:17:11 -0800382 output->current = !counter->polled_value();
Brian Silverman85fbb602015-08-29 19:28:20 -0700383 // These are inverted because the hall effects give logical false when
384 // there's a magnet in front of them.
385 output->posedge_count = counter->negative_count();
386 output->negedge_count = counter->positive_count();
Brian Silverman552350b2015-08-02 18:23:34 -0700387 output->posedge_value =
Brian Silverman85fbb602015-08-29 19:28:20 -0700388 shooter_translate(counter->last_negative_encoder_value());
Brian Silverman552350b2015-08-02 18:23:34 -0700389 }
390
Brian Silverman552350b2015-08-02 18:23:34 -0700391 ::std::unique_ptr<AnalogInput> auto_selector_analog_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700392
Brian Silverman552350b2015-08-02 18:23:34 -0700393 ::std::unique_ptr<AnalogInput> low_left_drive_hall_;
394 ::std::unique_ptr<AnalogInput> high_left_drive_hall_;
395 ::std::unique_ptr<AnalogInput> low_right_drive_hall_;
396 ::std::unique_ptr<AnalogInput> high_right_drive_hall_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700397
Brian Silverman552350b2015-08-02 18:23:34 -0700398 HalfClawReader top_reader_{false}, bottom_reader_{true};
399
400 ::std::unique_ptr<Encoder> shooter_encoder_;
Austin Schuhc5e36082015-10-31 13:30:46 -0700401 ::std::unique_ptr<DigitalInput> shooter_proximal_, shooter_distal_;
402 ::std::unique_ptr<DigitalInput> shooter_plunger_, shooter_latch_;
Brian Silvermanb601d892015-12-20 18:24:38 -0500403 ::std::unique_ptr<::frc971::wpilib::DMAEdgeCounter> shooter_proximal_counter_,
Brian Silverman552350b2015-08-02 18:23:34 -0700404 shooter_distal_counter_;
Brian Silvermanb601d892015-12-20 18:24:38 -0500405 ::std::unique_ptr<::frc971::wpilib::DMADigitalReader> shooter_plunger_reader_,
Brian Silverman552350b2015-08-02 18:23:34 -0700406 shooter_latch_reader_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700407
Austin Schuh2c2cc2e2019-02-02 20:19:45 -0800408 DigitalGlitchFilter hall_filter_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700409};
410
411class SolenoidWriter {
412 public:
Brian Silvermanb601d892015-12-20 18:24:38 -0500413 SolenoidWriter(const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
Brian Silverman17f503e2015-08-02 18:17:18 -0700414 : pcm_(pcm),
Brian Silvermanc75c1ad2015-12-30 16:21:13 -0800415 shooter_(".y2014.control_loops.shooter_queue.output"),
Comran Morshed5323ecb2015-12-26 20:50:55 +0000416 drivetrain_(".frc971.control_loops.drivetrain_queue.output") {}
Brian Silverman17f503e2015-08-02 18:17:18 -0700417
Austin Schuhc5e36082015-10-31 13:30:46 -0700418 void set_pressure_switch(::std::unique_ptr<DigitalInput> pressure_switch) {
Brian Silverman17f503e2015-08-02 18:17:18 -0700419 pressure_switch_ = ::std::move(pressure_switch);
420 }
421
422 void set_compressor_relay(::std::unique_ptr<Relay> compressor_relay) {
423 compressor_relay_ = ::std::move(compressor_relay);
424 }
425
Brian Silvermanb601d892015-12-20 18:24:38 -0500426 void set_drivetrain_left(
427 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Brian Silverman552350b2015-08-02 18:23:34 -0700428 drivetrain_left_ = ::std::move(s);
Brian Silverman17f503e2015-08-02 18:17:18 -0700429 }
430
Brian Silvermanb601d892015-12-20 18:24:38 -0500431 void set_drivetrain_right(
432 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Brian Silverman552350b2015-08-02 18:23:34 -0700433 drivetrain_right_ = ::std::move(s);
Brian Silverman17f503e2015-08-02 18:17:18 -0700434 }
435
Brian Silvermanb601d892015-12-20 18:24:38 -0500436 void set_shooter_latch(
437 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Brian Silverman552350b2015-08-02 18:23:34 -0700438 shooter_latch_ = ::std::move(s);
Brian Silverman17f503e2015-08-02 18:17:18 -0700439 }
440
Brian Silvermanb601d892015-12-20 18:24:38 -0500441 void set_shooter_brake(
442 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Brian Silverman552350b2015-08-02 18:23:34 -0700443 shooter_brake_ = ::std::move(s);
Brian Silverman17f503e2015-08-02 18:17:18 -0700444 }
445
446 void operator()() {
447 ::aos::SetCurrentThreadName("Solenoids");
Brian Silverman5090c432016-01-02 14:44:26 -0800448 ::aos::SetCurrentThreadRealtimePriority(27);
449
Austin Schuh8aec1ed2016-05-01 13:29:20 -0700450 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(20),
451 ::std::chrono::milliseconds(1));
Brian Silverman17f503e2015-08-02 18:17:18 -0700452
453 while (run_) {
Brian Silverman5090c432016-01-02 14:44:26 -0800454 {
455 const int iterations = phased_loop.SleepUntilNext();
456 if (iterations != 1) {
457 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
458 }
459 }
Brian Silverman17f503e2015-08-02 18:17:18 -0700460
461 {
Brian Silverman552350b2015-08-02 18:23:34 -0700462 shooter_.FetchLatest();
463 if (shooter_.get()) {
464 LOG_STRUCT(DEBUG, "solenoids", *shooter_);
465 shooter_latch_->Set(!shooter_->latch_piston);
466 shooter_brake_->Set(!shooter_->brake_piston);
Brian Silverman17f503e2015-08-02 18:17:18 -0700467 }
468 }
469
470 {
Brian Silverman552350b2015-08-02 18:23:34 -0700471 drivetrain_.FetchLatest();
472 if (drivetrain_.get()) {
473 LOG_STRUCT(DEBUG, "solenoids", *drivetrain_);
Austin Schuh86f895e2015-11-08 13:40:51 -0800474 drivetrain_left_->Set(!drivetrain_->left_high);
475 drivetrain_right_->Set(!drivetrain_->right_high);
Brian Silverman17f503e2015-08-02 18:17:18 -0700476 }
477 }
478
Brian Silverman17f503e2015-08-02 18:17:18 -0700479 {
Brian Silvermanb601d892015-12-20 18:24:38 -0500480 ::frc971::wpilib::PneumaticsToLog to_log;
Brian Silverman17f503e2015-08-02 18:17:18 -0700481 {
482 const bool compressor_on = !pressure_switch_->Get();
483 to_log.compressor_on = compressor_on;
484 if (compressor_on) {
485 compressor_relay_->Set(Relay::kForward);
486 } else {
487 compressor_relay_->Set(Relay::kOff);
488 }
489 }
490
491 pcm_->Flush();
492 to_log.read_solenoids = pcm_->GetAll();
493 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
494 }
495 }
496 }
497
498 void Quit() { run_ = false; }
499
500 private:
Brian Silvermanb601d892015-12-20 18:24:38 -0500501 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
Brian Silverman552350b2015-08-02 18:23:34 -0700502
Brian Silvermanb601d892015-12-20 18:24:38 -0500503 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_left_;
504 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_right_;
505 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> shooter_latch_;
506 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> shooter_brake_;
Brian Silverman552350b2015-08-02 18:23:34 -0700507
Austin Schuhc5e36082015-10-31 13:30:46 -0700508 ::std::unique_ptr<DigitalInput> pressure_switch_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700509 ::std::unique_ptr<Relay> compressor_relay_;
510
Brian Silvermanb601d892015-12-20 18:24:38 -0500511 ::aos::Queue<::y2014::control_loops::ShooterQueue::Output> shooter_;
Comran Morshed5323ecb2015-12-26 20:50:55 +0000512 ::aos::Queue<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700513
514 ::std::atomic<bool> run_{true};
515};
516
Brian Silvermanb601d892015-12-20 18:24:38 -0500517class ShooterWriter : public ::frc971::wpilib::LoopOutputHandler {
Brian Silverman17f503e2015-08-02 18:17:18 -0700518 public:
Brian Silverman552350b2015-08-02 18:23:34 -0700519 void set_shooter_talon(::std::unique_ptr<Talon> t) {
520 shooter_talon_ = ::std::move(t);
Brian Silverman17f503e2015-08-02 18:17:18 -0700521 }
522
523 private:
524 virtual void Read() override {
Brian Silvermanb601d892015-12-20 18:24:38 -0500525 ::y2014::control_loops::shooter_queue.output.FetchAnother();
Brian Silverman17f503e2015-08-02 18:17:18 -0700526 }
527
528 virtual void Write() override {
Brian Silvermanb601d892015-12-20 18:24:38 -0500529 auto &queue = ::y2014::control_loops::shooter_queue.output;
Brian Silverman17f503e2015-08-02 18:17:18 -0700530 LOG_STRUCT(DEBUG, "will output", *queue);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800531 shooter_talon_->SetSpeed(queue->voltage / 12.0);
Brian Silverman17f503e2015-08-02 18:17:18 -0700532 }
533
534 virtual void Stop() override {
Brian Silverman552350b2015-08-02 18:23:34 -0700535 LOG(WARNING, "shooter output too old\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800536 shooter_talon_->SetDisabled();
Brian Silverman17f503e2015-08-02 18:17:18 -0700537 }
538
Brian Silverman552350b2015-08-02 18:23:34 -0700539 ::std::unique_ptr<Talon> shooter_talon_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700540};
541
Brian Silvermanb601d892015-12-20 18:24:38 -0500542class ClawWriter : public ::frc971::wpilib::LoopOutputHandler {
Brian Silverman17f503e2015-08-02 18:17:18 -0700543 public:
Brian Silverman552350b2015-08-02 18:23:34 -0700544 void set_top_claw_talon(::std::unique_ptr<Talon> t) {
545 top_claw_talon_ = ::std::move(t);
Brian Silverman17f503e2015-08-02 18:17:18 -0700546 }
547
Brian Silverman552350b2015-08-02 18:23:34 -0700548 void set_bottom_claw_talon(::std::unique_ptr<Talon> t) {
549 bottom_claw_talon_ = ::std::move(t);
Brian Silverman17f503e2015-08-02 18:17:18 -0700550 }
551
Brian Silverman552350b2015-08-02 18:23:34 -0700552 void set_left_tusk_talon(::std::unique_ptr<Talon> t) {
553 left_tusk_talon_ = ::std::move(t);
554 }
555
556 void set_right_tusk_talon(::std::unique_ptr<Talon> t) {
557 right_tusk_talon_ = ::std::move(t);
558 }
559
560 void set_intake1_talon(::std::unique_ptr<Talon> t) {
561 intake1_talon_ = ::std::move(t);
562 }
563
564 void set_intake2_talon(::std::unique_ptr<Talon> t) {
565 intake2_talon_ = ::std::move(t);
Brian Silverman17f503e2015-08-02 18:17:18 -0700566 }
567
568 private:
569 virtual void Read() override {
Brian Silvermanb601d892015-12-20 18:24:38 -0500570 ::y2014::control_loops::claw_queue.output.FetchAnother();
Brian Silverman17f503e2015-08-02 18:17:18 -0700571 }
572
573 virtual void Write() override {
Brian Silvermanb601d892015-12-20 18:24:38 -0500574 auto &queue = ::y2014::control_loops::claw_queue.output;
Brian Silverman17f503e2015-08-02 18:17:18 -0700575 LOG_STRUCT(DEBUG, "will output", *queue);
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800576 intake1_talon_->SetSpeed(queue->intake_voltage / 12.0);
577 intake2_talon_->SetSpeed(queue->intake_voltage / 12.0);
578 bottom_claw_talon_->SetSpeed(-queue->bottom_claw_voltage / 12.0);
579 top_claw_talon_->SetSpeed(queue->top_claw_voltage / 12.0);
580 left_tusk_talon_->SetSpeed(queue->tusk_voltage / 12.0);
581 right_tusk_talon_->SetSpeed(-queue->tusk_voltage / 12.0);
Brian Silverman17f503e2015-08-02 18:17:18 -0700582 }
583
584 virtual void Stop() override {
Brian Silverman552350b2015-08-02 18:23:34 -0700585 LOG(WARNING, "claw output too old\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800586 intake1_talon_->SetDisabled();
587 intake2_talon_->SetDisabled();
588 bottom_claw_talon_->SetDisabled();
589 top_claw_talon_->SetDisabled();
590 left_tusk_talon_->SetDisabled();
591 right_tusk_talon_->SetDisabled();
Brian Silverman17f503e2015-08-02 18:17:18 -0700592 }
593
Brian Silverman552350b2015-08-02 18:23:34 -0700594 ::std::unique_ptr<Talon> top_claw_talon_;
595 ::std::unique_ptr<Talon> bottom_claw_talon_;
596 ::std::unique_ptr<Talon> left_tusk_talon_;
597 ::std::unique_ptr<Talon> right_tusk_talon_;
598 ::std::unique_ptr<Talon> intake1_talon_;
599 ::std::unique_ptr<Talon> intake2_talon_;
Brian Silverman17f503e2015-08-02 18:17:18 -0700600};
601
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800602class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
Brian Silverman17f503e2015-08-02 18:17:18 -0700603 public:
Brian Silverman552350b2015-08-02 18:23:34 -0700604 ::std::unique_ptr<Encoder> make_encoder(int index) {
Brian Silverman17f503e2015-08-02 18:17:18 -0700605 return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false,
606 Encoder::k4X);
607 }
Brian Silverman552350b2015-08-02 18:23:34 -0700608
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800609 void Run() override {
Brian Silverman17f503e2015-08-02 18:17:18 -0700610 ::aos::InitNRT();
611 ::aos::SetCurrentThreadName("StartCompetition");
612
Brian Silvermanb601d892015-12-20 18:24:38 -0500613 ::frc971::wpilib::JoystickSender joystick_sender;
Brian Silverman17f503e2015-08-02 18:17:18 -0700614 ::std::thread joystick_thread(::std::ref(joystick_sender));
Brian Silverman17f503e2015-08-02 18:17:18 -0700615
Brian Silverman425492b2015-12-30 15:23:55 -0800616 ::frc971::wpilib::PDPFetcher pdp_fetcher;
617 ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
Brian Silverman39b339e2016-01-03 13:24:22 -0800618 SensorReader reader;
Brian Silverman17f503e2015-08-02 18:17:18 -0700619
Brian Silverman85fbb602015-08-29 19:28:20 -0700620 // Create this first to make sure it ends up in one of the lower-numbered
621 // FPGA slots so we can use it with DMA.
622 auto shooter_encoder_temp = make_encoder(2);
623
Brian Silverman552350b2015-08-02 18:23:34 -0700624 reader.set_auto_selector_analog(make_unique<AnalogInput>(4));
Brian Silverman17f503e2015-08-02 18:17:18 -0700625
Brian Silverman552350b2015-08-02 18:23:34 -0700626 reader.set_drivetrain_left_encoder(make_encoder(0));
627 reader.set_drivetrain_right_encoder(make_encoder(1));
628 reader.set_high_left_drive_hall(make_unique<AnalogInput>(1));
629 reader.set_low_left_drive_hall(make_unique<AnalogInput>(0));
630 reader.set_high_right_drive_hall(make_unique<AnalogInput>(2));
631 reader.set_low_right_drive_hall(make_unique<AnalogInput>(3));
Brian Silverman17f503e2015-08-02 18:17:18 -0700632
Brian Silverman552350b2015-08-02 18:23:34 -0700633 reader.set_top_claw_encoder(make_encoder(3));
Austin Schuh5c25ab72015-11-01 13:17:11 -0800634 reader.set_top_claw_front_hall(make_unique<DigitalInput>(4)); // R2
635 reader.set_top_claw_calibration_hall(make_unique<DigitalInput>(3)); // R3
636 reader.set_top_claw_back_hall(make_unique<DigitalInput>(5)); // R1
Brian Silverman17f503e2015-08-02 18:17:18 -0700637
Brian Silverman85fbb602015-08-29 19:28:20 -0700638 reader.set_bottom_claw_encoder(make_encoder(4));
Austin Schuh5c25ab72015-11-01 13:17:11 -0800639 reader.set_bottom_claw_front_hall(make_unique<DigitalInput>(1)); // L2
640 reader.set_bottom_claw_calibration_hall(make_unique<DigitalInput>(0)); // L3
641 reader.set_bottom_claw_back_hall(make_unique<DigitalInput>(2)); // L1
Brian Silverman17f503e2015-08-02 18:17:18 -0700642
Brian Silverman85fbb602015-08-29 19:28:20 -0700643 reader.set_shooter_encoder(::std::move(shooter_encoder_temp));
Austin Schuh5c25ab72015-11-01 13:17:11 -0800644 reader.set_shooter_proximal(make_unique<DigitalInput>(6)); // S1
645 reader.set_shooter_distal(make_unique<DigitalInput>(7)); // S2
646 reader.set_shooter_plunger(make_unique<DigitalInput>(8)); // S3
647 reader.set_shooter_latch(make_unique<DigitalInput>(9)); // S4
Brian Silverman552350b2015-08-02 18:23:34 -0700648
Brian Silverman17f503e2015-08-02 18:17:18 -0700649 reader.set_dma(make_unique<DMA>());
650 ::std::thread reader_thread(::std::ref(reader));
Brian Silverman552350b2015-08-02 18:23:34 -0700651
Brian Silvermanb601d892015-12-20 18:24:38 -0500652 ::frc971::wpilib::GyroSender gyro_sender;
Brian Silverman17f503e2015-08-02 18:17:18 -0700653 ::std::thread gyro_thread(::std::ref(gyro_sender));
654
Sabina Davis05f580f2019-02-03 01:17:35 -0800655 ::frc971::wpilib::DrivetrainWriter drivetrain_writer;
656 drivetrain_writer.set_left_controller0(
657 ::std::unique_ptr<Talon>(new Talon(5)), true);
658 drivetrain_writer.set_right_controller0(
659 ::std::unique_ptr<Talon>(new Talon(2)), false);
Brian Silverman17f503e2015-08-02 18:17:18 -0700660 ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
661
Brian Silvermanb601d892015-12-20 18:24:38 -0500662 ::y2014::wpilib::ClawWriter claw_writer;
Brian Silverman552350b2015-08-02 18:23:34 -0700663 claw_writer.set_top_claw_talon(::std::unique_ptr<Talon>(new Talon(1)));
664 claw_writer.set_bottom_claw_talon(::std::unique_ptr<Talon>(new Talon(0)));
665 claw_writer.set_left_tusk_talon(::std::unique_ptr<Talon>(new Talon(4)));
666 claw_writer.set_right_tusk_talon(::std::unique_ptr<Talon>(new Talon(3)));
667 claw_writer.set_intake1_talon(::std::unique_ptr<Talon>(new Talon(7)));
668 claw_writer.set_intake2_talon(::std::unique_ptr<Talon>(new Talon(8)));
Brian Silverman17f503e2015-08-02 18:17:18 -0700669 ::std::thread claw_writer_thread(::std::ref(claw_writer));
670
Brian Silvermanb601d892015-12-20 18:24:38 -0500671 ::y2014::wpilib::ShooterWriter shooter_writer;
Brian Silverman552350b2015-08-02 18:23:34 -0700672 shooter_writer.set_shooter_talon(::std::unique_ptr<Talon>(new Talon(6)));
673 ::std::thread shooter_writer_thread(::std::ref(shooter_writer));
674
Brian Silverman17f503e2015-08-02 18:17:18 -0700675 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
676 new ::frc971::wpilib::BufferedPcm());
677 SolenoidWriter solenoid_writer(pcm);
Brian Silverman552350b2015-08-02 18:23:34 -0700678 solenoid_writer.set_drivetrain_left(pcm->MakeSolenoid(6));
679 solenoid_writer.set_drivetrain_right(pcm->MakeSolenoid(7));
680 solenoid_writer.set_shooter_latch(pcm->MakeSolenoid(5));
681 solenoid_writer.set_shooter_brake(pcm->MakeSolenoid(4));
Brian Silverman17f503e2015-08-02 18:17:18 -0700682
Austin Schuh016a6b02015-10-08 06:41:14 +0000683 solenoid_writer.set_pressure_switch(make_unique<DigitalInput>(25));
Brian Silverman17f503e2015-08-02 18:17:18 -0700684 solenoid_writer.set_compressor_relay(make_unique<Relay>(0));
685 ::std::thread solenoid_thread(::std::ref(solenoid_writer));
686
687 // Wait forever. Not much else to do...
Brian Silverman5090c432016-01-02 14:44:26 -0800688 while (true) {
689 const int r = select(0, nullptr, nullptr, nullptr, nullptr);
690 if (r != 0) {
691 PLOG(WARNING, "infinite select failed");
692 } else {
693 PLOG(WARNING, "infinite select succeeded??\n");
694 }
695 }
Brian Silverman17f503e2015-08-02 18:17:18 -0700696
697 LOG(ERROR, "Exiting WPILibRobot\n");
698
699 joystick_sender.Quit();
700 joystick_thread.join();
Brian Silverman425492b2015-12-30 15:23:55 -0800701 pdp_fetcher.Quit();
702 pdp_fetcher_thread.join();
Brian Silverman17f503e2015-08-02 18:17:18 -0700703 reader.Quit();
704 reader_thread.join();
705 gyro_sender.Quit();
706 gyro_thread.join();
707
708 drivetrain_writer.Quit();
709 drivetrain_writer_thread.join();
Brian Silverman552350b2015-08-02 18:23:34 -0700710 shooter_writer.Quit();
711 shooter_writer_thread.join();
712 claw_writer.Quit();
713 claw_writer_thread.join();
Brian Silverman17f503e2015-08-02 18:17:18 -0700714 solenoid_writer.Quit();
715 solenoid_thread.join();
716
717 ::aos::Cleanup();
718 }
719};
720
721} // namespace wpilib
Brian Silvermanb601d892015-12-20 18:24:38 -0500722} // namespace y2014
Brian Silverman17f503e2015-08-02 18:17:18 -0700723
724
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800725AOS_ROBOT_CLASS(::y2014::wpilib::WPILibRobot);