blob: 339a3886acafa4b95c515fba2043e6ea6260df17 [file] [log] [blame]
Sabina Davisabeae332019-02-01 21:12:57 -08001#include <inttypes.h>
2#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
5
6#include <array>
7#include <chrono>
8#include <cmath>
9#include <functional>
10#include <mutex>
11#include <thread>
12
13#include "frc971/wpilib/ahal/AnalogInput.h"
14#include "frc971/wpilib/ahal/Counter.h"
15#include "frc971/wpilib/ahal/DigitalGlitchFilter.h"
16#include "frc971/wpilib/ahal/DriverStation.h"
17#include "frc971/wpilib/ahal/Encoder.h"
18#include "frc971/wpilib/ahal/VictorSP.h"
19#undef ERROR
20
21#include "aos/commonmath.h"
22#include "aos/init.h"
23#include "aos/logging/logging.h"
24#include "aos/logging/queue_logging.h"
25#include "aos/make_unique.h"
Sabina Davisabeae332019-02-01 21:12:57 -080026#include "aos/time/time.h"
Sabina Davisabeae332019-02-01 21:12:57 -080027#include "aos/util/log_interval.h"
28#include "aos/util/phased_loop.h"
29#include "aos/util/wrapping_counter.h"
30
31#include "frc971/autonomous/auto.q.h"
32#include "frc971/control_loops/drivetrain/drivetrain.q.h"
33#include "frc971/wpilib/ADIS16448.h"
Austin Schuhc1d6f832019-02-15 23:22:17 -080034#include "frc971/wpilib/buffered_pcm.h"
35#include "frc971/wpilib/buffered_solenoid.h"
Sabina Davisabeae332019-02-01 21:12:57 -080036#include "frc971/wpilib/dma.h"
Sabina Davisd004fd62019-02-02 23:51:46 -080037#include "frc971/wpilib/drivetrain_writer.h"
Sabina Davisabeae332019-02-01 21:12:57 -080038#include "frc971/wpilib/encoder_and_potentiometer.h"
Sabina Davisabeae332019-02-01 21:12:57 -080039#include "frc971/wpilib/joystick_sender.h"
40#include "frc971/wpilib/logging.q.h"
41#include "frc971/wpilib/loop_output_handler.h"
42#include "frc971/wpilib/pdp_fetcher.h"
Sabina Davisadc58542019-02-01 22:23:00 -080043#include "frc971/wpilib/sensor_reader.h"
Sabina Davisabeae332019-02-01 21:12:57 -080044#include "frc971/wpilib/wpilib_robot_base.h"
Austin Schuhc1d6f832019-02-15 23:22:17 -080045#include "third_party/Phoenix-frc-lib/cpp/include/ctre/phoenix/MotorControl/CAN/TalonSRX.h"
Sabina Davis7be49f32019-02-02 00:30:19 -080046#include "y2019/constants.h"
Alex Perry5fb5ff22019-02-09 21:53:17 -080047#include "y2019/control_loops/superstructure/superstructure.q.h"
Sabina Davisabeae332019-02-01 21:12:57 -080048
49#ifndef M_PI
50#define M_PI 3.14159265358979323846
51#endif
52
53using ::frc971::control_loops::drivetrain_queue;
Alex Perry5fb5ff22019-02-09 21:53:17 -080054using ::y2019::control_loops::superstructure::superstructure_queue;
Sabina Davis7be49f32019-02-02 00:30:19 -080055using ::y2019::constants::Values;
Sabina Davisabeae332019-02-01 21:12:57 -080056using ::aos::monotonic_clock;
57namespace chrono = ::std::chrono;
58using aos::make_unique;
59
60namespace y2019 {
61namespace wpilib {
62namespace {
63
64constexpr double kMaxBringupPower = 12.0;
65
66// TODO(Brian): Fix the interpretation of the result of GetRaw here and in the
67// DMA stuff and then removing the * 2.0 in *_translate.
68// The low bit is direction.
69
70// TODO(brian): Use ::std::max instead once we have C++14 so that can be
71// constexpr.
72template <typename T>
73constexpr T max(T a, T b) {
74 return (a > b) ? a : b;
75}
76
77template <typename T, typename... Rest>
78constexpr T max(T a, T b, T c, Rest... rest) {
79 return max(max(a, b), c, rest...);
80}
81
82double drivetrain_translate(int32_t in) {
Sabina Davis7be49f32019-02-02 00:30:19 -080083 return ((static_cast<double>(in) /
84 Values::kDrivetrainEncoderCountsPerRevolution()) *
Sabina Davisabeae332019-02-01 21:12:57 -080085 (2.0 * M_PI)) *
86 Values::kDrivetrainEncoderRatio() *
Sabina Davis7be49f32019-02-02 00:30:19 -080087 control_loops::drivetrain::kWheelRadius;
Sabina Davisabeae332019-02-01 21:12:57 -080088}
89
90double drivetrain_velocity_translate(double in) {
Sabina Davis7be49f32019-02-02 00:30:19 -080091 return (((1.0 / in) / Values::kDrivetrainCyclesPerRevolution()) *
Sabina Davisabeae332019-02-01 21:12:57 -080092 (2.0 * M_PI)) *
93 Values::kDrivetrainEncoderRatio() *
Sabina Davis7be49f32019-02-02 00:30:19 -080094 control_loops::drivetrain::kWheelRadius;
Sabina Davisabeae332019-02-01 21:12:57 -080095}
96
Alex Perry5fb5ff22019-02-09 21:53:17 -080097double elevator_pot_translate(double voltage) {
98 return voltage * Values::kElevatorPotRatio() *
Austin Schuhed7f8632019-02-15 23:12:20 -080099 (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Alex Perry5fb5ff22019-02-09 21:53:17 -0800100}
101
102double wrist_pot_translate(double voltage) {
Austin Schuhed7f8632019-02-15 23:12:20 -0800103 return voltage * Values::kWristPotRatio() * (5.0 /*turns*/ / 5.0 /*volts*/) *
Alex Perry5fb5ff22019-02-09 21:53:17 -0800104 (2 * M_PI /*radians*/);
105}
106
107double stilts_pot_translate(double voltage) {
108 return voltage * Values::kStiltsPotRatio() *
109 (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
110}
111
Sabina Davisabeae332019-02-01 21:12:57 -0800112constexpr double kMaxFastEncoderPulsesPerSecond =
Alex Perry5fb5ff22019-02-09 21:53:17 -0800113 max(Values::kMaxDrivetrainEncoderPulsesPerSecond(),
114 Values::kMaxIntakeEncoderPulsesPerSecond());
Sabina Davisabeae332019-02-01 21:12:57 -0800115static_assert(kMaxFastEncoderPulsesPerSecond <= 1300000,
116 "fast encoders are too fast");
Sabina Davisabeae332019-02-01 21:12:57 -0800117constexpr double kMaxMediumEncoderPulsesPerSecond =
Alex Perry5fb5ff22019-02-09 21:53:17 -0800118 max(Values::kMaxElevatorEncoderPulsesPerSecond(),
119 Values::kMaxWristEncoderPulsesPerSecond());
Theo Bafrali00e42272019-02-12 01:07:46 -0800120
Sabina Davisabeae332019-02-01 21:12:57 -0800121static_assert(kMaxMediumEncoderPulsesPerSecond <= 400000,
122 "medium encoders are too fast");
123
124// Class to send position messages with sensor readings to our loops.
Sabina Davisadc58542019-02-01 22:23:00 -0800125class SensorReader : public ::frc971::wpilib::SensorReader {
Sabina Davisabeae332019-02-01 21:12:57 -0800126 public:
127 SensorReader() {
128 // Set to filter out anything shorter than 1/4 of the minimum pulse width
129 // we should ever see.
Austin Schuh45a549f2019-02-02 15:43:56 -0800130 UpdateFastEncoderFilterHz(kMaxFastEncoderPulsesPerSecond);
131 UpdateMediumEncoderFilterHz(kMaxMediumEncoderPulsesPerSecond);
Sabina Davisabeae332019-02-01 21:12:57 -0800132 }
133
Alex Perry5fb5ff22019-02-09 21:53:17 -0800134 // Elevator
135
136 void set_elevator_encoder(::std::unique_ptr<frc::Encoder> encoder) {
137 medium_encoder_filter_.Add(encoder.get());
138 elevator_encoder_.set_encoder(::std::move(encoder));
139 }
140
141 void set_elevator_absolute_pwm(
142 ::std::unique_ptr<frc::DigitalInput> absolute_pwm) {
143 elevator_encoder_.set_absolute_pwm(::std::move(absolute_pwm));
144 }
145
146 void set_elevator_potentiometer(
147 ::std::unique_ptr<frc::AnalogInput> potentiometer) {
148 elevator_encoder_.set_potentiometer(::std::move(potentiometer));
149 }
150
151 // Intake
152
153 void set_intake_encoder(::std::unique_ptr<frc::Encoder> encoder) {
154 medium_encoder_filter_.Add(encoder.get());
155 intake_encoder_.set_encoder(::std::move(encoder));
156 }
157
158 void set_intake_absolute_pwm(
159 ::std::unique_ptr<frc::DigitalInput> absolute_pwm) {
160 intake_encoder_.set_absolute_pwm(::std::move(absolute_pwm));
161 }
162
163 // Wrist
164
165 void set_wrist_encoder(::std::unique_ptr<frc::Encoder> encoder) {
166 medium_encoder_filter_.Add(encoder.get());
167 wrist_encoder_.set_encoder(::std::move(encoder));
168 }
169
170 void set_wrist_absolute_pwm(
171 ::std::unique_ptr<frc::DigitalInput> absolute_pwm) {
172 wrist_encoder_.set_absolute_pwm(::std::move(absolute_pwm));
173 }
174
175 void set_wrist_potentiometer(
176 ::std::unique_ptr<frc::AnalogInput> potentiometer) {
177 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
178 }
179
180 // Stilts
181
182 void set_stilts_encoder(::std::unique_ptr<frc::Encoder> encoder) {
183 medium_encoder_filter_.Add(encoder.get());
184 stilts_encoder_.set_encoder(::std::move(encoder));
185 }
186
187 void set_stilts_absolute_pwm(
188 ::std::unique_ptr<frc::DigitalInput> absolute_pwm) {
189 stilts_encoder_.set_absolute_pwm(::std::move(absolute_pwm));
190 }
191
192 void set_stilts_potentiometer(
193 ::std::unique_ptr<frc::AnalogInput> potentiometer) {
194 stilts_encoder_.set_potentiometer(::std::move(potentiometer));
195 }
196
Sabina Davis399dbd82019-02-01 23:06:08 -0800197 void RunIteration() override {
Sabina Davisabeae332019-02-01 21:12:57 -0800198 {
199 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
200 drivetrain_message->left_encoder =
201 drivetrain_translate(drivetrain_left_encoder_->GetRaw());
202 drivetrain_message->left_speed =
203 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
204
205 drivetrain_message->right_encoder =
206 -drivetrain_translate(drivetrain_right_encoder_->GetRaw());
207 drivetrain_message->right_speed = -drivetrain_velocity_translate(
208 drivetrain_right_encoder_->GetPeriod());
209
210 drivetrain_message.Send();
211 }
Alex Perry5fb5ff22019-02-09 21:53:17 -0800212 const auto values = constants::GetValues();
213
214 {
215 auto superstructure_message = superstructure_queue.position.MakeMessage();
216
217 // Elevator
218 CopyPosition(elevator_encoder_, &superstructure_message->elevator,
219 Values::kElevatorEncoderCountsPerRevolution(),
220 Values::kElevatorEncoderRatio(), elevator_pot_translate,
221 false, values.elevator.potentiometer_offset);
222 // Intake
223 CopyPosition(intake_encoder_, &superstructure_message->intake_joint,
224 Values::kIntakeEncoderCountsPerRevolution(),
225 Values::kIntakeEncoderRatio(), false);
226
227 // Wrist
228 CopyPosition(wrist_encoder_, &superstructure_message->wrist,
229 Values::kWristEncoderCountsPerRevolution(),
230 Values::kWristEncoderRatio(), wrist_pot_translate, false,
231 values.wrist.potentiometer_offset);
232
233 // Stilts
234 CopyPosition(stilts_encoder_, &superstructure_message->stilts,
235 Values::kStiltsEncoderCountsPerRevolution(),
236 Values::kStiltsEncoderRatio(), stilts_pot_translate, false,
237 values.stilts.potentiometer_offset);
238
239 superstructure_message.Send();
240 }
241 }
242
243 private:
244 ::frc971::wpilib::AbsoluteEncoderAndPotentiometer elevator_encoder_,
245 wrist_encoder_, stilts_encoder_;
246
247 ::frc971::wpilib::AbsoluteEncoder intake_encoder_;
248 // TODO(sabina): Add wrist and elevator hall effects.
249};
250
251class SuperstructureWriter : public ::frc971::wpilib::LoopOutputHandler {
252 public:
253 void set_elevator_victor(::std::unique_ptr<::frc::VictorSP> t) {
254 elevator_victor_ = ::std::move(t);
255 }
256
257 void set_intake_victor(::std::unique_ptr<::frc::VictorSP> t) {
258 intake_victor_ = ::std::move(t);
259 }
Alex Perry5fb5ff22019-02-09 21:53:17 -0800260
261 void set_wrist_victor(::std::unique_ptr<::frc::VictorSP> t) {
262 wrist_victor_ = ::std::move(t);
263 }
264
265 void set_stilts_victor(::std::unique_ptr<::frc::VictorSP> t) {
266 stilts_victor_ = ::std::move(t);
267 }
268
269 private:
270 virtual void Read() override {
271 ::y2019::control_loops::superstructure::superstructure_queue.output
272 .FetchAnother();
273 }
274
275 virtual void Write() override {
276 auto &queue =
277 ::y2019::control_loops::superstructure::superstructure_queue.output;
278 LOG_STRUCT(DEBUG, "will output", *queue);
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800279 elevator_victor_->SetSpeed(::aos::Clip(queue->elevator_voltage,
Alex Perry5fb5ff22019-02-09 21:53:17 -0800280 -kMaxBringupPower,
281 kMaxBringupPower) /
282 12.0);
283
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800284 intake_victor_->SetSpeed(::aos::Clip(queue->intake_joint_voltage,
Alex Perry5fb5ff22019-02-09 21:53:17 -0800285 -kMaxBringupPower, kMaxBringupPower) /
286 12.0);
287
Alex Perry5fb5ff22019-02-09 21:53:17 -0800288 wrist_victor_->SetSpeed(::aos::Clip(-queue->wrist_voltage,
289 -kMaxBringupPower, kMaxBringupPower) /
290 12.0);
291
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800292 stilts_victor_->SetSpeed(::aos::Clip(queue->stilts_voltage,
Alex Perry5fb5ff22019-02-09 21:53:17 -0800293 -kMaxBringupPower, kMaxBringupPower) /
294 12.0);
295 }
296
297 virtual void Stop() override {
298 LOG(WARNING, "Superstructure output too old.\n");
299
300 elevator_victor_->SetDisabled();
301 intake_victor_->SetDisabled();
Alex Perry5fb5ff22019-02-09 21:53:17 -0800302 wrist_victor_->SetDisabled();
303 stilts_victor_->SetDisabled();
304 }
305
306 ::std::unique_ptr<::frc::VictorSP> elevator_victor_, intake_victor_,
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800307 wrist_victor_, stilts_victor_;
Sabina Davisabeae332019-02-01 21:12:57 -0800308};
309
Austin Schuhc1d6f832019-02-15 23:22:17 -0800310class SolenoidWriter {
311 public:
312 SolenoidWriter()
313 : superstructure_(
314 ".y2019.control_loops.superstructure.superstructure_queue.output") {
315 }
316
317 void set_big_suction_cup(int index) {
318 big_suction_cup_ = pcm_.MakeSolenoid(index);
319 }
320 void set_small_suction_cup(int index) {
321 small_suction_cup_ = pcm_.MakeSolenoid(index);
322 }
323
324 void set_intake_roller_talon(
325 ::std::unique_ptr<::ctre::phoenix::motorcontrol::can::TalonSRX> t) {
326 intake_rollers_talon_ = ::std::move(t);
327 intake_rollers_talon_->ConfigContinuousCurrentLimit(40.0, 0);
328 intake_rollers_talon_->EnableCurrentLimit(true);
329 }
330
331 void operator()() {
332 ::aos::SetCurrentThreadName("Solenoids");
333 ::aos::SetCurrentThreadRealtimePriority(27);
334
335 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(20),
336 ::std::chrono::milliseconds(1));
337
338 while (run_) {
339 {
340 const int iterations = phased_loop.SleepUntilNext();
341 if (iterations != 1) {
342 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
343 }
344 }
345
346 {
347 superstructure_.FetchLatest();
348 if (superstructure_.get()) {
349 LOG_STRUCT(DEBUG, "solenoids", *superstructure_);
350
351 big_suction_cup_->Set(!superstructure_->intake_suction_top);
352 small_suction_cup_->Set(!superstructure_->intake_suction_bottom);
353
354 intake_rollers_talon_->Set(
355 ctre::phoenix::motorcontrol::ControlMode::PercentOutput,
356 ::aos::Clip(superstructure_->intake_roller_voltage,
357 -kMaxBringupPower, kMaxBringupPower) /
358 12.0);
359 }
360 }
361
362 {
363 ::frc971::wpilib::PneumaticsToLog to_log;
364
365 pcm_.Flush();
366 to_log.read_solenoids = pcm_.GetAll();
367 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
368 }
369 }
370 }
371
372 void Quit() { run_ = false; }
373
374 private:
375 ::frc971::wpilib::BufferedPcm pcm_;
376
377 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> big_suction_cup_,
378 small_suction_cup_;
379
380 ::std::unique_ptr<::ctre::phoenix::motorcontrol::can::TalonSRX>
381 intake_rollers_talon_;
382
383 ::aos::Queue<
384 ::y2019::control_loops::superstructure::SuperstructureQueue::Output>
385 superstructure_;
386
387 ::std::atomic<bool> run_{true};
388};
389
Sabina Davisabeae332019-02-01 21:12:57 -0800390class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
391 public:
392 ::std::unique_ptr<frc::Encoder> make_encoder(int index) {
393 return make_unique<frc::Encoder>(10 + index * 2, 11 + index * 2, false,
394 frc::Encoder::k4X);
395 }
396
397 void Run() override {
398 ::aos::InitNRT();
399 ::aos::SetCurrentThreadName("StartCompetition");
400
401 ::frc971::wpilib::JoystickSender joystick_sender;
402 ::std::thread joystick_thread(::std::ref(joystick_sender));
403
404 ::frc971::wpilib::PDPFetcher pdp_fetcher;
405 ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
406 SensorReader reader;
407
Sabina Davisabeae332019-02-01 21:12:57 -0800408 reader.set_drivetrain_left_encoder(make_encoder(0));
409 reader.set_drivetrain_right_encoder(make_encoder(1));
410
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800411 reader.set_elevator_encoder(make_encoder(4));
412 reader.set_elevator_absolute_pwm(make_unique<frc::DigitalInput>(4));
413 reader.set_elevator_potentiometer(make_unique<frc::AnalogInput>(4));
Alex Perry5fb5ff22019-02-09 21:53:17 -0800414
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800415 reader.set_wrist_encoder(make_encoder(5));
416 reader.set_wrist_absolute_pwm(make_unique<frc::DigitalInput>(5));
417 reader.set_wrist_potentiometer(make_unique<frc::AnalogInput>(5));
Alex Perry5fb5ff22019-02-09 21:53:17 -0800418
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800419 reader.set_intake_encoder(make_encoder(2));
420 reader.set_intake_absolute_pwm(make_unique<frc::DigitalInput>(2));
Alex Perry5fb5ff22019-02-09 21:53:17 -0800421
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800422 reader.set_stilts_encoder(make_encoder(3));
423 reader.set_stilts_absolute_pwm(make_unique<frc::DigitalInput>(3));
Alex Perry5fb5ff22019-02-09 21:53:17 -0800424 reader.set_stilts_potentiometer(make_unique<frc::AnalogInput>(3));
425
Sabina Davisabeae332019-02-01 21:12:57 -0800426 reader.set_pwm_trigger(make_unique<frc::DigitalInput>(25));
427
Sabina Davisabeae332019-02-01 21:12:57 -0800428 ::std::thread reader_thread(::std::ref(reader));
429
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800430 auto imu_trigger = make_unique<frc::DigitalInput>(0);
Sabina Davisabeae332019-02-01 21:12:57 -0800431 ::frc971::wpilib::ADIS16448 imu(frc::SPI::Port::kOnboardCS1,
432 imu_trigger.get());
433 imu.SetDummySPI(frc::SPI::Port::kOnboardCS2);
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800434 auto imu_reset = make_unique<frc::DigitalOutput>(1);
Sabina Davisabeae332019-02-01 21:12:57 -0800435 imu.set_reset(imu_reset.get());
436 ::std::thread imu_thread(::std::ref(imu));
437
438 // While as of 2/9/18 the drivetrain Victors are SPX, it appears as though
439 // they are identical, as far as DrivetrainWriter is concerned, to the SP
440 // variety so all the Victors are written as SPs.
441
Sabina Davisd004fd62019-02-02 23:51:46 -0800442 ::frc971::wpilib::DrivetrainWriter drivetrain_writer;
443 drivetrain_writer.set_left_controller0(
Sabina Davis1b84afa2019-02-09 01:20:21 -0800444 ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(0)), true);
Sabina Davisd004fd62019-02-02 23:51:46 -0800445 drivetrain_writer.set_right_controller0(
Sabina Davis1b84afa2019-02-09 01:20:21 -0800446 ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(1)), false);
Sabina Davisabeae332019-02-01 21:12:57 -0800447 ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
448
Alex Perry5fb5ff22019-02-09 21:53:17 -0800449 SuperstructureWriter superstructure_writer;
450 superstructure_writer.set_elevator_victor(
Alex Perry5fb5ff22019-02-09 21:53:17 -0800451 ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(4)));
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800452 // TODO(austin): Do the vacuum
453 //superstructure_writer.set_vacuum(
454 //::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(6)));
455 superstructure_writer.set_intake_victor(
456 ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(2)));
Alex Perry5fb5ff22019-02-09 21:53:17 -0800457 superstructure_writer.set_wrist_victor(
458 ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(5)));
459 superstructure_writer.set_stilts_victor(
Austin Schuh3e3d4ba2019-02-15 23:14:52 -0800460 ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(3)));
Alex Perry5fb5ff22019-02-09 21:53:17 -0800461
462 ::std::thread superstructure_writer_thread(
463 ::std::ref(superstructure_writer));
464
Austin Schuhc1d6f832019-02-15 23:22:17 -0800465 SolenoidWriter solenoid_writer;
466 solenoid_writer.set_intake_roller_talon(
467 make_unique<::ctre::phoenix::motorcontrol::can::TalonSRX>(10));
468 solenoid_writer.set_big_suction_cup(0);
469 solenoid_writer.set_small_suction_cup(1);
470
471 ::std::thread solenoid_writer_thread(::std::ref(solenoid_writer));
472
Sabina Davisabeae332019-02-01 21:12:57 -0800473 // Wait forever. Not much else to do...
474 while (true) {
475 const int r = select(0, nullptr, nullptr, nullptr, nullptr);
476 if (r != 0) {
477 PLOG(WARNING, "infinite select failed");
478 } else {
479 PLOG(WARNING, "infinite select succeeded??\n");
480 }
481 }
482
483 LOG(ERROR, "Exiting WPILibRobot\n");
484
Austin Schuhc1d6f832019-02-15 23:22:17 -0800485 solenoid_writer.Quit();
486 solenoid_writer_thread.join();
Sabina Davisabeae332019-02-01 21:12:57 -0800487 joystick_sender.Quit();
488 joystick_thread.join();
489 pdp_fetcher.Quit();
490 pdp_fetcher_thread.join();
491 reader.Quit();
492 reader_thread.join();
493 imu.Quit();
494 imu_thread.join();
495
496 drivetrain_writer.Quit();
497 drivetrain_writer_thread.join();
Alex Perry5fb5ff22019-02-09 21:53:17 -0800498 superstructure_writer.Quit();
499 superstructure_writer_thread.join();
Sabina Davisabeae332019-02-01 21:12:57 -0800500
501 ::aos::Cleanup();
502 }
503};
504
505} // namespace
506} // namespace wpilib
507} // namespace y2019
508
509AOS_ROBOT_CLASS(::y2019::wpilib::WPILibRobot);