Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 1 | #include <inttypes.h> |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 5 | |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 6 | #include <array> |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 7 | #include <chrono> |
| 8 | #include <functional> |
| 9 | #include <mutex> |
| 10 | #include <thread> |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 11 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 12 | #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 Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 19 | #include "frc971/wpilib/wpilib_robot_base.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 20 | #undef ERROR |
| 21 | |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 22 | #include "aos/commonmath.h" |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 23 | #include "aos/events/shm-event-loop.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 24 | #include "aos/logging/logging.h" |
| 25 | #include "aos/logging/queue_logging.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 26 | #include "aos/make_unique.h" |
| 27 | #include "aos/robot_state/robot_state.q.h" |
| 28 | #include "aos/stl_mutex/stl_mutex.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 29 | #include "aos/time/time.h" |
| 30 | #include "aos/util/log_interval.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 31 | #include "aos/util/wrapping_counter.h" |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 32 | #include "frc971/autonomous/auto.q.h" |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 33 | #include "frc971/control_loops/control_loops.q.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 34 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 35 | #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 Davis | b71bc28 | 2019-02-03 01:17:23 -0800 | [diff] [blame] | 40 | #include "frc971/wpilib/drivetrain_writer.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 41 | #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 Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 49 | #include "y2016/constants.h" |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame] | 50 | #include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 51 | #include "y2016/control_loops/shooter/shooter.q.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 52 | #include "y2016/control_loops/shooter/shooter.q.h" |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 53 | #include "y2016/control_loops/superstructure/superstructure.q.h" |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 54 | #include "y2016/queues/ball_detector.q.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 55 | |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 56 | using aos::make_unique; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 57 | using ::frc971::wpilib::LoopOutputHandler; |
| 58 | using ::y2016::control_loops::shooter::ShooterQueue; |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 59 | using ::y2016::control_loops::SuperstructureQueue; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 60 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 61 | namespace y2016 { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 62 | namespace wpilib { |
Austin Schuh | a9992ff | 2016-02-28 21:59:23 -0800 | [diff] [blame] | 63 | namespace { |
| 64 | constexpr double kMaxBringupPower = 12.0; |
| 65 | } // namespace |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 66 | |
| 67 | // TODO(Brian): Fix the interpretation of the result of GetRaw here and in the |
| 68 | // DMA stuff and then removing the * 2.0 in *_translate. |
| 69 | // The low bit is direction. |
| 70 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 71 | // Translates for the sensor values to convert raw index pulses into something |
| 72 | // with proper units. |
| 73 | |
| 74 | // TODO(comran): Template these methods since there is a lot of repetition here. |
| 75 | double hall_translate(double in) { |
| 76 | // Turn voltage from our 3-state halls into a ratio that the loop can use. |
| 77 | return in / 5.0; |
| 78 | } |
| 79 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 80 | double drivetrain_translate(int32_t in) { |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 81 | return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 82 | constants::Values::kDrivetrainEncoderRatio * |
Austin Schuh | 9f77fd2 | 2016-02-21 02:53:58 -0800 | [diff] [blame] | 83 | control_loops::drivetrain::kWheelRadius * 2.0 * M_PI; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | double drivetrain_velocity_translate(double in) { |
| 87 | return (1.0 / in) / 256.0 /*cpr*/ * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 88 | constants::Values::kDrivetrainEncoderRatio * |
Austin Schuh | 9f77fd2 | 2016-02-21 02:53:58 -0800 | [diff] [blame] | 89 | control_loops::drivetrain::kWheelRadius * 2.0 * M_PI; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 92 | double shooter_translate(int32_t in) { |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame] | 93 | return -static_cast<double>(in) / (128.0 /*cpr*/ * 4.0 /*4x*/) * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 94 | constants::Values::kShooterEncoderRatio * (2 * M_PI /*radians*/); |
| 95 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 96 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 97 | double intake_translate(int32_t in) { |
Austin Schuh | 9f77fd2 | 2016-02-21 02:53:58 -0800 | [diff] [blame] | 98 | return static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 99 | constants::Values::kIntakeEncoderRatio * (2 * M_PI /*radians*/); |
| 100 | } |
| 101 | |
| 102 | double shoulder_translate(int32_t in) { |
| 103 | return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) * |
| 104 | constants::Values::kShoulderEncoderRatio * (2 * M_PI /*radians*/); |
| 105 | } |
| 106 | |
| 107 | double wrist_translate(int32_t in) { |
| 108 | return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) * |
| 109 | constants::Values::kWristEncoderRatio * (2 * M_PI /*radians*/); |
| 110 | } |
| 111 | |
| 112 | double intake_pot_translate(double voltage) { |
| 113 | return voltage * constants::Values::kIntakePotRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame] | 114 | (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | double shoulder_pot_translate(double voltage) { |
| 118 | return voltage * constants::Values::kShoulderPotRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame] | 119 | (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | double wrist_pot_translate(double voltage) { |
| 123 | return voltage * constants::Values::kWristPotRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame] | 124 | (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 127 | constexpr double kMaxDrivetrainEncoderPulsesPerSecond = |
| 128 | 5600.0 /* CIM free speed RPM */ * 14.0 / 48.0 /* 1st reduction */ * 28.0 / |
| 129 | 50.0 /* 2nd reduction (high gear) */ * 30.0 / 44.0 /* encoder gears */ / |
| 130 | 60.0 /* seconds per minute */ * 256.0 /* CPR */ * 4 /* edges per cycle */; |
| 131 | |
| 132 | constexpr double kMaxShooterEncoderPulsesPerSecond = |
| 133 | 18700.0 /* 775pro free speed RPM */ * 12.0 / |
| 134 | 18.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ * |
| 135 | 128.0 /* CPR */ * 4 /* edges per cycle */; |
| 136 | |
| 137 | double kMaxDrivetrainShooterEncoderPulsesPerSecond = ::std::max( |
| 138 | kMaxDrivetrainEncoderPulsesPerSecond, kMaxShooterEncoderPulsesPerSecond); |
| 139 | |
| 140 | constexpr double kMaxSuperstructureEncoderPulsesPerSecond = |
| 141 | 18700.0 /* 775pro free speed RPM */ * 12.0 / |
| 142 | 56.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ * |
| 143 | 512.0 /* CPR */ * 4 /* index pulse every quarter cycle */; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 144 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 145 | // Class to send position messages with sensor readings to our loops. |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 146 | class SensorReader : public ::frc971::wpilib::SensorReader { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 147 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 148 | SensorReader(::aos::EventLoop *event_loop) |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 149 | : ::frc971::wpilib::SensorReader(event_loop), |
| 150 | ball_detector_sender_( |
| 151 | event_loop->MakeSender<::y2016::sensors::BallDetector>( |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 152 | ".y2016.sensors.ball_detector")), |
| 153 | auto_mode_sender_( |
| 154 | event_loop->MakeSender<::frc971::autonomous::AutonomousMode>( |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 155 | ".frc971.autonomous.auto_mode")), |
| 156 | shooter_position_sender_(event_loop->MakeSender<ShooterQueue::Position>( |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 157 | ".y2016.control_loops.shooter.shooter_queue.position")), |
| 158 | superstructure_position_sender_( |
| 159 | event_loop->MakeSender<SuperstructureQueue::Position>( |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 160 | ".y2016.control_loops.superstructure_queue.position")), |
| 161 | drivetrain_position_sender_( |
| 162 | event_loop->MakeSender< |
| 163 | ::frc971::control_loops::DrivetrainQueue::Position>( |
| 164 | ".frc971.control_loops.drivetrain_queue.position")) { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 165 | // Set it to filter out anything shorter than 1/4 of the minimum pulse width |
| 166 | // we should ever see. |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 167 | UpdateFastEncoderFilterHz(kMaxDrivetrainShooterEncoderPulsesPerSecond); |
| 168 | UpdateMediumEncoderFilterHz(kMaxSuperstructureEncoderPulsesPerSecond); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 169 | hall_filter_.SetPeriodNanoSeconds(100000); |
| 170 | } |
| 171 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 172 | void set_drivetrain_left_hall(::std::unique_ptr<::frc::AnalogInput> analog) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 173 | drivetrain_left_hall_ = ::std::move(analog); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 176 | void set_drivetrain_right_hall(::std::unique_ptr<::frc::AnalogInput> analog) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 177 | drivetrain_right_hall_ = ::std::move(analog); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 180 | // Shooter setters. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 181 | void set_shooter_left_encoder(::std::unique_ptr<::frc::Encoder> encoder) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 182 | fast_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 183 | shooter_left_encoder_ = ::std::move(encoder); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 186 | void set_shooter_right_encoder(::std::unique_ptr<::frc::Encoder> encoder) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 187 | fast_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 188 | shooter_right_encoder_ = ::std::move(encoder); |
| 189 | } |
| 190 | |
| 191 | // Intake setters. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 192 | void set_intake_encoder(::std::unique_ptr<::frc::Encoder> encoder) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 193 | medium_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 194 | intake_encoder_.set_encoder(::std::move(encoder)); |
| 195 | } |
| 196 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 197 | void set_intake_potentiometer( |
| 198 | ::std::unique_ptr<::frc::AnalogInput> potentiometer) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 199 | intake_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 200 | } |
| 201 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 202 | void set_intake_index(::std::unique_ptr<::frc::DigitalInput> index) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 203 | medium_encoder_filter_.Add(index.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 204 | intake_encoder_.set_index(::std::move(index)); |
| 205 | } |
| 206 | |
| 207 | // Shoulder setters. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 208 | void set_shoulder_encoder(::std::unique_ptr<::frc::Encoder> encoder) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 209 | medium_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 210 | shoulder_encoder_.set_encoder(::std::move(encoder)); |
| 211 | } |
| 212 | |
| 213 | void set_shoulder_potentiometer( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 214 | ::std::unique_ptr<::frc::AnalogInput> potentiometer) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 215 | shoulder_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 216 | } |
| 217 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 218 | void set_shoulder_index(::std::unique_ptr<::frc::DigitalInput> index) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 219 | medium_encoder_filter_.Add(index.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 220 | shoulder_encoder_.set_index(::std::move(index)); |
| 221 | } |
| 222 | |
| 223 | // Wrist setters. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 224 | void set_wrist_encoder(::std::unique_ptr<::frc::Encoder> encoder) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 225 | medium_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 226 | wrist_encoder_.set_encoder(::std::move(encoder)); |
| 227 | } |
| 228 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 229 | void set_wrist_potentiometer( |
| 230 | ::std::unique_ptr<::frc::AnalogInput> potentiometer) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 231 | wrist_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 232 | } |
| 233 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 234 | void set_wrist_index(::std::unique_ptr<::frc::DigitalInput> index) { |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 235 | medium_encoder_filter_.Add(index.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 236 | wrist_encoder_.set_index(::std::move(index)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 239 | // Ball detector setter. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 240 | void set_ball_detector(::std::unique_ptr<::frc::AnalogInput> analog) { |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 241 | ball_detector_ = ::std::move(analog); |
| 242 | } |
| 243 | |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 244 | // Autonomous mode switch setter. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 245 | void set_autonomous_mode(int i, |
| 246 | ::std::unique_ptr<::frc::DigitalInput> sensor) { |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 247 | autonomous_modes_.at(i) = ::std::move(sensor); |
| 248 | } |
| 249 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 250 | // All of the DMA-related set_* calls must be made before this, and it doesn't |
| 251 | // hurt to do all of them. |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 252 | |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 253 | void Start() { |
| 254 | AddToDMA(&intake_encoder_); |
| 255 | AddToDMA(&shoulder_encoder_); |
| 256 | AddToDMA(&wrist_encoder_); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void RunIteration() { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 260 | { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 261 | auto drivetrain_message = drivetrain_position_sender_.MakeMessage(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 262 | drivetrain_message->right_encoder = |
Austin Schuh | 9f77fd2 | 2016-02-21 02:53:58 -0800 | [diff] [blame] | 263 | drivetrain_translate(-drivetrain_right_encoder_->GetRaw()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 264 | drivetrain_message->left_encoder = |
| 265 | -drivetrain_translate(drivetrain_left_encoder_->GetRaw()); |
| 266 | drivetrain_message->left_speed = |
| 267 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod()); |
| 268 | drivetrain_message->right_speed = |
| 269 | drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod()); |
| 270 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 271 | drivetrain_message->left_shifter_position = |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 272 | hall_translate(drivetrain_left_hall_->GetVoltage()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 273 | drivetrain_message->right_shifter_position = |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 274 | hall_translate(drivetrain_right_hall_->GetVoltage()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 275 | |
| 276 | drivetrain_message.Send(); |
| 277 | } |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 278 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 279 | |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 280 | void RunDmaIteration() { |
| 281 | const auto &values = constants::GetValues(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 282 | { |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 283 | auto shooter_message = shooter_position_sender_.MakeMessage(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 284 | shooter_message->theta_left = |
Austin Schuh | 9f77fd2 | 2016-02-21 02:53:58 -0800 | [diff] [blame] | 285 | shooter_translate(-shooter_left_encoder_->GetRaw()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 286 | shooter_message->theta_right = |
| 287 | shooter_translate(shooter_right_encoder_->GetRaw()); |
| 288 | shooter_message.Send(); |
| 289 | } |
| 290 | |
| 291 | { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 292 | auto superstructure_message = |
| 293 | superstructure_position_sender_.MakeMessage(); |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 294 | CopyPosition(intake_encoder_, &superstructure_message->intake, |
| 295 | intake_translate, intake_pot_translate, false, |
| 296 | values.intake.pot_offset); |
| 297 | CopyPosition(shoulder_encoder_, &superstructure_message->shoulder, |
| 298 | shoulder_translate, shoulder_pot_translate, false, |
| 299 | values.shoulder.pot_offset); |
| 300 | CopyPosition(wrist_encoder_, &superstructure_message->wrist, |
| 301 | wrist_translate, wrist_pot_translate, true, |
| 302 | values.wrist.pot_offset); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 303 | |
| 304 | superstructure_message.Send(); |
| 305 | } |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 306 | |
| 307 | { |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 308 | auto ball_detector_message = ball_detector_sender_.MakeMessage(); |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 309 | ball_detector_message->voltage = ball_detector_->GetVoltage(); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 310 | AOS_LOG_STRUCT(DEBUG, "ball detector", *ball_detector_message); |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 311 | ball_detector_message.Send(); |
| 312 | } |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 313 | |
| 314 | { |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 315 | auto auto_mode_message = auto_mode_sender_.MakeMessage(); |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 316 | auto_mode_message->mode = 0; |
| 317 | for (size_t i = 0; i < autonomous_modes_.size(); ++i) { |
| 318 | if (autonomous_modes_[i]->Get()) { |
| 319 | auto_mode_message->mode |= 1 << i; |
| 320 | } |
| 321 | } |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 322 | AOS_LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message); |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 323 | auto_mode_message.Send(); |
| 324 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 327 | private: |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 328 | ::aos::Sender<::y2016::sensors::BallDetector> ball_detector_sender_; |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 329 | ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_; |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 330 | ::aos::Sender<ShooterQueue::Position> shooter_position_sender_; |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 331 | ::aos::Sender<SuperstructureQueue::Position> superstructure_position_sender_; |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 332 | ::aos::Sender<::frc971::control_loops::DrivetrainQueue::Position> |
| 333 | drivetrain_position_sender_; |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 334 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 335 | ::std::unique_ptr<::frc::AnalogInput> drivetrain_left_hall_, |
| 336 | drivetrain_right_hall_; |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 337 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 338 | ::std::unique_ptr<::frc::Encoder> shooter_left_encoder_, |
| 339 | shooter_right_encoder_; |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 340 | ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_, |
| 341 | shoulder_encoder_, wrist_encoder_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 342 | ::std::unique_ptr<::frc::AnalogInput> ball_detector_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 343 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 344 | ::std::array<::std::unique_ptr<::frc::DigitalInput>, 4> autonomous_modes_; |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 345 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 346 | ::frc::DigitalGlitchFilter hall_filter_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | class SolenoidWriter { |
| 350 | public: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 351 | SolenoidWriter(::aos::EventLoop *event_loop, |
| 352 | const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm) |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 353 | : pcm_(pcm), |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 354 | drivetrain_( |
| 355 | event_loop |
| 356 | ->MakeFetcher<::frc971::control_loops::DrivetrainQueue::Output>( |
| 357 | ".frc971.control_loops.drivetrain_queue.output")), |
| 358 | shooter_(event_loop->MakeFetcher<ShooterQueue::Output>( |
| 359 | ".y2016.control_loops.shooter.shooter_queue.output")), |
| 360 | superstructure_(event_loop->MakeFetcher< |
| 361 | ::y2016::control_loops::SuperstructureQueue::Output>( |
| 362 | ".y2016.control_loops.superstructure_queue.output")) { |
| 363 | event_loop->set_name("Solenoids"); |
| 364 | event_loop->SetRuntimeRealtimePriority(27); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 365 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 366 | event_loop->OnRun([this]() { compressor_->Start(); }); |
| 367 | |
| 368 | event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); }, |
| 369 | ::std::chrono::milliseconds(20), |
| 370 | ::std::chrono::milliseconds(1)); |
| 371 | } |
| 372 | |
| 373 | void set_compressor(::std::unique_ptr<::frc::Compressor> compressor) { |
Campbell Crowley | 1ab5fab | 2016-02-21 13:39:31 -0800 | [diff] [blame] | 374 | compressor_ = ::std::move(compressor); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 377 | void set_drivetrain_shifter( |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 378 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 379 | drivetrain_shifter_ = ::std::move(s); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 382 | void set_climber_trigger( |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 383 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 384 | climber_trigger_ = ::std::move(s); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 387 | void set_traverse(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 388 | traverse_ = ::std::move(s); |
| 389 | } |
| 390 | |
| 391 | void set_traverse_latch( |
| 392 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 393 | traverse_latch_ = ::std::move(s); |
| 394 | } |
| 395 | |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 396 | void set_shooter_clamp( |
| 397 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 398 | shooter_clamp_ = ::std::move(s); |
| 399 | } |
| 400 | |
| 401 | void set_shooter_pusher( |
| 402 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 403 | shooter_pusher_ = ::std::move(s); |
| 404 | } |
| 405 | |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 406 | void set_lights(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Austin Schuh | e0729a6 | 2016-03-12 21:54:17 -0800 | [diff] [blame] | 407 | lights_ = ::std::move(s); |
| 408 | } |
| 409 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 410 | void set_flashlight(::std::unique_ptr<::frc::Relay> relay) { |
Austin Schuh | 8b89d33 | 2016-03-24 20:19:12 -0700 | [diff] [blame] | 411 | flashlight_ = ::std::move(relay); |
| 412 | } |
| 413 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 414 | private: |
| 415 | void Loop(const int iterations) { |
| 416 | if (iterations != 1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 417 | AOS_LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 418 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 419 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 420 | { |
| 421 | drivetrain_.Fetch(); |
| 422 | if (drivetrain_.get()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 423 | AOS_LOG_STRUCT(DEBUG, "solenoids", *drivetrain_); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 424 | drivetrain_shifter_->Set( |
| 425 | !(drivetrain_->left_high || drivetrain_->right_high)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 426 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 427 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 428 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 429 | { |
| 430 | shooter_.Fetch(); |
| 431 | if (shooter_.get()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 432 | AOS_LOG_STRUCT(DEBUG, "solenoids", *shooter_); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 433 | shooter_clamp_->Set(shooter_->clamp_open); |
| 434 | shooter_pusher_->Set(shooter_->push_to_shooter); |
| 435 | lights_->Set(shooter_->lights_on); |
| 436 | if (shooter_->forwards_flashlight) { |
| 437 | if (shooter_->backwards_flashlight) { |
| 438 | flashlight_->Set(::frc::Relay::kOn); |
Austin Schuh | b2c3338 | 2016-04-03 16:09:17 -0700 | [diff] [blame] | 439 | } else { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 440 | flashlight_->Set(::frc::Relay::kReverse); |
| 441 | } |
| 442 | } else { |
| 443 | if (shooter_->backwards_flashlight) { |
| 444 | flashlight_->Set(::frc::Relay::kForward); |
| 445 | } else { |
| 446 | flashlight_->Set(::frc::Relay::kOff); |
Austin Schuh | b2c3338 | 2016-04-03 16:09:17 -0700 | [diff] [blame] | 447 | } |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 448 | } |
| 449 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 450 | } |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 451 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 452 | { |
| 453 | superstructure_.Fetch(); |
| 454 | if (superstructure_.get()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 455 | AOS_LOG_STRUCT(DEBUG, "solenoids", *superstructure_); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 456 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 457 | climber_trigger_->Set(superstructure_->unfold_climber); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 458 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 459 | traverse_->Set(superstructure_->traverse_down); |
| 460 | traverse_latch_->Set(superstructure_->traverse_unlatched); |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 461 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 462 | } |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 463 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 464 | { |
| 465 | ::frc971::wpilib::PneumaticsToLog to_log; |
| 466 | { to_log.compressor_on = compressor_->Enabled(); } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 467 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 468 | pcm_->Flush(); |
| 469 | to_log.read_solenoids = pcm_->GetAll(); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 470 | AOS_LOG_STRUCT(DEBUG, "pneumatics info", to_log); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 474 | const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_; |
| 475 | |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 476 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_, |
| 477 | shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_, |
| 478 | climber_trigger_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 479 | ::std::unique_ptr<::frc::Relay> flashlight_; |
| 480 | ::std::unique_ptr<::frc::Compressor> compressor_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 481 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 482 | ::aos::Fetcher<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_; |
| 483 | ::aos::Fetcher<ShooterQueue::Output> shooter_; |
| 484 | ::aos::Fetcher<::y2016::control_loops::SuperstructureQueue::Output> |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 485 | superstructure_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 486 | }; |
| 487 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 488 | class ShooterWriter : public LoopOutputHandler<ShooterQueue::Output> { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 489 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 490 | ShooterWriter(::aos::EventLoop *event_loop) |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 491 | : LoopOutputHandler<ShooterQueue::Output>( |
| 492 | event_loop, ".y2016.control_loops.shooter.shooter_queue.output") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 493 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 494 | void set_shooter_left_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 495 | shooter_left_talon_ = ::std::move(t); |
| 496 | } |
| 497 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 498 | void set_shooter_right_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 499 | shooter_right_talon_ = ::std::move(t); |
| 500 | } |
| 501 | |
| 502 | private: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 503 | void Write(const ShooterQueue::Output &output) override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 504 | AOS_LOG_STRUCT(DEBUG, "will output", output); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 505 | |
| 506 | shooter_left_talon_->SetSpeed(output.voltage_left / 12.0); |
| 507 | shooter_right_talon_->SetSpeed(-output.voltage_right / 12.0); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 510 | void Stop() override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 511 | AOS_LOG(WARNING, "Shooter output too old.\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 512 | shooter_left_talon_->SetDisabled(); |
| 513 | shooter_right_talon_->SetDisabled(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 516 | ::std::unique_ptr<::frc::Talon> shooter_left_talon_, shooter_right_talon_; |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 517 | }; |
| 518 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 519 | class SuperstructureWriter |
| 520 | : public LoopOutputHandler< |
| 521 | ::y2016::control_loops::SuperstructureQueue::Output> { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 522 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 523 | SuperstructureWriter(::aos::EventLoop *event_loop) |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 524 | : LoopOutputHandler<::y2016::control_loops::SuperstructureQueue::Output>( |
| 525 | event_loop, ".y2016.control_loops.superstructure_queue.output") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 526 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 527 | void set_intake_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 528 | intake_talon_ = ::std::move(t); |
| 529 | } |
| 530 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 531 | void set_shoulder_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 532 | shoulder_talon_ = ::std::move(t); |
| 533 | } |
| 534 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 535 | void set_wrist_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 536 | wrist_talon_ = ::std::move(t); |
| 537 | } |
| 538 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 539 | void set_top_rollers_talon(::std::unique_ptr<::frc::Talon> t) { |
Campbell Crowley | d4fd655 | 2016-02-21 17:53:46 -0800 | [diff] [blame] | 540 | top_rollers_talon_ = ::std::move(t); |
| 541 | } |
| 542 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 543 | void set_bottom_rollers_talon(::std::unique_ptr<::frc::Talon> t) { |
Campbell Crowley | d4fd655 | 2016-02-21 17:53:46 -0800 | [diff] [blame] | 544 | bottom_rollers_talon_ = ::std::move(t); |
Comran Morshed | f4cd764 | 2016-02-15 20:40:49 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 547 | void set_climber_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 548 | climber_talon_ = ::std::move(t); |
| 549 | } |
| 550 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 551 | private: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 552 | virtual void Write(const ::y2016::control_loops::SuperstructureQueue::Output |
| 553 | &output) override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 554 | AOS_LOG_STRUCT(DEBUG, "will output", output); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 555 | intake_talon_->SetSpeed(::aos::Clip(output.voltage_intake, |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 556 | -kMaxBringupPower, kMaxBringupPower) / |
| 557 | 12.0); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 558 | shoulder_talon_->SetSpeed(::aos::Clip(-output.voltage_shoulder, |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 559 | -kMaxBringupPower, kMaxBringupPower) / |
| 560 | 12.0); |
| 561 | wrist_talon_->SetSpeed( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 562 | ::aos::Clip(output.voltage_wrist, -kMaxBringupPower, kMaxBringupPower) / |
Austin Schuh | a9992ff | 2016-02-28 21:59:23 -0800 | [diff] [blame] | 563 | 12.0); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 564 | top_rollers_talon_->SetSpeed(-output.voltage_top_rollers / 12.0); |
| 565 | bottom_rollers_talon_->SetSpeed(-output.voltage_bottom_rollers / 12.0); |
| 566 | climber_talon_->SetSpeed(-output.voltage_climber / 12.0); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | virtual void Stop() override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 570 | AOS_LOG(WARNING, "Superstructure output too old.\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 571 | intake_talon_->SetDisabled(); |
| 572 | shoulder_talon_->SetDisabled(); |
| 573 | wrist_talon_->SetDisabled(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 576 | ::std::unique_ptr<::frc::Talon> intake_talon_, shoulder_talon_, wrist_talon_, |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 577 | top_rollers_talon_, bottom_rollers_talon_, climber_talon_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 578 | }; |
| 579 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 580 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 581 | public: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 582 | ::std::unique_ptr<::frc::Encoder> make_encoder(int index) { |
| 583 | return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false, |
| 584 | ::frc::Encoder::k4X); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | void Run() override { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 588 | // Thread 1. |
| 589 | ::aos::ShmEventLoop joystick_sender_event_loop; |
| 590 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 591 | &joystick_sender_event_loop); |
| 592 | AddLoop(&joystick_sender_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 593 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 594 | // Thread 2. |
| 595 | ::aos::ShmEventLoop pdp_fetcher_event_loop; |
| 596 | ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop); |
| 597 | AddLoop(&pdp_fetcher_event_loop); |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 598 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 599 | // Thread 3. |
| 600 | ::aos::ShmEventLoop sensor_reader_event_loop; |
| 601 | SensorReader sensor_reader(&sensor_reader_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 602 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 603 | sensor_reader.set_drivetrain_left_encoder(make_encoder(5)); |
| 604 | sensor_reader.set_drivetrain_right_encoder(make_encoder(6)); |
| 605 | sensor_reader.set_drivetrain_left_hall(make_unique<::frc::AnalogInput>(5)); |
| 606 | sensor_reader.set_drivetrain_right_hall(make_unique<::frc::AnalogInput>(6)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 607 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 608 | sensor_reader.set_shooter_left_encoder(make_encoder(7)); |
| 609 | sensor_reader.set_shooter_right_encoder(make_encoder(-3)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 610 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 611 | sensor_reader.set_intake_encoder(make_encoder(0)); |
| 612 | sensor_reader.set_intake_index(make_unique<::frc::DigitalInput>(0)); |
| 613 | sensor_reader.set_intake_potentiometer(make_unique<::frc::AnalogInput>(0)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 614 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 615 | sensor_reader.set_shoulder_encoder(make_encoder(4)); |
| 616 | sensor_reader.set_shoulder_index(make_unique<::frc::DigitalInput>(2)); |
| 617 | sensor_reader.set_shoulder_potentiometer( |
| 618 | make_unique<::frc::AnalogInput>(2)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 619 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 620 | sensor_reader.set_wrist_encoder(make_encoder(1)); |
| 621 | sensor_reader.set_wrist_index(make_unique<::frc::DigitalInput>(1)); |
| 622 | sensor_reader.set_wrist_potentiometer(make_unique<::frc::AnalogInput>(1)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 623 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 624 | sensor_reader.set_ball_detector(make_unique<::frc::AnalogInput>(7)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 625 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 626 | sensor_reader.set_autonomous_mode(0, make_unique<::frc::DigitalInput>(9)); |
| 627 | sensor_reader.set_autonomous_mode(1, make_unique<::frc::DigitalInput>(8)); |
| 628 | sensor_reader.set_autonomous_mode(2, make_unique<::frc::DigitalInput>(7)); |
| 629 | sensor_reader.set_autonomous_mode(3, make_unique<::frc::DigitalInput>(6)); |
| 630 | AddLoop(&sensor_reader_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 631 | |
Brian Silverman | 003a473 | 2018-03-11 14:02:15 -0700 | [diff] [blame] | 632 | // TODO(Brian): This interacts poorly with the SpiRxClearer in ADIS16448. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 633 | // Thread 4. |
| 634 | ::aos::ShmEventLoop gyro_event_loop; |
| 635 | ::frc971::wpilib::GyroSender gyro_sender(&gyro_event_loop); |
| 636 | AddLoop(&gyro_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 637 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 638 | // Thread 5. |
| 639 | ::aos::ShmEventLoop imu_event_loop; |
| 640 | auto imu_trigger = make_unique<::frc::DigitalInput>(3); |
| 641 | ::frc971::wpilib::ADIS16448 imu(&imu_event_loop, ::frc::SPI::Port::kMXP, |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 642 | imu_trigger.get()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 643 | AddLoop(&imu_event_loop); |
Brian Silverman | 5f17a97 | 2016-02-28 01:49:32 -0500 | [diff] [blame] | 644 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 645 | // Thread 5. |
| 646 | ::aos::ShmEventLoop output_event_loop; |
| 647 | ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop); |
Sabina Davis | b71bc28 | 2019-02-03 01:17:23 -0800 | [diff] [blame] | 648 | drivetrain_writer.set_left_controller0( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 649 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), false); |
Sabina Davis | b71bc28 | 2019-02-03 01:17:23 -0800 | [diff] [blame] | 650 | drivetrain_writer.set_right_controller0( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 651 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)), true); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 652 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 653 | ShooterWriter shooter_writer(&output_event_loop); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 654 | shooter_writer.set_shooter_left_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 655 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(9))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 656 | shooter_writer.set_shooter_right_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 657 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(8))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 658 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 659 | SuperstructureWriter superstructure_writer(&output_event_loop); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 660 | superstructure_writer.set_intake_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 661 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 662 | superstructure_writer.set_shoulder_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 663 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 664 | superstructure_writer.set_wrist_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 665 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2))); |
Campbell Crowley | d4fd655 | 2016-02-21 17:53:46 -0800 | [diff] [blame] | 666 | superstructure_writer.set_top_rollers_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 667 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1))); |
Austin Schuh | caa1ee9 | 2016-02-27 14:45:37 -0800 | [diff] [blame] | 668 | superstructure_writer.set_bottom_rollers_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 669 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(0))); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 670 | superstructure_writer.set_climber_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 671 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 672 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 673 | AddLoop(&output_event_loop); |
| 674 | |
| 675 | // Thread 6. |
| 676 | ::aos::ShmEventLoop solenoid_writer_event_loop; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 677 | ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm( |
| 678 | new ::frc971::wpilib::BufferedPcm()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 679 | SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 680 | solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0)); |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 681 | solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2)); |
| 682 | solenoid_writer.set_traverse(pcm->MakeSolenoid(3)); |
Austin Schuh | caa1ee9 | 2016-02-27 14:45:37 -0800 | [diff] [blame] | 683 | solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4)); |
| 684 | solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5)); |
Austin Schuh | e0729a6 | 2016-03-12 21:54:17 -0800 | [diff] [blame] | 685 | solenoid_writer.set_lights(pcm->MakeSolenoid(6)); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 686 | solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1)); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 687 | solenoid_writer.set_flashlight(make_unique<::frc::Relay>(0)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 688 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 689 | solenoid_writer.set_compressor(make_unique<::frc::Compressor>()); |
| 690 | AddLoop(&solenoid_writer_event_loop); |
Campbell Crowley | 1ab5fab | 2016-02-21 13:39:31 -0800 | [diff] [blame] | 691 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 692 | RunLoops(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 693 | } |
| 694 | }; |
| 695 | |
| 696 | } // namespace wpilib |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 697 | } // namespace y2016 |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 698 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 699 | AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot); |