blob: 3167587d0091b700bd5beba3357e596af6328c08 [file] [log] [blame]
Sabina Davis2243cab2019-02-05 21:45:08 -08001#include <inttypes.h>
Comran Morshed9a9948c2016-01-16 15:58:04 +00002#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
Comran Morshed9a9948c2016-01-16 15:58:04 +00005
Brian Silverman68cb5c22016-03-20 18:11:14 -07006#include <array>
Sabina Davis2243cab2019-02-05 21:45:08 -08007#include <chrono>
8#include <functional>
9#include <mutex>
10#include <thread>
Comran Morshed9a9948c2016-01-16 15:58:04 +000011
Parker Schuhd3b7a8872018-02-19 16:42:27 -080012#include "frc971/wpilib/ahal/AnalogInput.h"
13#include "frc971/wpilib/ahal/Compressor.h"
14#include "frc971/wpilib/ahal/DigitalGlitchFilter.h"
15#include "frc971/wpilib/ahal/DriverStation.h"
16#include "frc971/wpilib/ahal/Encoder.h"
17#include "frc971/wpilib/ahal/Relay.h"
18#include "frc971/wpilib/ahal/Talon.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000019#include "frc971/wpilib/wpilib_robot_base.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000020#undef ERROR
21
Brian Silvermanf819b442019-01-20 16:51:04 -080022#include "aos/commonmath.h"
Austin Schuhdf6cbb12019-02-02 13:46:52 -080023#include "aos/events/shm-event-loop.h"
John Park33858a32018-09-28 23:05:48 -070024#include "aos/logging/logging.h"
25#include "aos/logging/queue_logging.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080026#include "aos/make_unique.h"
27#include "aos/robot_state/robot_state.q.h"
28#include "aos/stl_mutex/stl_mutex.h"
John Park33858a32018-09-28 23:05:48 -070029#include "aos/time/time.h"
30#include "aos/util/log_interval.h"
John Park33858a32018-09-28 23:05:48 -070031#include "aos/util/wrapping_counter.h"
Philipp Schrader4bd29b12017-02-22 04:42:27 +000032#include "frc971/autonomous/auto.q.h"
Comran Morshed225f0b92016-02-10 20:34:27 +000033#include "frc971/control_loops/control_loops.q.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000034#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Austin Schuh54667ac2019-02-02 16:44:49 -080035#include "frc971/wpilib/ADIS16448.h"
36#include "frc971/wpilib/buffered_pcm.h"
37#include "frc971/wpilib/buffered_solenoid.h"
38#include "frc971/wpilib/dma.h"
39#include "frc971/wpilib/dma_edge_counting.h"
Sabina Davisb71bc282019-02-03 01:17:23 -080040#include "frc971/wpilib/drivetrain_writer.h"
Austin Schuh54667ac2019-02-02 16:44:49 -080041#include "frc971/wpilib/encoder_and_potentiometer.h"
42#include "frc971/wpilib/gyro_sender.h"
43#include "frc971/wpilib/interrupt_edge_counting.h"
44#include "frc971/wpilib/joystick_sender.h"
45#include "frc971/wpilib/logging.q.h"
46#include "frc971/wpilib/loop_output_handler.h"
47#include "frc971/wpilib/pdp_fetcher.h"
48#include "frc971/wpilib/sensor_reader.h"
Comran Morshed6c6a0a92016-01-17 12:45:16 +000049#include "y2016/constants.h"
Comran Morshed5bb12112016-02-16 13:48:57 +000050#include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Comran Morshed225f0b92016-02-10 20:34:27 +000051#include "y2016/control_loops/shooter/shooter.q.h"
Austin Schuh54667ac2019-02-02 16:44:49 -080052#include "y2016/control_loops/shooter/shooter.q.h"
Comran Morshed225f0b92016-02-10 20:34:27 +000053#include "y2016/control_loops/superstructure/superstructure.q.h"
Comran Morshedaa0573c2016-03-05 19:05:54 +000054#include "y2016/queues/ball_detector.q.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000055
Comran Morshed9a9948c2016-01-16 15:58:04 +000056using ::frc971::control_loops::drivetrain_queue;
Comran Morshed225f0b92016-02-10 20:34:27 +000057using ::y2016::control_loops::shooter::shooter_queue;
58using ::y2016::control_loops::superstructure_queue;
Brian Silvermanf819b442019-01-20 16:51:04 -080059using aos::make_unique;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -070060using ::frc971::wpilib::LoopOutputHandler;
61using ::y2016::control_loops::shooter::ShooterQueue;
Comran Morshed9a9948c2016-01-16 15:58:04 +000062
Comran Morshed6c6a0a92016-01-17 12:45:16 +000063namespace y2016 {
Comran Morshed9a9948c2016-01-16 15:58:04 +000064namespace wpilib {
Austin Schuha9992ff2016-02-28 21:59:23 -080065namespace {
66constexpr double kMaxBringupPower = 12.0;
67} // namespace
Comran Morshed9a9948c2016-01-16 15:58:04 +000068
69// TODO(Brian): Fix the interpretation of the result of GetRaw here and in the
70// DMA stuff and then removing the * 2.0 in *_translate.
71// The low bit is direction.
72
Comran Morshed225f0b92016-02-10 20:34:27 +000073// Translates for the sensor values to convert raw index pulses into something
74// with proper units.
75
76// TODO(comran): Template these methods since there is a lot of repetition here.
77double hall_translate(double in) {
78 // Turn voltage from our 3-state halls into a ratio that the loop can use.
79 return in / 5.0;
80}
81
Comran Morshed9a9948c2016-01-16 15:58:04 +000082double drivetrain_translate(int32_t in) {
Comran Morshed6c6a0a92016-01-17 12:45:16 +000083 return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +000084 constants::Values::kDrivetrainEncoderRatio *
Austin Schuh9f77fd22016-02-21 02:53:58 -080085 control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
Comran Morshed9a9948c2016-01-16 15:58:04 +000086}
87
88double drivetrain_velocity_translate(double in) {
89 return (1.0 / in) / 256.0 /*cpr*/ *
Comran Morshed225f0b92016-02-10 20:34:27 +000090 constants::Values::kDrivetrainEncoderRatio *
Austin Schuh9f77fd22016-02-21 02:53:58 -080091 control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
Comran Morshed9a9948c2016-01-16 15:58:04 +000092}
93
Comran Morshed225f0b92016-02-10 20:34:27 +000094double shooter_translate(int32_t in) {
Comran Morshed5bb12112016-02-16 13:48:57 +000095 return -static_cast<double>(in) / (128.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +000096 constants::Values::kShooterEncoderRatio * (2 * M_PI /*radians*/);
97}
Comran Morshed9a9948c2016-01-16 15:58:04 +000098
Comran Morshed225f0b92016-02-10 20:34:27 +000099double intake_translate(int32_t in) {
Austin Schuh9f77fd22016-02-21 02:53:58 -0800100 return static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +0000101 constants::Values::kIntakeEncoderRatio * (2 * M_PI /*radians*/);
102}
103
104double shoulder_translate(int32_t in) {
105 return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
106 constants::Values::kShoulderEncoderRatio * (2 * M_PI /*radians*/);
107}
108
109double wrist_translate(int32_t in) {
110 return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
111 constants::Values::kWristEncoderRatio * (2 * M_PI /*radians*/);
112}
113
114double intake_pot_translate(double voltage) {
115 return voltage * constants::Values::kIntakePotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000116 (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed225f0b92016-02-10 20:34:27 +0000117}
118
119double shoulder_pot_translate(double voltage) {
120 return voltage * constants::Values::kShoulderPotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000121 (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed225f0b92016-02-10 20:34:27 +0000122}
123
124double wrist_pot_translate(double voltage) {
125 return voltage * constants::Values::kWristPotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000126 (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000127}
128
Comran Morshed1b764322016-02-14 20:18:12 +0000129constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
130 5600.0 /* CIM free speed RPM */ * 14.0 / 48.0 /* 1st reduction */ * 28.0 /
131 50.0 /* 2nd reduction (high gear) */ * 30.0 / 44.0 /* encoder gears */ /
132 60.0 /* seconds per minute */ * 256.0 /* CPR */ * 4 /* edges per cycle */;
133
134constexpr double kMaxShooterEncoderPulsesPerSecond =
135 18700.0 /* 775pro free speed RPM */ * 12.0 /
136 18.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ *
137 128.0 /* CPR */ * 4 /* edges per cycle */;
138
139double kMaxDrivetrainShooterEncoderPulsesPerSecond = ::std::max(
140 kMaxDrivetrainEncoderPulsesPerSecond, kMaxShooterEncoderPulsesPerSecond);
141
142constexpr double kMaxSuperstructureEncoderPulsesPerSecond =
143 18700.0 /* 775pro free speed RPM */ * 12.0 /
144 56.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ *
145 512.0 /* CPR */ * 4 /* index pulse every quarter cycle */;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000146
Comran Morshed225f0b92016-02-10 20:34:27 +0000147// Class to send position messages with sensor readings to our loops.
Austin Schuh54667ac2019-02-02 16:44:49 -0800148class SensorReader : public ::frc971::wpilib::SensorReader {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000149 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800150 SensorReader(::aos::EventLoop *event_loop)
Austin Schuh4b652c92019-05-27 13:22:27 -0700151 : ::frc971::wpilib::SensorReader(event_loop),
152 ball_detector_sender_(
153 event_loop->MakeSender<::y2016::sensors::BallDetector>(
Austin Schuha250b2d2019-05-27 16:14:02 -0700154 ".y2016.sensors.ball_detector")),
155 auto_mode_sender_(
156 event_loop->MakeSender<::frc971::autonomous::AutonomousMode>(
157 ".frc971.autonomous.auto_mode")) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000158 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
159 // we should ever see.
Austin Schuh54667ac2019-02-02 16:44:49 -0800160 UpdateFastEncoderFilterHz(kMaxDrivetrainShooterEncoderPulsesPerSecond);
161 UpdateMediumEncoderFilterHz(kMaxSuperstructureEncoderPulsesPerSecond);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000162 hall_filter_.SetPeriodNanoSeconds(100000);
163 }
164
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700165 void set_drivetrain_left_hall(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000166 drivetrain_left_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000167 }
168
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700169 void set_drivetrain_right_hall(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000170 drivetrain_right_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000171 }
172
Comran Morshed225f0b92016-02-10 20:34:27 +0000173 // Shooter setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700174 void set_shooter_left_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800175 fast_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000176 shooter_left_encoder_ = ::std::move(encoder);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000177 }
178
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700179 void set_shooter_right_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800180 fast_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000181 shooter_right_encoder_ = ::std::move(encoder);
182 }
183
184 // Intake setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700185 void set_intake_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800186 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000187 intake_encoder_.set_encoder(::std::move(encoder));
188 }
189
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700190 void set_intake_potentiometer(
191 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000192 intake_encoder_.set_potentiometer(::std::move(potentiometer));
193 }
194
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700195 void set_intake_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800196 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000197 intake_encoder_.set_index(::std::move(index));
198 }
199
200 // Shoulder setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700201 void set_shoulder_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800202 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000203 shoulder_encoder_.set_encoder(::std::move(encoder));
204 }
205
206 void set_shoulder_potentiometer(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700207 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000208 shoulder_encoder_.set_potentiometer(::std::move(potentiometer));
209 }
210
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700211 void set_shoulder_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800212 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000213 shoulder_encoder_.set_index(::std::move(index));
214 }
215
216 // Wrist setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700217 void set_wrist_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800218 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000219 wrist_encoder_.set_encoder(::std::move(encoder));
220 }
221
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700222 void set_wrist_potentiometer(
223 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000224 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
225 }
226
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700227 void set_wrist_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800228 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000229 wrist_encoder_.set_index(::std::move(index));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000230 }
231
Comran Morshedaa0573c2016-03-05 19:05:54 +0000232 // Ball detector setter.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700233 void set_ball_detector(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshedaa0573c2016-03-05 19:05:54 +0000234 ball_detector_ = ::std::move(analog);
235 }
236
Brian Silverman68cb5c22016-03-20 18:11:14 -0700237 // Autonomous mode switch setter.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700238 void set_autonomous_mode(int i,
239 ::std::unique_ptr<::frc::DigitalInput> sensor) {
Brian Silverman68cb5c22016-03-20 18:11:14 -0700240 autonomous_modes_.at(i) = ::std::move(sensor);
241 }
242
Comran Morshed9a9948c2016-01-16 15:58:04 +0000243 // All of the DMA-related set_* calls must be made before this, and it doesn't
244 // hurt to do all of them.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000245
Austin Schuh54667ac2019-02-02 16:44:49 -0800246 void Start() {
247 AddToDMA(&intake_encoder_);
248 AddToDMA(&shoulder_encoder_);
249 AddToDMA(&wrist_encoder_);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000250 }
251
252 void RunIteration() {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000253 {
254 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
255 drivetrain_message->right_encoder =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800256 drivetrain_translate(-drivetrain_right_encoder_->GetRaw());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000257 drivetrain_message->left_encoder =
258 -drivetrain_translate(drivetrain_left_encoder_->GetRaw());
259 drivetrain_message->left_speed =
260 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
261 drivetrain_message->right_speed =
262 drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod());
263
Comran Morshed9a9948c2016-01-16 15:58:04 +0000264 drivetrain_message->left_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000265 hall_translate(drivetrain_left_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000266 drivetrain_message->right_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000267 hall_translate(drivetrain_right_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000268
269 drivetrain_message.Send();
270 }
Austin Schuh54667ac2019-02-02 16:44:49 -0800271 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000272
Austin Schuh54667ac2019-02-02 16:44:49 -0800273 void RunDmaIteration() {
274 const auto &values = constants::GetValues();
Comran Morshed225f0b92016-02-10 20:34:27 +0000275 {
276 auto shooter_message = shooter_queue.position.MakeMessage();
277 shooter_message->theta_left =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800278 shooter_translate(-shooter_left_encoder_->GetRaw());
Comran Morshed225f0b92016-02-10 20:34:27 +0000279 shooter_message->theta_right =
280 shooter_translate(shooter_right_encoder_->GetRaw());
281 shooter_message.Send();
282 }
283
284 {
285 auto superstructure_message = superstructure_queue.position.MakeMessage();
Sabina Davis2243cab2019-02-05 21:45:08 -0800286 CopyPosition(intake_encoder_, &superstructure_message->intake,
287 intake_translate, intake_pot_translate, false,
288 values.intake.pot_offset);
289 CopyPosition(shoulder_encoder_, &superstructure_message->shoulder,
290 shoulder_translate, shoulder_pot_translate, false,
291 values.shoulder.pot_offset);
292 CopyPosition(wrist_encoder_, &superstructure_message->wrist,
293 wrist_translate, wrist_pot_translate, true,
294 values.wrist.pot_offset);
Comran Morshed225f0b92016-02-10 20:34:27 +0000295
296 superstructure_message.Send();
297 }
Comran Morshedaa0573c2016-03-05 19:05:54 +0000298
299 {
Austin Schuh4b652c92019-05-27 13:22:27 -0700300 auto ball_detector_message = ball_detector_sender_.MakeMessage();
Comran Morshedaa0573c2016-03-05 19:05:54 +0000301 ball_detector_message->voltage = ball_detector_->GetVoltage();
302 LOG_STRUCT(DEBUG, "ball detector", *ball_detector_message);
303 ball_detector_message.Send();
304 }
Brian Silverman68cb5c22016-03-20 18:11:14 -0700305
306 {
Austin Schuha250b2d2019-05-27 16:14:02 -0700307 auto auto_mode_message = auto_mode_sender_.MakeMessage();
Brian Silverman68cb5c22016-03-20 18:11:14 -0700308 auto_mode_message->mode = 0;
309 for (size_t i = 0; i < autonomous_modes_.size(); ++i) {
310 if (autonomous_modes_[i]->Get()) {
311 auto_mode_message->mode |= 1 << i;
312 }
313 }
314 LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message);
315 auto_mode_message.Send();
316 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000317 }
318
Comran Morshed9a9948c2016-01-16 15:58:04 +0000319 private:
Austin Schuh4b652c92019-05-27 13:22:27 -0700320 ::aos::Sender<::y2016::sensors::BallDetector> ball_detector_sender_;
Austin Schuha250b2d2019-05-27 16:14:02 -0700321 ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_;
Austin Schuh4b652c92019-05-27 13:22:27 -0700322
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700323 ::std::unique_ptr<::frc::AnalogInput> drivetrain_left_hall_,
324 drivetrain_right_hall_;
Comran Morshed225f0b92016-02-10 20:34:27 +0000325
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700326 ::std::unique_ptr<::frc::Encoder> shooter_left_encoder_,
327 shooter_right_encoder_;
Comran Morshedb79c4242016-02-06 18:27:26 +0000328 ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_,
329 shoulder_encoder_, wrist_encoder_;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700330 ::std::unique_ptr<::frc::AnalogInput> ball_detector_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000331
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700332 ::std::array<::std::unique_ptr<::frc::DigitalInput>, 4> autonomous_modes_;
Brian Silverman68cb5c22016-03-20 18:11:14 -0700333
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700334 ::frc::DigitalGlitchFilter hall_filter_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000335};
336
337class SolenoidWriter {
338 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700339 SolenoidWriter(::aos::EventLoop *event_loop,
340 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000341 : pcm_(pcm),
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700342 drivetrain_(
343 event_loop
344 ->MakeFetcher<::frc971::control_loops::DrivetrainQueue::Output>(
345 ".frc971.control_loops.drivetrain_queue.output")),
346 shooter_(event_loop->MakeFetcher<ShooterQueue::Output>(
347 ".y2016.control_loops.shooter.shooter_queue.output")),
348 superstructure_(event_loop->MakeFetcher<
349 ::y2016::control_loops::SuperstructureQueue::Output>(
350 ".y2016.control_loops.superstructure_queue.output")) {
351 event_loop->set_name("Solenoids");
352 event_loop->SetRuntimeRealtimePriority(27);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000353
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700354 event_loop->OnRun([this]() { compressor_->Start(); });
355
356 event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); },
357 ::std::chrono::milliseconds(20),
358 ::std::chrono::milliseconds(1));
359 }
360
361 void set_compressor(::std::unique_ptr<::frc::Compressor> compressor) {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800362 compressor_ = ::std::move(compressor);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000363 }
364
Comran Morshed71466fe2016-04-21 20:21:14 -0700365 void set_drivetrain_shifter(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000366 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700367 drivetrain_shifter_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000368 }
369
Comran Morshed71466fe2016-04-21 20:21:14 -0700370 void set_climber_trigger(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000371 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700372 climber_trigger_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000373 }
374
Sabina Davis2243cab2019-02-05 21:45:08 -0800375 void set_traverse(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Austin Schuh843412b2016-03-20 16:48:46 -0700376 traverse_ = ::std::move(s);
377 }
378
379 void set_traverse_latch(
380 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
381 traverse_latch_ = ::std::move(s);
382 }
383
Comran Morshedb79c4242016-02-06 18:27:26 +0000384 void set_shooter_clamp(
385 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
386 shooter_clamp_ = ::std::move(s);
387 }
388
389 void set_shooter_pusher(
390 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
391 shooter_pusher_ = ::std::move(s);
392 }
393
Sabina Davis2243cab2019-02-05 21:45:08 -0800394 void set_lights(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Austin Schuhe0729a62016-03-12 21:54:17 -0800395 lights_ = ::std::move(s);
396 }
397
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700398 void set_flashlight(::std::unique_ptr<::frc::Relay> relay) {
Austin Schuh8b89d332016-03-24 20:19:12 -0700399 flashlight_ = ::std::move(relay);
400 }
401
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700402 private:
403 void Loop(const int iterations) {
404 if (iterations != 1) {
405 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
406 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000407
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700408 {
409 drivetrain_.Fetch();
410 if (drivetrain_.get()) {
411 LOG_STRUCT(DEBUG, "solenoids", *drivetrain_);
412 drivetrain_shifter_->Set(
413 !(drivetrain_->left_high || drivetrain_->right_high));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000414 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700415 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000416
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700417 {
418 shooter_.Fetch();
419 if (shooter_.get()) {
420 LOG_STRUCT(DEBUG, "solenoids", *shooter_);
421 shooter_clamp_->Set(shooter_->clamp_open);
422 shooter_pusher_->Set(shooter_->push_to_shooter);
423 lights_->Set(shooter_->lights_on);
424 if (shooter_->forwards_flashlight) {
425 if (shooter_->backwards_flashlight) {
426 flashlight_->Set(::frc::Relay::kOn);
Austin Schuhb2c33382016-04-03 16:09:17 -0700427 } else {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700428 flashlight_->Set(::frc::Relay::kReverse);
429 }
430 } else {
431 if (shooter_->backwards_flashlight) {
432 flashlight_->Set(::frc::Relay::kForward);
433 } else {
434 flashlight_->Set(::frc::Relay::kOff);
Austin Schuhb2c33382016-04-03 16:09:17 -0700435 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000436 }
437 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700438 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000439
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700440 {
441 superstructure_.Fetch();
442 if (superstructure_.get()) {
443 LOG_STRUCT(DEBUG, "solenoids", *superstructure_);
Comran Morshed71466fe2016-04-21 20:21:14 -0700444
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700445 climber_trigger_->Set(superstructure_->unfold_climber);
Comran Morshed71466fe2016-04-21 20:21:14 -0700446
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700447 traverse_->Set(superstructure_->traverse_down);
448 traverse_latch_->Set(superstructure_->traverse_unlatched);
Austin Schuh843412b2016-03-20 16:48:46 -0700449 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700450 }
Austin Schuh843412b2016-03-20 16:48:46 -0700451
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700452 {
453 ::frc971::wpilib::PneumaticsToLog to_log;
454 { to_log.compressor_on = compressor_->Enabled(); }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000455
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700456 pcm_->Flush();
457 to_log.read_solenoids = pcm_->GetAll();
458 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000459 }
460 }
461
Comran Morshed9a9948c2016-01-16 15:58:04 +0000462 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
463
Comran Morshed71466fe2016-04-21 20:21:14 -0700464 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_,
465 shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_,
466 climber_trigger_;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700467 ::std::unique_ptr<::frc::Relay> flashlight_;
468 ::std::unique_ptr<::frc::Compressor> compressor_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000469
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700470 ::aos::Fetcher<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
471 ::aos::Fetcher<ShooterQueue::Output> shooter_;
472 ::aos::Fetcher<::y2016::control_loops::SuperstructureQueue::Output>
Austin Schuh843412b2016-03-20 16:48:46 -0700473 superstructure_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000474};
475
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700476class ShooterWriter : public LoopOutputHandler<ShooterQueue::Output> {
Comran Morshed225f0b92016-02-10 20:34:27 +0000477 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800478 ShooterWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700479 : LoopOutputHandler<ShooterQueue::Output>(
480 event_loop, ".y2016.control_loops.shooter.shooter_queue.output") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800481
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700482 void set_shooter_left_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000483 shooter_left_talon_ = ::std::move(t);
484 }
485
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700486 void set_shooter_right_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000487 shooter_right_talon_ = ::std::move(t);
488 }
489
490 private:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700491 void Write(const ShooterQueue::Output &output) override {
492 LOG_STRUCT(DEBUG, "will output", output);
493
494 shooter_left_talon_->SetSpeed(output.voltage_left / 12.0);
495 shooter_right_talon_->SetSpeed(-output.voltage_right / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000496 }
497
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700498 void Stop() override {
Comran Morshed225f0b92016-02-10 20:34:27 +0000499 LOG(WARNING, "Shooter output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800500 shooter_left_talon_->SetDisabled();
501 shooter_right_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000502 }
503
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700504 ::std::unique_ptr<::frc::Talon> shooter_left_talon_, shooter_right_talon_;
Comran Morshed225f0b92016-02-10 20:34:27 +0000505};
506
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700507class SuperstructureWriter
508 : public LoopOutputHandler<
509 ::y2016::control_loops::SuperstructureQueue::Output> {
Comran Morshed225f0b92016-02-10 20:34:27 +0000510 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800511 SuperstructureWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700512 : LoopOutputHandler<::y2016::control_loops::SuperstructureQueue::Output>(
513 event_loop, ".y2016.control_loops.superstructure_queue.output") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800514
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700515 void set_intake_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000516 intake_talon_ = ::std::move(t);
517 }
518
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700519 void set_shoulder_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000520 shoulder_talon_ = ::std::move(t);
521 }
522
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700523 void set_wrist_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000524 wrist_talon_ = ::std::move(t);
525 }
526
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700527 void set_top_rollers_talon(::std::unique_ptr<::frc::Talon> t) {
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800528 top_rollers_talon_ = ::std::move(t);
529 }
530
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700531 void set_bottom_rollers_talon(::std::unique_ptr<::frc::Talon> t) {
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800532 bottom_rollers_talon_ = ::std::move(t);
Comran Morshedf4cd7642016-02-15 20:40:49 +0000533 }
534
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700535 void set_climber_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700536 climber_talon_ = ::std::move(t);
537 }
538
Comran Morshed225f0b92016-02-10 20:34:27 +0000539 private:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700540 virtual void Write(const ::y2016::control_loops::SuperstructureQueue::Output
541 &output) override {
542 LOG_STRUCT(DEBUG, "will output", output);
543 intake_talon_->SetSpeed(::aos::Clip(output.voltage_intake,
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800544 -kMaxBringupPower, kMaxBringupPower) /
545 12.0);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700546 shoulder_talon_->SetSpeed(::aos::Clip(-output.voltage_shoulder,
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800547 -kMaxBringupPower, kMaxBringupPower) /
548 12.0);
549 wrist_talon_->SetSpeed(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700550 ::aos::Clip(output.voltage_wrist, -kMaxBringupPower, kMaxBringupPower) /
Austin Schuha9992ff2016-02-28 21:59:23 -0800551 12.0);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700552 top_rollers_talon_->SetSpeed(-output.voltage_top_rollers / 12.0);
553 bottom_rollers_talon_->SetSpeed(-output.voltage_bottom_rollers / 12.0);
554 climber_talon_->SetSpeed(-output.voltage_climber / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000555 }
556
557 virtual void Stop() override {
558 LOG(WARNING, "Superstructure output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800559 intake_talon_->SetDisabled();
560 shoulder_talon_->SetDisabled();
561 wrist_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000562 }
563
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700564 ::std::unique_ptr<::frc::Talon> intake_talon_, shoulder_talon_, wrist_talon_,
Comran Morshed71466fe2016-04-21 20:21:14 -0700565 top_rollers_talon_, bottom_rollers_talon_, climber_talon_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000566};
567
Comran Morshed9a9948c2016-01-16 15:58:04 +0000568class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
569 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700570 ::std::unique_ptr<::frc::Encoder> make_encoder(int index) {
571 return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false,
572 ::frc::Encoder::k4X);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000573 }
574
575 void Run() override {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700576 // Thread 1.
577 ::aos::ShmEventLoop joystick_sender_event_loop;
578 ::frc971::wpilib::JoystickSender joystick_sender(
579 &joystick_sender_event_loop);
580 AddLoop(&joystick_sender_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000581
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700582 // Thread 2.
583 ::aos::ShmEventLoop pdp_fetcher_event_loop;
584 ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop);
585 AddLoop(&pdp_fetcher_event_loop);
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800586
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700587 // Thread 3.
588 ::aos::ShmEventLoop sensor_reader_event_loop;
589 SensorReader sensor_reader(&sensor_reader_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000590
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700591 sensor_reader.set_drivetrain_left_encoder(make_encoder(5));
592 sensor_reader.set_drivetrain_right_encoder(make_encoder(6));
593 sensor_reader.set_drivetrain_left_hall(make_unique<::frc::AnalogInput>(5));
594 sensor_reader.set_drivetrain_right_hall(make_unique<::frc::AnalogInput>(6));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000595
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700596 sensor_reader.set_shooter_left_encoder(make_encoder(7));
597 sensor_reader.set_shooter_right_encoder(make_encoder(-3));
Comran Morshed225f0b92016-02-10 20:34:27 +0000598
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700599 sensor_reader.set_intake_encoder(make_encoder(0));
600 sensor_reader.set_intake_index(make_unique<::frc::DigitalInput>(0));
601 sensor_reader.set_intake_potentiometer(make_unique<::frc::AnalogInput>(0));
Comran Morshed225f0b92016-02-10 20:34:27 +0000602
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700603 sensor_reader.set_shoulder_encoder(make_encoder(4));
604 sensor_reader.set_shoulder_index(make_unique<::frc::DigitalInput>(2));
605 sensor_reader.set_shoulder_potentiometer(
606 make_unique<::frc::AnalogInput>(2));
Comran Morshed225f0b92016-02-10 20:34:27 +0000607
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700608 sensor_reader.set_wrist_encoder(make_encoder(1));
609 sensor_reader.set_wrist_index(make_unique<::frc::DigitalInput>(1));
610 sensor_reader.set_wrist_potentiometer(make_unique<::frc::AnalogInput>(1));
Comran Morshed225f0b92016-02-10 20:34:27 +0000611
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700612 sensor_reader.set_ball_detector(make_unique<::frc::AnalogInput>(7));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000613
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700614 sensor_reader.set_autonomous_mode(0, make_unique<::frc::DigitalInput>(9));
615 sensor_reader.set_autonomous_mode(1, make_unique<::frc::DigitalInput>(8));
616 sensor_reader.set_autonomous_mode(2, make_unique<::frc::DigitalInput>(7));
617 sensor_reader.set_autonomous_mode(3, make_unique<::frc::DigitalInput>(6));
618 AddLoop(&sensor_reader_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000619
Brian Silverman003a4732018-03-11 14:02:15 -0700620 // TODO(Brian): This interacts poorly with the SpiRxClearer in ADIS16448.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700621 // Thread 4.
622 ::aos::ShmEventLoop gyro_event_loop;
623 ::frc971::wpilib::GyroSender gyro_sender(&gyro_event_loop);
624 AddLoop(&gyro_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000625
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700626 // Thread 5.
627 ::aos::ShmEventLoop imu_event_loop;
628 auto imu_trigger = make_unique<::frc::DigitalInput>(3);
629 ::frc971::wpilib::ADIS16448 imu(&imu_event_loop, ::frc::SPI::Port::kMXP,
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800630 imu_trigger.get());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700631 AddLoop(&imu_event_loop);
Brian Silverman5f17a972016-02-28 01:49:32 -0500632
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700633 // Thread 5.
634 ::aos::ShmEventLoop output_event_loop;
635 ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop);
Sabina Davisb71bc282019-02-03 01:17:23 -0800636 drivetrain_writer.set_left_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700637 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), false);
Sabina Davisb71bc282019-02-03 01:17:23 -0800638 drivetrain_writer.set_right_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700639 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)), true);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000640
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700641 ShooterWriter shooter_writer(&output_event_loop);
Comran Morshed225f0b92016-02-10 20:34:27 +0000642 shooter_writer.set_shooter_left_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700643 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(9)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000644 shooter_writer.set_shooter_right_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700645 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(8)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000646
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700647 SuperstructureWriter superstructure_writer(&output_event_loop);
Comran Morshed225f0b92016-02-10 20:34:27 +0000648 superstructure_writer.set_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700649 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000650 superstructure_writer.set_shoulder_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700651 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000652 superstructure_writer.set_wrist_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700653 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2)));
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800654 superstructure_writer.set_top_rollers_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700655 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1)));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800656 superstructure_writer.set_bottom_rollers_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700657 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(0)));
Comran Morshed71466fe2016-04-21 20:21:14 -0700658 superstructure_writer.set_climber_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700659 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000660
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700661 AddLoop(&output_event_loop);
662
663 // Thread 6.
664 ::aos::ShmEventLoop solenoid_writer_event_loop;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000665 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
666 new ::frc971::wpilib::BufferedPcm());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700667 SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm);
Comran Morshed71466fe2016-04-21 20:21:14 -0700668 solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0));
Austin Schuh843412b2016-03-20 16:48:46 -0700669 solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2));
670 solenoid_writer.set_traverse(pcm->MakeSolenoid(3));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800671 solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4));
672 solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5));
Austin Schuhe0729a62016-03-12 21:54:17 -0800673 solenoid_writer.set_lights(pcm->MakeSolenoid(6));
Comran Morshed71466fe2016-04-21 20:21:14 -0700674 solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1));
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700675 solenoid_writer.set_flashlight(make_unique<::frc::Relay>(0));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000676
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700677 solenoid_writer.set_compressor(make_unique<::frc::Compressor>());
678 AddLoop(&solenoid_writer_event_loop);
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800679
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700680 RunLoops();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000681 }
682};
683
684} // namespace wpilib
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000685} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000686
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000687AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot);