blob: d2d299fc89d34a91e12a437f9401f5c59e6aba39 [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::superstructure_queue;
Brian Silvermanf819b442019-01-20 16:51:04 -080058using aos::make_unique;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -070059using ::frc971::wpilib::LoopOutputHandler;
60using ::y2016::control_loops::shooter::ShooterQueue;
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>(
158 ".y2016.control_loops.shooter.shooter_queue.position")) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000159 // Set it to filter out anything shorter than 1/4 of the minimum pulse width
160 // we should ever see.
Austin Schuh54667ac2019-02-02 16:44:49 -0800161 UpdateFastEncoderFilterHz(kMaxDrivetrainShooterEncoderPulsesPerSecond);
162 UpdateMediumEncoderFilterHz(kMaxSuperstructureEncoderPulsesPerSecond);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000163 hall_filter_.SetPeriodNanoSeconds(100000);
164 }
165
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700166 void set_drivetrain_left_hall(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000167 drivetrain_left_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000168 }
169
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700170 void set_drivetrain_right_hall(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000171 drivetrain_right_hall_ = ::std::move(analog);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000172 }
173
Comran Morshed225f0b92016-02-10 20:34:27 +0000174 // Shooter setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700175 void set_shooter_left_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800176 fast_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000177 shooter_left_encoder_ = ::std::move(encoder);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000178 }
179
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700180 void set_shooter_right_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800181 fast_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000182 shooter_right_encoder_ = ::std::move(encoder);
183 }
184
185 // Intake setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700186 void set_intake_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800187 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000188 intake_encoder_.set_encoder(::std::move(encoder));
189 }
190
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700191 void set_intake_potentiometer(
192 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000193 intake_encoder_.set_potentiometer(::std::move(potentiometer));
194 }
195
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700196 void set_intake_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800197 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000198 intake_encoder_.set_index(::std::move(index));
199 }
200
201 // Shoulder setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700202 void set_shoulder_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800203 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000204 shoulder_encoder_.set_encoder(::std::move(encoder));
205 }
206
207 void set_shoulder_potentiometer(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700208 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000209 shoulder_encoder_.set_potentiometer(::std::move(potentiometer));
210 }
211
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700212 void set_shoulder_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800213 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000214 shoulder_encoder_.set_index(::std::move(index));
215 }
216
217 // Wrist setters.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700218 void set_wrist_encoder(::std::unique_ptr<::frc::Encoder> encoder) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800219 medium_encoder_filter_.Add(encoder.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000220 wrist_encoder_.set_encoder(::std::move(encoder));
221 }
222
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700223 void set_wrist_potentiometer(
224 ::std::unique_ptr<::frc::AnalogInput> potentiometer) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000225 wrist_encoder_.set_potentiometer(::std::move(potentiometer));
226 }
227
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700228 void set_wrist_index(::std::unique_ptr<::frc::DigitalInput> index) {
Austin Schuh54667ac2019-02-02 16:44:49 -0800229 medium_encoder_filter_.Add(index.get());
Comran Morshed225f0b92016-02-10 20:34:27 +0000230 wrist_encoder_.set_index(::std::move(index));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000231 }
232
Comran Morshedaa0573c2016-03-05 19:05:54 +0000233 // Ball detector setter.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700234 void set_ball_detector(::std::unique_ptr<::frc::AnalogInput> analog) {
Comran Morshedaa0573c2016-03-05 19:05:54 +0000235 ball_detector_ = ::std::move(analog);
236 }
237
Brian Silverman68cb5c22016-03-20 18:11:14 -0700238 // Autonomous mode switch setter.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700239 void set_autonomous_mode(int i,
240 ::std::unique_ptr<::frc::DigitalInput> sensor) {
Brian Silverman68cb5c22016-03-20 18:11:14 -0700241 autonomous_modes_.at(i) = ::std::move(sensor);
242 }
243
Comran Morshed9a9948c2016-01-16 15:58:04 +0000244 // All of the DMA-related set_* calls must be made before this, and it doesn't
245 // hurt to do all of them.
Comran Morshed9a9948c2016-01-16 15:58:04 +0000246
Austin Schuh54667ac2019-02-02 16:44:49 -0800247 void Start() {
248 AddToDMA(&intake_encoder_);
249 AddToDMA(&shoulder_encoder_);
250 AddToDMA(&wrist_encoder_);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000251 }
252
253 void RunIteration() {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000254 {
255 auto drivetrain_message = drivetrain_queue.position.MakeMessage();
256 drivetrain_message->right_encoder =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800257 drivetrain_translate(-drivetrain_right_encoder_->GetRaw());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000258 drivetrain_message->left_encoder =
259 -drivetrain_translate(drivetrain_left_encoder_->GetRaw());
260 drivetrain_message->left_speed =
261 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod());
262 drivetrain_message->right_speed =
263 drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod());
264
Comran Morshed9a9948c2016-01-16 15:58:04 +0000265 drivetrain_message->left_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000266 hall_translate(drivetrain_left_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000267 drivetrain_message->right_shifter_position =
Comran Morshed225f0b92016-02-10 20:34:27 +0000268 hall_translate(drivetrain_right_hall_->GetVoltage());
Comran Morshed9a9948c2016-01-16 15:58:04 +0000269
270 drivetrain_message.Send();
271 }
Austin Schuh54667ac2019-02-02 16:44:49 -0800272 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000273
Austin Schuh54667ac2019-02-02 16:44:49 -0800274 void RunDmaIteration() {
275 const auto &values = constants::GetValues();
Comran Morshed225f0b92016-02-10 20:34:27 +0000276 {
Austin Schuhae023fb2019-06-29 17:11:45 -0700277 auto shooter_message = shooter_position_sender_.MakeMessage();
Comran Morshed225f0b92016-02-10 20:34:27 +0000278 shooter_message->theta_left =
Austin Schuh9f77fd22016-02-21 02:53:58 -0800279 shooter_translate(-shooter_left_encoder_->GetRaw());
Comran Morshed225f0b92016-02-10 20:34:27 +0000280 shooter_message->theta_right =
281 shooter_translate(shooter_right_encoder_->GetRaw());
282 shooter_message.Send();
283 }
284
285 {
286 auto superstructure_message = superstructure_queue.position.MakeMessage();
Sabina Davis2243cab2019-02-05 21:45:08 -0800287 CopyPosition(intake_encoder_, &superstructure_message->intake,
288 intake_translate, intake_pot_translate, false,
289 values.intake.pot_offset);
290 CopyPosition(shoulder_encoder_, &superstructure_message->shoulder,
291 shoulder_translate, shoulder_pot_translate, false,
292 values.shoulder.pot_offset);
293 CopyPosition(wrist_encoder_, &superstructure_message->wrist,
294 wrist_translate, wrist_pot_translate, true,
295 values.wrist.pot_offset);
Comran Morshed225f0b92016-02-10 20:34:27 +0000296
297 superstructure_message.Send();
298 }
Comran Morshedaa0573c2016-03-05 19:05:54 +0000299
300 {
Austin Schuh4b652c92019-05-27 13:22:27 -0700301 auto ball_detector_message = ball_detector_sender_.MakeMessage();
Comran Morshedaa0573c2016-03-05 19:05:54 +0000302 ball_detector_message->voltage = ball_detector_->GetVoltage();
303 LOG_STRUCT(DEBUG, "ball detector", *ball_detector_message);
304 ball_detector_message.Send();
305 }
Brian Silverman68cb5c22016-03-20 18:11:14 -0700306
307 {
Austin Schuha250b2d2019-05-27 16:14:02 -0700308 auto auto_mode_message = auto_mode_sender_.MakeMessage();
Brian Silverman68cb5c22016-03-20 18:11:14 -0700309 auto_mode_message->mode = 0;
310 for (size_t i = 0; i < autonomous_modes_.size(); ++i) {
311 if (autonomous_modes_[i]->Get()) {
312 auto_mode_message->mode |= 1 << i;
313 }
314 }
315 LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message);
316 auto_mode_message.Send();
317 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000318 }
319
Comran Morshed9a9948c2016-01-16 15:58:04 +0000320 private:
Austin Schuh4b652c92019-05-27 13:22:27 -0700321 ::aos::Sender<::y2016::sensors::BallDetector> ball_detector_sender_;
Austin Schuha250b2d2019-05-27 16:14:02 -0700322 ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_;
Austin Schuhae023fb2019-06-29 17:11:45 -0700323 ::aos::Sender<ShooterQueue::Position> shooter_position_sender_;
Austin Schuh4b652c92019-05-27 13:22:27 -0700324
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700325 ::std::unique_ptr<::frc::AnalogInput> drivetrain_left_hall_,
326 drivetrain_right_hall_;
Comran Morshed225f0b92016-02-10 20:34:27 +0000327
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700328 ::std::unique_ptr<::frc::Encoder> shooter_left_encoder_,
329 shooter_right_encoder_;
Comran Morshedb79c4242016-02-06 18:27:26 +0000330 ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_,
331 shoulder_encoder_, wrist_encoder_;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700332 ::std::unique_ptr<::frc::AnalogInput> ball_detector_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000333
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700334 ::std::array<::std::unique_ptr<::frc::DigitalInput>, 4> autonomous_modes_;
Brian Silverman68cb5c22016-03-20 18:11:14 -0700335
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700336 ::frc::DigitalGlitchFilter hall_filter_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000337};
338
339class SolenoidWriter {
340 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700341 SolenoidWriter(::aos::EventLoop *event_loop,
342 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000343 : pcm_(pcm),
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700344 drivetrain_(
345 event_loop
346 ->MakeFetcher<::frc971::control_loops::DrivetrainQueue::Output>(
347 ".frc971.control_loops.drivetrain_queue.output")),
348 shooter_(event_loop->MakeFetcher<ShooterQueue::Output>(
349 ".y2016.control_loops.shooter.shooter_queue.output")),
350 superstructure_(event_loop->MakeFetcher<
351 ::y2016::control_loops::SuperstructureQueue::Output>(
352 ".y2016.control_loops.superstructure_queue.output")) {
353 event_loop->set_name("Solenoids");
354 event_loop->SetRuntimeRealtimePriority(27);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000355
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700356 event_loop->OnRun([this]() { compressor_->Start(); });
357
358 event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); },
359 ::std::chrono::milliseconds(20),
360 ::std::chrono::milliseconds(1));
361 }
362
363 void set_compressor(::std::unique_ptr<::frc::Compressor> compressor) {
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800364 compressor_ = ::std::move(compressor);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000365 }
366
Comran Morshed71466fe2016-04-21 20:21:14 -0700367 void set_drivetrain_shifter(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000368 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700369 drivetrain_shifter_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000370 }
371
Comran Morshed71466fe2016-04-21 20:21:14 -0700372 void set_climber_trigger(
Comran Morshed9a9948c2016-01-16 15:58:04 +0000373 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700374 climber_trigger_ = ::std::move(s);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000375 }
376
Sabina Davis2243cab2019-02-05 21:45:08 -0800377 void set_traverse(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Austin Schuh843412b2016-03-20 16:48:46 -0700378 traverse_ = ::std::move(s);
379 }
380
381 void set_traverse_latch(
382 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
383 traverse_latch_ = ::std::move(s);
384 }
385
Comran Morshedb79c4242016-02-06 18:27:26 +0000386 void set_shooter_clamp(
387 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
388 shooter_clamp_ = ::std::move(s);
389 }
390
391 void set_shooter_pusher(
392 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
393 shooter_pusher_ = ::std::move(s);
394 }
395
Sabina Davis2243cab2019-02-05 21:45:08 -0800396 void set_lights(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
Austin Schuhe0729a62016-03-12 21:54:17 -0800397 lights_ = ::std::move(s);
398 }
399
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700400 void set_flashlight(::std::unique_ptr<::frc::Relay> relay) {
Austin Schuh8b89d332016-03-24 20:19:12 -0700401 flashlight_ = ::std::move(relay);
402 }
403
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700404 private:
405 void Loop(const int iterations) {
406 if (iterations != 1) {
407 LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
408 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000409
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700410 {
411 drivetrain_.Fetch();
412 if (drivetrain_.get()) {
413 LOG_STRUCT(DEBUG, "solenoids", *drivetrain_);
414 drivetrain_shifter_->Set(
415 !(drivetrain_->left_high || drivetrain_->right_high));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000416 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700417 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000418
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700419 {
420 shooter_.Fetch();
421 if (shooter_.get()) {
422 LOG_STRUCT(DEBUG, "solenoids", *shooter_);
423 shooter_clamp_->Set(shooter_->clamp_open);
424 shooter_pusher_->Set(shooter_->push_to_shooter);
425 lights_->Set(shooter_->lights_on);
426 if (shooter_->forwards_flashlight) {
427 if (shooter_->backwards_flashlight) {
428 flashlight_->Set(::frc::Relay::kOn);
Austin Schuhb2c33382016-04-03 16:09:17 -0700429 } else {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700430 flashlight_->Set(::frc::Relay::kReverse);
431 }
432 } else {
433 if (shooter_->backwards_flashlight) {
434 flashlight_->Set(::frc::Relay::kForward);
435 } else {
436 flashlight_->Set(::frc::Relay::kOff);
Austin Schuhb2c33382016-04-03 16:09:17 -0700437 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000438 }
439 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700440 }
Comran Morshedb79c4242016-02-06 18:27:26 +0000441
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700442 {
443 superstructure_.Fetch();
444 if (superstructure_.get()) {
445 LOG_STRUCT(DEBUG, "solenoids", *superstructure_);
Comran Morshed71466fe2016-04-21 20:21:14 -0700446
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700447 climber_trigger_->Set(superstructure_->unfold_climber);
Comran Morshed71466fe2016-04-21 20:21:14 -0700448
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700449 traverse_->Set(superstructure_->traverse_down);
450 traverse_latch_->Set(superstructure_->traverse_unlatched);
Austin Schuh843412b2016-03-20 16:48:46 -0700451 }
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700452 }
Austin Schuh843412b2016-03-20 16:48:46 -0700453
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700454 {
455 ::frc971::wpilib::PneumaticsToLog to_log;
456 { to_log.compressor_on = compressor_->Enabled(); }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000457
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700458 pcm_->Flush();
459 to_log.read_solenoids = pcm_->GetAll();
460 LOG_STRUCT(DEBUG, "pneumatics info", to_log);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000461 }
462 }
463
Comran Morshed9a9948c2016-01-16 15:58:04 +0000464 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
465
Comran Morshed71466fe2016-04-21 20:21:14 -0700466 ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_,
467 shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_,
468 climber_trigger_;
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700469 ::std::unique_ptr<::frc::Relay> flashlight_;
470 ::std::unique_ptr<::frc::Compressor> compressor_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000471
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700472 ::aos::Fetcher<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
473 ::aos::Fetcher<ShooterQueue::Output> shooter_;
474 ::aos::Fetcher<::y2016::control_loops::SuperstructureQueue::Output>
Austin Schuh843412b2016-03-20 16:48:46 -0700475 superstructure_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000476};
477
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700478class ShooterWriter : public LoopOutputHandler<ShooterQueue::Output> {
Comran Morshed225f0b92016-02-10 20:34:27 +0000479 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800480 ShooterWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700481 : LoopOutputHandler<ShooterQueue::Output>(
482 event_loop, ".y2016.control_loops.shooter.shooter_queue.output") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800483
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700484 void set_shooter_left_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000485 shooter_left_talon_ = ::std::move(t);
486 }
487
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700488 void set_shooter_right_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000489 shooter_right_talon_ = ::std::move(t);
490 }
491
492 private:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700493 void Write(const ShooterQueue::Output &output) override {
494 LOG_STRUCT(DEBUG, "will output", output);
495
496 shooter_left_talon_->SetSpeed(output.voltage_left / 12.0);
497 shooter_right_talon_->SetSpeed(-output.voltage_right / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000498 }
499
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700500 void Stop() override {
Comran Morshed225f0b92016-02-10 20:34:27 +0000501 LOG(WARNING, "Shooter output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800502 shooter_left_talon_->SetDisabled();
503 shooter_right_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000504 }
505
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700506 ::std::unique_ptr<::frc::Talon> shooter_left_talon_, shooter_right_talon_;
Comran Morshed225f0b92016-02-10 20:34:27 +0000507};
508
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700509class SuperstructureWriter
510 : public LoopOutputHandler<
511 ::y2016::control_loops::SuperstructureQueue::Output> {
Comran Morshed225f0b92016-02-10 20:34:27 +0000512 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800513 SuperstructureWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700514 : LoopOutputHandler<::y2016::control_loops::SuperstructureQueue::Output>(
515 event_loop, ".y2016.control_loops.superstructure_queue.output") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800516
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700517 void set_intake_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000518 intake_talon_ = ::std::move(t);
519 }
520
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700521 void set_shoulder_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000522 shoulder_talon_ = ::std::move(t);
523 }
524
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700525 void set_wrist_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed225f0b92016-02-10 20:34:27 +0000526 wrist_talon_ = ::std::move(t);
527 }
528
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700529 void set_top_rollers_talon(::std::unique_ptr<::frc::Talon> t) {
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800530 top_rollers_talon_ = ::std::move(t);
531 }
532
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700533 void set_bottom_rollers_talon(::std::unique_ptr<::frc::Talon> t) {
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800534 bottom_rollers_talon_ = ::std::move(t);
Comran Morshedf4cd7642016-02-15 20:40:49 +0000535 }
536
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700537 void set_climber_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed71466fe2016-04-21 20:21:14 -0700538 climber_talon_ = ::std::move(t);
539 }
540
Comran Morshed225f0b92016-02-10 20:34:27 +0000541 private:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700542 virtual void Write(const ::y2016::control_loops::SuperstructureQueue::Output
543 &output) override {
544 LOG_STRUCT(DEBUG, "will output", output);
545 intake_talon_->SetSpeed(::aos::Clip(output.voltage_intake,
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800546 -kMaxBringupPower, kMaxBringupPower) /
547 12.0);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700548 shoulder_talon_->SetSpeed(::aos::Clip(-output.voltage_shoulder,
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800549 -kMaxBringupPower, kMaxBringupPower) /
550 12.0);
551 wrist_talon_->SetSpeed(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700552 ::aos::Clip(output.voltage_wrist, -kMaxBringupPower, kMaxBringupPower) /
Austin Schuha9992ff2016-02-28 21:59:23 -0800553 12.0);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700554 top_rollers_talon_->SetSpeed(-output.voltage_top_rollers / 12.0);
555 bottom_rollers_talon_->SetSpeed(-output.voltage_bottom_rollers / 12.0);
556 climber_talon_->SetSpeed(-output.voltage_climber / 12.0);
Comran Morshed225f0b92016-02-10 20:34:27 +0000557 }
558
559 virtual void Stop() override {
560 LOG(WARNING, "Superstructure output too old.\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800561 intake_talon_->SetDisabled();
562 shoulder_talon_->SetDisabled();
563 wrist_talon_->SetDisabled();
Comran Morshed225f0b92016-02-10 20:34:27 +0000564 }
565
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700566 ::std::unique_ptr<::frc::Talon> intake_talon_, shoulder_talon_, wrist_talon_,
Comran Morshed71466fe2016-04-21 20:21:14 -0700567 top_rollers_talon_, bottom_rollers_talon_, climber_talon_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000568};
569
Comran Morshed9a9948c2016-01-16 15:58:04 +0000570class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
571 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700572 ::std::unique_ptr<::frc::Encoder> make_encoder(int index) {
573 return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false,
574 ::frc::Encoder::k4X);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000575 }
576
577 void Run() override {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700578 // Thread 1.
579 ::aos::ShmEventLoop joystick_sender_event_loop;
580 ::frc971::wpilib::JoystickSender joystick_sender(
581 &joystick_sender_event_loop);
582 AddLoop(&joystick_sender_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000583
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700584 // Thread 2.
585 ::aos::ShmEventLoop pdp_fetcher_event_loop;
586 ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop);
587 AddLoop(&pdp_fetcher_event_loop);
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800588
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700589 // Thread 3.
590 ::aos::ShmEventLoop sensor_reader_event_loop;
591 SensorReader sensor_reader(&sensor_reader_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000592
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700593 sensor_reader.set_drivetrain_left_encoder(make_encoder(5));
594 sensor_reader.set_drivetrain_right_encoder(make_encoder(6));
595 sensor_reader.set_drivetrain_left_hall(make_unique<::frc::AnalogInput>(5));
596 sensor_reader.set_drivetrain_right_hall(make_unique<::frc::AnalogInput>(6));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000597
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700598 sensor_reader.set_shooter_left_encoder(make_encoder(7));
599 sensor_reader.set_shooter_right_encoder(make_encoder(-3));
Comran Morshed225f0b92016-02-10 20:34:27 +0000600
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700601 sensor_reader.set_intake_encoder(make_encoder(0));
602 sensor_reader.set_intake_index(make_unique<::frc::DigitalInput>(0));
603 sensor_reader.set_intake_potentiometer(make_unique<::frc::AnalogInput>(0));
Comran Morshed225f0b92016-02-10 20:34:27 +0000604
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700605 sensor_reader.set_shoulder_encoder(make_encoder(4));
606 sensor_reader.set_shoulder_index(make_unique<::frc::DigitalInput>(2));
607 sensor_reader.set_shoulder_potentiometer(
608 make_unique<::frc::AnalogInput>(2));
Comran Morshed225f0b92016-02-10 20:34:27 +0000609
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700610 sensor_reader.set_wrist_encoder(make_encoder(1));
611 sensor_reader.set_wrist_index(make_unique<::frc::DigitalInput>(1));
612 sensor_reader.set_wrist_potentiometer(make_unique<::frc::AnalogInput>(1));
Comran Morshed225f0b92016-02-10 20:34:27 +0000613
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700614 sensor_reader.set_ball_detector(make_unique<::frc::AnalogInput>(7));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000615
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700616 sensor_reader.set_autonomous_mode(0, make_unique<::frc::DigitalInput>(9));
617 sensor_reader.set_autonomous_mode(1, make_unique<::frc::DigitalInput>(8));
618 sensor_reader.set_autonomous_mode(2, make_unique<::frc::DigitalInput>(7));
619 sensor_reader.set_autonomous_mode(3, make_unique<::frc::DigitalInput>(6));
620 AddLoop(&sensor_reader_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000621
Brian Silverman003a4732018-03-11 14:02:15 -0700622 // TODO(Brian): This interacts poorly with the SpiRxClearer in ADIS16448.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700623 // Thread 4.
624 ::aos::ShmEventLoop gyro_event_loop;
625 ::frc971::wpilib::GyroSender gyro_sender(&gyro_event_loop);
626 AddLoop(&gyro_event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000627
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700628 // Thread 5.
629 ::aos::ShmEventLoop imu_event_loop;
630 auto imu_trigger = make_unique<::frc::DigitalInput>(3);
631 ::frc971::wpilib::ADIS16448 imu(&imu_event_loop, ::frc::SPI::Port::kMXP,
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800632 imu_trigger.get());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700633 AddLoop(&imu_event_loop);
Brian Silverman5f17a972016-02-28 01:49:32 -0500634
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700635 // Thread 5.
636 ::aos::ShmEventLoop output_event_loop;
637 ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop);
Sabina Davisb71bc282019-02-03 01:17:23 -0800638 drivetrain_writer.set_left_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700639 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), false);
Sabina Davisb71bc282019-02-03 01:17:23 -0800640 drivetrain_writer.set_right_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700641 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)), true);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000642
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700643 ShooterWriter shooter_writer(&output_event_loop);
Comran Morshed225f0b92016-02-10 20:34:27 +0000644 shooter_writer.set_shooter_left_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700645 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(9)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000646 shooter_writer.set_shooter_right_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700647 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(8)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000648
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700649 SuperstructureWriter superstructure_writer(&output_event_loop);
Comran Morshed225f0b92016-02-10 20:34:27 +0000650 superstructure_writer.set_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700651 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000652 superstructure_writer.set_shoulder_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700653 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000654 superstructure_writer.set_wrist_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700655 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2)));
Campbell Crowleyd4fd6552016-02-21 17:53:46 -0800656 superstructure_writer.set_top_rollers_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700657 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1)));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800658 superstructure_writer.set_bottom_rollers_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700659 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(0)));
Comran Morshed71466fe2016-04-21 20:21:14 -0700660 superstructure_writer.set_climber_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700661 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7)));
Comran Morshed225f0b92016-02-10 20:34:27 +0000662
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700663 AddLoop(&output_event_loop);
664
665 // Thread 6.
666 ::aos::ShmEventLoop solenoid_writer_event_loop;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000667 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
668 new ::frc971::wpilib::BufferedPcm());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700669 SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm);
Comran Morshed71466fe2016-04-21 20:21:14 -0700670 solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0));
Austin Schuh843412b2016-03-20 16:48:46 -0700671 solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2));
672 solenoid_writer.set_traverse(pcm->MakeSolenoid(3));
Austin Schuhcaa1ee92016-02-27 14:45:37 -0800673 solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4));
674 solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5));
Austin Schuhe0729a62016-03-12 21:54:17 -0800675 solenoid_writer.set_lights(pcm->MakeSolenoid(6));
Comran Morshed71466fe2016-04-21 20:21:14 -0700676 solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1));
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700677 solenoid_writer.set_flashlight(make_unique<::frc::Relay>(0));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000678
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700679 solenoid_writer.set_compressor(make_unique<::frc::Compressor>());
680 AddLoop(&solenoid_writer_event_loop);
Campbell Crowley1ab5fab2016-02-21 13:39:31 -0800681
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700682 RunLoops();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000683 }
684};
685
686} // namespace wpilib
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000687} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000688
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000689AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot);