blob: c2a42716da8b7ce76f9c31e9f908916f840a5a45 [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;
Brian Silvermanf819b442019-01-20 16:51:04 -080057using aos::make_unique;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -070058using ::frc971::wpilib::LoopOutputHandler;
59using ::y2016::control_loops::shooter::ShooterQueue;
Austin Schuh9481d0d2019-06-29 21:56:17 -070060using ::y2016::control_loops::SuperstructureQueue;
Comran Morshed9a9948c2016-01-16 15:58:04 +000061
Comran Morshed6c6a0a92016-01-17 12:45:16 +000062namespace y2016 {
Comran Morshed9a9948c2016-01-16 15:58:04 +000063namespace wpilib {
Austin Schuha9992ff2016-02-28 21:59:23 -080064namespace {
65constexpr double kMaxBringupPower = 12.0;
66} // namespace
Comran Morshed9a9948c2016-01-16 15:58:04 +000067
68// TODO(Brian): Fix the interpretation of the result of GetRaw here and in the
69// DMA stuff and then removing the * 2.0 in *_translate.
70// The low bit is direction.
71
Comran Morshed225f0b92016-02-10 20:34:27 +000072// Translates for the sensor values to convert raw index pulses into something
73// with proper units.
74
75// TODO(comran): Template these methods since there is a lot of repetition here.
76double hall_translate(double in) {
77 // Turn voltage from our 3-state halls into a ratio that the loop can use.
78 return in / 5.0;
79}
80
Comran Morshed9a9948c2016-01-16 15:58:04 +000081double drivetrain_translate(int32_t in) {
Comran Morshed6c6a0a92016-01-17 12:45:16 +000082 return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +000083 constants::Values::kDrivetrainEncoderRatio *
Austin Schuh9f77fd22016-02-21 02:53:58 -080084 control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
Comran Morshed9a9948c2016-01-16 15:58:04 +000085}
86
87double drivetrain_velocity_translate(double in) {
88 return (1.0 / in) / 256.0 /*cpr*/ *
Comran Morshed225f0b92016-02-10 20:34:27 +000089 constants::Values::kDrivetrainEncoderRatio *
Austin Schuh9f77fd22016-02-21 02:53:58 -080090 control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
Comran Morshed9a9948c2016-01-16 15:58:04 +000091}
92
Comran Morshed225f0b92016-02-10 20:34:27 +000093double shooter_translate(int32_t in) {
Comran Morshed5bb12112016-02-16 13:48:57 +000094 return -static_cast<double>(in) / (128.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +000095 constants::Values::kShooterEncoderRatio * (2 * M_PI /*radians*/);
96}
Comran Morshed9a9948c2016-01-16 15:58:04 +000097
Comran Morshed225f0b92016-02-10 20:34:27 +000098double intake_translate(int32_t in) {
Austin Schuh9f77fd22016-02-21 02:53:58 -080099 return static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
Comran Morshed225f0b92016-02-10 20:34:27 +0000100 constants::Values::kIntakeEncoderRatio * (2 * M_PI /*radians*/);
101}
102
103double shoulder_translate(int32_t in) {
104 return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
105 constants::Values::kShoulderEncoderRatio * (2 * M_PI /*radians*/);
106}
107
108double wrist_translate(int32_t in) {
109 return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
110 constants::Values::kWristEncoderRatio * (2 * M_PI /*radians*/);
111}
112
113double intake_pot_translate(double voltage) {
114 return voltage * constants::Values::kIntakePotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000115 (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed225f0b92016-02-10 20:34:27 +0000116}
117
118double shoulder_pot_translate(double voltage) {
119 return voltage * constants::Values::kShoulderPotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000120 (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed225f0b92016-02-10 20:34:27 +0000121}
122
123double wrist_pot_translate(double voltage) {
124 return voltage * constants::Values::kWristPotRatio *
Comran Morshed5bb12112016-02-16 13:48:57 +0000125 (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000126}
127
Comran Morshed1b764322016-02-14 20:18:12 +0000128constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
129 5600.0 /* CIM free speed RPM */ * 14.0 / 48.0 /* 1st reduction */ * 28.0 /
130 50.0 /* 2nd reduction (high gear) */ * 30.0 / 44.0 /* encoder gears */ /
131 60.0 /* seconds per minute */ * 256.0 /* CPR */ * 4 /* edges per cycle */;
132
133constexpr double kMaxShooterEncoderPulsesPerSecond =
134 18700.0 /* 775pro free speed RPM */ * 12.0 /
135 18.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ *
136 128.0 /* CPR */ * 4 /* edges per cycle */;
137
138double kMaxDrivetrainShooterEncoderPulsesPerSecond = ::std::max(
139 kMaxDrivetrainEncoderPulsesPerSecond, kMaxShooterEncoderPulsesPerSecond);
140
141constexpr double kMaxSuperstructureEncoderPulsesPerSecond =
142 18700.0 /* 775pro free speed RPM */ * 12.0 /
143 56.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ *
144 512.0 /* CPR */ * 4 /* index pulse every quarter cycle */;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000145
Comran Morshed225f0b92016-02-10 20:34:27 +0000146// Class to send position messages with sensor readings to our loops.
Austin Schuh54667ac2019-02-02 16:44:49 -0800147class SensorReader : public ::frc971::wpilib::SensorReader {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000148 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800149 SensorReader(::aos::EventLoop *event_loop)
Austin Schuh4b652c92019-05-27 13:22:27 -0700150 : ::frc971::wpilib::SensorReader(event_loop),
151 ball_detector_sender_(
152 event_loop->MakeSender<::y2016::sensors::BallDetector>(
Austin Schuha250b2d2019-05-27 16:14:02 -0700153 ".y2016.sensors.ball_detector")),
154 auto_mode_sender_(
155 event_loop->MakeSender<::frc971::autonomous::AutonomousMode>(
Austin Schuhae023fb2019-06-29 17:11:45 -0700156 ".frc971.autonomous.auto_mode")),
157 shooter_position_sender_(event_loop->MakeSender<ShooterQueue::Position>(
Austin Schuh9481d0d2019-06-29 21:56:17 -0700158 ".y2016.control_loops.shooter.shooter_queue.position")),
159 superstructure_position_sender_(
160 event_loop->MakeSender<SuperstructureQueue::Position>(
161 ".y2016.control_loops.superstructure_queue.position")) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000162 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
163 // we should ever see.
Austin Schuh54667ac2019-02-02 16:44:49 -0800164 UpdateFastEncoderFilterHz(kMaxDrivetrainShooterEncoderPulsesPerSecond);
165 UpdateMediumEncoderFilterHz(kMaxSuperstructureEncoderPulsesPerSecond);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000166 hall_filter_.SetPeriodNanoSeconds(100000);
167 }
168
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700169 void set_drivetrain_left_hall(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000170 drivetrain_left_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000171 }
172
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700173 void set_drivetrain_right_hall(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000174 drivetrain_right_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000175 }
176
Comran Morshed225f0b92016-02-10 20:34:27 +0000177 // Shooter setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700178 void set_shooter_left_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800179 fast_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000180 shooter_left_encoder_ = ::std::move(encoder);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000181 }
182
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700183 void set_shooter_right_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800184 fast_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000185 shooter_right_encoder_ = ::std::move(encoder);
186 }
187
188 // Intake setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700189 void set_intake_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800190 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000191 intake_encoder_.set_encoder(::std::move(encoder));
192 }
193
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700194 void set_intake_potentiometer(
195 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000196 intake_encoder_.set_potentiometer(::std::move(potentiometer));
197 }
198
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700199 void set_intake_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800200 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000201 intake_encoder_.set_index(::std::move(index));
202 }
203
204 // Shoulder setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700205 void set_shoulder_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800206 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000207 shoulder_encoder_.set_encoder(::std::move(encoder));
208 }
209
210 void set_shoulder_potentiometer(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700211 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000212 shoulder_encoder_.set_potentiometer(::std::move(potentiometer));
213 }
214
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700215 void set_shoulder_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800216 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000217 shoulder_encoder_.set_index(::std::move(index));
218 }
219
220 // Wrist setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700221 void set_wrist_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800222 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000223 wrist_encoder_.set_encoder(::std::move(encoder));
224 }
225
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700226 void set_wrist_potentiometer(
227 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000228 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
229 }
230
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700231 void set_wrist_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800232 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000233 wrist_encoder_.set_index(::std::move(index));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000234 }
235
Comran Morshedaa0573c2016-03-05 19:05:54 +0000236 // Ball detector setter.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700237 void set_ball_detector(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshedaa0573c2016-03-05 19:05:54 +0000238 ball_detector_ = ::std::move(analog);
239 }
240
Brian Silverman68cb5c22016-03-20 18:11:14 -0700241 // Autonomous mode switch setter.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700242 void set_autonomous_mode(int i,
243 ::std::unique_ptr<::frc::DigitalInput> sensor) {
Brian Silverman68cb5c22016-03-20 18:11:14 -0700244 autonomous_modes_.at(i) = ::std::move(sensor);
245 }
246
Comran Morshed9a9948c2016-01-16 15:58:04 +0000247 // All of the DMA-related set_* calls must be made before this, and it doesn't
248 // hurt to do all of them.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000249
Austin Schuh54667ac2019-02-02 16:44:49 -0800250 void Start() {
251 AddToDMA(&intake_encoder_);
252 AddToDMA(&shoulder_encoder_);
253 AddToDMA(&wrist_encoder_);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000254 }
255
256 void RunIteration() {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000257 {
258 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
259 drivetrain_message->right_encoder =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800260 drivetrain_translate(-drivetrain_right_encoder_->GetRaw());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000261 drivetrain_message->left_encoder =
262 -drivetrain_translate(drivetrain_left_encoder_->GetRaw());
263 drivetrain_message->left_speed =
264 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
265 drivetrain_message->right_speed =
266 drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod());
267
Comran Morshed9a9948c2016-01-16 15:58:04 +0000268 drivetrain_message->left_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000269 hall_translate(drivetrain_left_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000270 drivetrain_message->right_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000271 hall_translate(drivetrain_right_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000272
273 drivetrain_message.Send();
274 }
Austin Schuh54667ac2019-02-02 16:44:49 -0800275 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000276
Austin Schuh54667ac2019-02-02 16:44:49 -0800277 void RunDmaIteration() {
278 const auto &values = constants::GetValues();
Comran Morshed225f0b92016-02-10 20:34:27 +0000279 {
Austin Schuhae023fb2019-06-29 17:11:45 -0700280 auto shooter_message = shooter_position_sender_.MakeMessage();
Comran Morshed225f0b92016-02-10 20:34:27 +0000281 shooter_message->theta_left =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800282 shooter_translate(-shooter_left_encoder_->GetRaw());
Comran Morshed225f0b92016-02-10 20:34:27 +0000283 shooter_message->theta_right =
284 shooter_translate(shooter_right_encoder_->GetRaw());
285 shooter_message.Send();
286 }
287
288 {
Austin Schuh9481d0d2019-06-29 21:56:17 -0700289 auto superstructure_message =
290 superstructure_position_sender_.MakeMessage();
Sabina Davis2243cab2019-02-05 21:45:08 -0800291 CopyPosition(intake_encoder_, &superstructure_message->intake,
292 intake_translate, intake_pot_translate, false,
293 values.intake.pot_offset);
294 CopyPosition(shoulder_encoder_, &superstructure_message->shoulder,
295 shoulder_translate, shoulder_pot_translate, false,
296 values.shoulder.pot_offset);
297 CopyPosition(wrist_encoder_, &superstructure_message->wrist,
298 wrist_translate, wrist_pot_translate, true,
299 values.wrist.pot_offset);
Comran Morshed225f0b92016-02-10 20:34:27 +0000300
301 superstructure_message.Send();
302 }
Comran Morshedaa0573c2016-03-05 19:05:54 +0000303
304 {
Austin Schuh4b652c92019-05-27 13:22:27 -0700305 auto ball_detector_message = ball_detector_sender_.MakeMessage();
Comran Morshedaa0573c2016-03-05 19:05:54 +0000306 ball_detector_message->voltage = ball_detector_->GetVoltage();
307 LOG_STRUCT(DEBUG, "ball detector", *ball_detector_message);
308 ball_detector_message.Send();
309 }
Brian Silverman68cb5c22016-03-20 18:11:14 -0700310
311 {
Austin Schuha250b2d2019-05-27 16:14:02 -0700312 auto auto_mode_message = auto_mode_sender_.MakeMessage();
Brian Silverman68cb5c22016-03-20 18:11:14 -0700313 auto_mode_message->mode = 0;
314 for (size_t i = 0; i < autonomous_modes_.size(); ++i) {
315 if (autonomous_modes_[i]->Get()) {
316 auto_mode_message->mode |= 1 << i;
317 }
318 }
319 LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message);
320 auto_mode_message.Send();
321 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000322 }
323
Comran Morshed9a9948c2016-01-16 15:58:04 +0000324 private:
Austin Schuh4b652c92019-05-27 13:22:27 -0700325 ::aos::Sender<::y2016::sensors::BallDetector> ball_detector_sender_;
Austin Schuha250b2d2019-05-27 16:14:02 -0700326 ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_;
Austin Schuhae023fb2019-06-29 17:11:45 -0700327 ::aos::Sender<ShooterQueue::Position> shooter_position_sender_;
Austin Schuh9481d0d2019-06-29 21:56:17 -0700328 ::aos::Sender<SuperstructureQueue::Position> superstructure_position_sender_;
Austin Schuh4b652c92019-05-27 13:22:27 -0700329
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700330 ::std::unique_ptr<::frc::AnalogInput> drivetrain_left_hall_,
331 drivetrain_right_hall_;
Comran Morshed225f0b92016-02-10 20:34:27 +0000332
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700333 ::std::unique_ptr<::frc::Encoder> shooter_left_encoder_,
334 shooter_right_encoder_;
Comran Morshedb79c4242016-02-06 18:27:26 +0000335 ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_,
336 shoulder_encoder_, wrist_encoder_;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700337 ::std::unique_ptr<::frc::AnalogInput> ball_detector_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000338
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700339 ::std::array<::std::unique_ptr<::frc::DigitalInput>, 4> autonomous_modes_;
Brian Silverman68cb5c22016-03-20 18:11:14 -0700340
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700341 ::frc::DigitalGlitchFilter hall_filter_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000342};
343
344class SolenoidWriter {
345 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700346 SolenoidWriter(::aos::EventLoop *event_loop,
347 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000348 : pcm_(pcm),
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700349 drivetrain_(
350 event_loop
351 ->MakeFetcher<::frc971::control_loops::DrivetrainQueue::Output>(
352 ".frc971.control_loops.drivetrain_queue.output")),
353 shooter_(event_loop->MakeFetcher<ShooterQueue::Output>(
354 ".y2016.control_loops.shooter.shooter_queue.output")),
355 superstructure_(event_loop->MakeFetcher<
356 ::y2016::control_loops::SuperstructureQueue::Output>(
357 ".y2016.control_loops.superstructure_queue.output")) {
358 event_loop->set_name("Solenoids");
359 event_loop->SetRuntimeRealtimePriority(27);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000360
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700361 event_loop->OnRun([this]() { compressor_->Start(); });
362
363 event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); },
364 ::std::chrono::milliseconds(20),
365 ::std::chrono::milliseconds(1));
366 }
367
368 void set_compressor(::std::unique_ptr<::frc::Compressor> compressor) {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800369 compressor_ = ::std::move(compressor);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000370 }
371
Comran Morshed71466fe2016-04-21 20:21:14 -0700372 void set_drivetrain_shifter(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000373 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700374 drivetrain_shifter_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000375 }
376
Comran Morshed71466fe2016-04-21 20:21:14 -0700377 void set_climber_trigger(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000378 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700379 climber_trigger_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000380 }
381
Sabina Davis2243cab2019-02-05 21:45:08 -0800382 void set_traverse(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Austin Schuh843412b2016-03-20 16:48:46 -0700383 traverse_ = ::std::move(s);
384 }
385
386 void set_traverse_latch(
387 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
388 traverse_latch_ = ::std::move(s);
389 }
390
Comran Morshedb79c4242016-02-06 18:27:26 +0000391 void set_shooter_clamp(
392 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
393 shooter_clamp_ = ::std::move(s);
394 }
395
396 void set_shooter_pusher(
397 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
398 shooter_pusher_ = ::std::move(s);
399 }
400
Sabina Davis2243cab2019-02-05 21:45:08 -0800401 void set_lights(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Austin Schuhe0729a62016-03-12 21:54:17 -0800402 lights_ = ::std::move(s);
403 }
404
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700405 void set_flashlight(::std::unique_ptr<::frc::Relay> relay) {
Austin Schuh8b89d332016-03-24 20:19:12 -0700406 flashlight_ = ::std::move(relay);
407 }
408
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700409 private:
410 void Loop(const int iterations) {
411 if (iterations != 1) {
412 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
413 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000414
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700415 {
416 drivetrain_.Fetch();
417 if (drivetrain_.get()) {
418 LOG_STRUCT(DEBUG, "solenoids", *drivetrain_);
419 drivetrain_shifter_->Set(
420 !(drivetrain_->left_high || drivetrain_->right_high));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000421 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700422 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000423
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700424 {
425 shooter_.Fetch();
426 if (shooter_.get()) {
427 LOG_STRUCT(DEBUG, "solenoids", *shooter_);
428 shooter_clamp_->Set(shooter_->clamp_open);
429 shooter_pusher_->Set(shooter_->push_to_shooter);
430 lights_->Set(shooter_->lights_on);
431 if (shooter_->forwards_flashlight) {
432 if (shooter_->backwards_flashlight) {
433 flashlight_->Set(::frc::Relay::kOn);
Austin Schuhb2c33382016-04-03 16:09:17 -0700434 } else {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700435 flashlight_->Set(::frc::Relay::kReverse);
436 }
437 } else {
438 if (shooter_->backwards_flashlight) {
439 flashlight_->Set(::frc::Relay::kForward);
440 } else {
441 flashlight_->Set(::frc::Relay::kOff);
Austin Schuhb2c33382016-04-03 16:09:17 -0700442 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000443 }
444 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700445 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000446
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700447 {
448 superstructure_.Fetch();
449 if (superstructure_.get()) {
450 LOG_STRUCT(DEBUG, "solenoids", *superstructure_);
Comran Morshed71466fe2016-04-21 20:21:14 -0700451
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700452 climber_trigger_->Set(superstructure_->unfold_climber);
Comran Morshed71466fe2016-04-21 20:21:14 -0700453
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700454 traverse_->Set(superstructure_->traverse_down);
455 traverse_latch_->Set(superstructure_->traverse_unlatched);
Austin Schuh843412b2016-03-20 16:48:46 -0700456 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700457 }
Austin Schuh843412b2016-03-20 16:48:46 -0700458
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700459 {
460 ::frc971::wpilib::PneumaticsToLog to_log;
461 { to_log.compressor_on = compressor_->Enabled(); }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000462
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700463 pcm_->Flush();
464 to_log.read_solenoids = pcm_->GetAll();
465 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000466 }
467 }
468
Comran Morshed9a9948c2016-01-16 15:58:04 +0000469 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
470
Comran Morshed71466fe2016-04-21 20:21:14 -0700471 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_,
472 shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_,
473 climber_trigger_;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700474 ::std::unique_ptr<::frc::Relay> flashlight_;
475 ::std::unique_ptr<::frc::Compressor> compressor_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000476
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700477 ::aos::Fetcher<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
478 ::aos::Fetcher<ShooterQueue::Output> shooter_;
479 ::aos::Fetcher<::y2016::control_loops::SuperstructureQueue::Output>
Austin Schuh843412b2016-03-20 16:48:46 -0700480 superstructure_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000481};
482
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700483class ShooterWriter : public LoopOutputHandler<ShooterQueue::Output> {
Comran Morshed225f0b92016-02-10 20:34:27 +0000484 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800485 ShooterWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700486 : LoopOutputHandler<ShooterQueue::Output>(
487 event_loop, ".y2016.control_loops.shooter.shooter_queue.output") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800488
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700489 void set_shooter_left_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000490 shooter_left_talon_ = ::std::move(t);
491 }
492
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700493 void set_shooter_right_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000494 shooter_right_talon_ = ::std::move(t);
495 }
496
497 private:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700498 void Write(const ShooterQueue::Output &output) override {
499 LOG_STRUCT(DEBUG, "will output", output);
500
501 shooter_left_talon_->SetSpeed(output.voltage_left / 12.0);
502 shooter_right_talon_->SetSpeed(-output.voltage_right / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000503 }
504
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700505 void Stop() override {
Comran Morshed225f0b92016-02-10 20:34:27 +0000506 LOG(WARNING, "Shooter output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800507 shooter_left_talon_->SetDisabled();
508 shooter_right_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000509 }
510
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700511 ::std::unique_ptr<::frc::Talon> shooter_left_talon_, shooter_right_talon_;
Comran Morshed225f0b92016-02-10 20:34:27 +0000512};
513
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700514class SuperstructureWriter
515 : public LoopOutputHandler<
516 ::y2016::control_loops::SuperstructureQueue::Output> {
Comran Morshed225f0b92016-02-10 20:34:27 +0000517 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800518 SuperstructureWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700519 : LoopOutputHandler<::y2016::control_loops::SuperstructureQueue::Output>(
520 event_loop, ".y2016.control_loops.superstructure_queue.output") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800521
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700522 void set_intake_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000523 intake_talon_ = ::std::move(t);
524 }
525
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700526 void set_shoulder_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000527 shoulder_talon_ = ::std::move(t);
528 }
529
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700530 void set_wrist_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000531 wrist_talon_ = ::std::move(t);
532 }
533
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700534 void set_top_rollers_talon(::std::unique_ptr<::frc::Talon> t) {
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800535 top_rollers_talon_ = ::std::move(t);
536 }
537
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700538 void set_bottom_rollers_talon(::std::unique_ptr<::frc::Talon> t) {
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800539 bottom_rollers_talon_ = ::std::move(t);
Comran Morshedf4cd7642016-02-15 20:40:49 +0000540 }
541
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700542 void set_climber_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700543 climber_talon_ = ::std::move(t);
544 }
545
Comran Morshed225f0b92016-02-10 20:34:27 +0000546 private:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700547 virtual void Write(const ::y2016::control_loops::SuperstructureQueue::Output
548 &output) override {
549 LOG_STRUCT(DEBUG, "will output", output);
550 intake_talon_->SetSpeed(::aos::Clip(output.voltage_intake,
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800551 -kMaxBringupPower, kMaxBringupPower) /
552 12.0);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700553 shoulder_talon_->SetSpeed(::aos::Clip(-output.voltage_shoulder,
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800554 -kMaxBringupPower, kMaxBringupPower) /
555 12.0);
556 wrist_talon_->SetSpeed(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700557 ::aos::Clip(output.voltage_wrist, -kMaxBringupPower, kMaxBringupPower) /
Austin Schuha9992ff2016-02-28 21:59:23 -0800558 12.0);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700559 top_rollers_talon_->SetSpeed(-output.voltage_top_rollers / 12.0);
560 bottom_rollers_talon_->SetSpeed(-output.voltage_bottom_rollers / 12.0);
561 climber_talon_->SetSpeed(-output.voltage_climber / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000562 }
563
564 virtual void Stop() override {
565 LOG(WARNING, "Superstructure output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800566 intake_talon_->SetDisabled();
567 shoulder_talon_->SetDisabled();
568 wrist_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000569 }
570
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700571 ::std::unique_ptr<::frc::Talon> intake_talon_, shoulder_talon_, wrist_talon_,
Comran Morshed71466fe2016-04-21 20:21:14 -0700572 top_rollers_talon_, bottom_rollers_talon_, climber_talon_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000573};
574
Comran Morshed9a9948c2016-01-16 15:58:04 +0000575class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
576 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700577 ::std::unique_ptr<::frc::Encoder> make_encoder(int index) {
578 return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false,
579 ::frc::Encoder::k4X);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000580 }
581
582 void Run() override {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700583 // Thread 1.
584 ::aos::ShmEventLoop joystick_sender_event_loop;
585 ::frc971::wpilib::JoystickSender joystick_sender(
586 &joystick_sender_event_loop);
587 AddLoop(&joystick_sender_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000588
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700589 // Thread 2.
590 ::aos::ShmEventLoop pdp_fetcher_event_loop;
591 ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop);
592 AddLoop(&pdp_fetcher_event_loop);
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800593
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700594 // Thread 3.
595 ::aos::ShmEventLoop sensor_reader_event_loop;
596 SensorReader sensor_reader(&sensor_reader_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000597
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700598 sensor_reader.set_drivetrain_left_encoder(make_encoder(5));
599 sensor_reader.set_drivetrain_right_encoder(make_encoder(6));
600 sensor_reader.set_drivetrain_left_hall(make_unique<::frc::AnalogInput>(5));
601 sensor_reader.set_drivetrain_right_hall(make_unique<::frc::AnalogInput>(6));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000602
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700603 sensor_reader.set_shooter_left_encoder(make_encoder(7));
604 sensor_reader.set_shooter_right_encoder(make_encoder(-3));
Comran Morshed225f0b92016-02-10 20:34:27 +0000605
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700606 sensor_reader.set_intake_encoder(make_encoder(0));
607 sensor_reader.set_intake_index(make_unique<::frc::DigitalInput>(0));
608 sensor_reader.set_intake_potentiometer(make_unique<::frc::AnalogInput>(0));
Comran Morshed225f0b92016-02-10 20:34:27 +0000609
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700610 sensor_reader.set_shoulder_encoder(make_encoder(4));
611 sensor_reader.set_shoulder_index(make_unique<::frc::DigitalInput>(2));
612 sensor_reader.set_shoulder_potentiometer(
613 make_unique<::frc::AnalogInput>(2));
Comran Morshed225f0b92016-02-10 20:34:27 +0000614
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700615 sensor_reader.set_wrist_encoder(make_encoder(1));
616 sensor_reader.set_wrist_index(make_unique<::frc::DigitalInput>(1));
617 sensor_reader.set_wrist_potentiometer(make_unique<::frc::AnalogInput>(1));
Comran Morshed225f0b92016-02-10 20:34:27 +0000618
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700619 sensor_reader.set_ball_detector(make_unique<::frc::AnalogInput>(7));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000620
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700621 sensor_reader.set_autonomous_mode(0, make_unique<::frc::DigitalInput>(9));
622 sensor_reader.set_autonomous_mode(1, make_unique<::frc::DigitalInput>(8));
623 sensor_reader.set_autonomous_mode(2, make_unique<::frc::DigitalInput>(7));
624 sensor_reader.set_autonomous_mode(3, make_unique<::frc::DigitalInput>(6));
625 AddLoop(&sensor_reader_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000626
Brian Silverman003a4732018-03-11 14:02:15 -0700627 // TODO(Brian): This interacts poorly with the SpiRxClearer in ADIS16448.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700628 // Thread 4.
629 ::aos::ShmEventLoop gyro_event_loop;
630 ::frc971::wpilib::GyroSender gyro_sender(&gyro_event_loop);
631 AddLoop(&gyro_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000632
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700633 // Thread 5.
634 ::aos::ShmEventLoop imu_event_loop;
635 auto imu_trigger = make_unique<::frc::DigitalInput>(3);
636 ::frc971::wpilib::ADIS16448 imu(&imu_event_loop, ::frc::SPI::Port::kMXP,
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800637 imu_trigger.get());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700638 AddLoop(&imu_event_loop);
Brian Silverman5f17a972016-02-28 01:49:32 -0500639
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700640 // Thread 5.
641 ::aos::ShmEventLoop output_event_loop;
642 ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop);
Sabina Davisb71bc282019-02-03 01:17:23 -0800643 drivetrain_writer.set_left_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700644 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), false);
Sabina Davisb71bc282019-02-03 01:17:23 -0800645 drivetrain_writer.set_right_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700646 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)), true);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000647
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700648 ShooterWriter shooter_writer(&output_event_loop);
Comran Morshed225f0b92016-02-10 20:34:27 +0000649 shooter_writer.set_shooter_left_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700650 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(9)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000651 shooter_writer.set_shooter_right_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700652 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(8)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000653
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700654 SuperstructureWriter superstructure_writer(&output_event_loop);
Comran Morshed225f0b92016-02-10 20:34:27 +0000655 superstructure_writer.set_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700656 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000657 superstructure_writer.set_shoulder_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700658 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000659 superstructure_writer.set_wrist_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700660 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2)));
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800661 superstructure_writer.set_top_rollers_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700662 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1)));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800663 superstructure_writer.set_bottom_rollers_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700664 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(0)));
Comran Morshed71466fe2016-04-21 20:21:14 -0700665 superstructure_writer.set_climber_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700666 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000667
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700668 AddLoop(&output_event_loop);
669
670 // Thread 6.
671 ::aos::ShmEventLoop solenoid_writer_event_loop;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000672 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
673 new ::frc971::wpilib::BufferedPcm());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700674 SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm);
Comran Morshed71466fe2016-04-21 20:21:14 -0700675 solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0));
Austin Schuh843412b2016-03-20 16:48:46 -0700676 solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2));
677 solenoid_writer.set_traverse(pcm->MakeSolenoid(3));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800678 solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4));
679 solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5));
Austin Schuhe0729a62016-03-12 21:54:17 -0800680 solenoid_writer.set_lights(pcm->MakeSolenoid(6));
Comran Morshed71466fe2016-04-21 20:21:14 -0700681 solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1));
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700682 solenoid_writer.set_flashlight(make_unique<::frc::Relay>(0));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000683
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700684 solenoid_writer.set_compressor(make_unique<::frc::Compressor>());
685 AddLoop(&solenoid_writer_event_loop);
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800686
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700687 RunLoops();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000688 }
689};
690
691} // namespace wpilib
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000692} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000693
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000694AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot);