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" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [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" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 25 | #include "aos/stl_mutex/stl_mutex.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 26 | #include "aos/time/time.h" |
| 27 | #include "aos/util/log_interval.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 28 | #include "aos/util/wrapping_counter.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 29 | #include "frc971/autonomous/auto_generated.h" |
Austin Schuh | ed5b26d | 2019-12-05 20:51:59 -0800 | [diff] [blame] | 30 | #include "frc971/autonomous/auto_mode_generated.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 31 | #include "frc971/control_loops/drivetrain/drivetrain_output_generated.h" |
| 32 | #include "frc971/control_loops/drivetrain/drivetrain_position_generated.h" |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 33 | #include "frc971/input/robot_state_generated.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 34 | #include "frc971/wpilib/ADIS16448.h" |
| 35 | #include "frc971/wpilib/buffered_pcm.h" |
| 36 | #include "frc971/wpilib/buffered_solenoid.h" |
| 37 | #include "frc971/wpilib/dma.h" |
| 38 | #include "frc971/wpilib/dma_edge_counting.h" |
Sabina Davis | b71bc28 | 2019-02-03 01:17:23 -0800 | [diff] [blame] | 39 | #include "frc971/wpilib/drivetrain_writer.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 40 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
| 41 | #include "frc971/wpilib/gyro_sender.h" |
| 42 | #include "frc971/wpilib/interrupt_edge_counting.h" |
| 43 | #include "frc971/wpilib/joystick_sender.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 44 | #include "frc971/wpilib/logging_generated.h" |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 45 | #include "frc971/wpilib/loop_output_handler.h" |
| 46 | #include "frc971/wpilib/pdp_fetcher.h" |
| 47 | #include "frc971/wpilib/sensor_reader.h" |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 48 | #include "y2016/constants.h" |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame] | 49 | #include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 50 | #include "y2016/control_loops/shooter/shooter_output_generated.h" |
| 51 | #include "y2016/control_loops/shooter/shooter_position_generated.h" |
| 52 | #include "y2016/control_loops/superstructure/superstructure_output_generated.h" |
| 53 | #include "y2016/control_loops/superstructure/superstructure_position_generated.h" |
| 54 | #include "y2016/queues/ball_detector_generated.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 55 | |
Vinay Siva | e52a6b3 | 2021-07-10 15:19:26 -0700 | [diff] [blame] | 56 | using std::make_unique; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 57 | using ::frc971::wpilib::LoopOutputHandler; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 58 | namespace shooter = ::y2016::control_loops::shooter; |
| 59 | namespace superstructure = ::y2016::control_loops::superstructure; |
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 | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 148 | SensorReader(::aos::ShmEventLoop *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>( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 152 | "/superstructure")), |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 153 | auto_mode_sender_( |
| 154 | event_loop->MakeSender<::frc971::autonomous::AutonomousMode>( |
Tyler Chatow | 24b5db1 | 2020-01-06 21:16:56 -0800 | [diff] [blame] | 155 | "/autonomous")), |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 156 | shooter_position_sender_( |
| 157 | event_loop->MakeSender<shooter::Position>("/shooter")), |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 158 | superstructure_position_sender_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 159 | event_loop->MakeSender<superstructure::Position>( |
| 160 | "/superstructure")), |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 161 | drivetrain_position_sender_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 162 | event_loop |
| 163 | ->MakeSender<::frc971::control_loops::drivetrain::Position>( |
| 164 | "/drivetrain")) { |
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 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 261 | auto builder = drivetrain_position_sender_.MakeBuilder(); |
| 262 | frc971::control_loops::drivetrain::Position::Builder position_builder = |
| 263 | builder.MakeBuilder<frc971::control_loops::drivetrain::Position>(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 264 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 265 | position_builder.add_right_encoder( |
| 266 | drivetrain_translate(-drivetrain_right_encoder_->GetRaw())); |
| 267 | position_builder.add_left_encoder( |
| 268 | -drivetrain_translate(drivetrain_left_encoder_->GetRaw())); |
| 269 | position_builder.add_left_speed( |
| 270 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod())); |
| 271 | position_builder.add_right_speed(drivetrain_velocity_translate( |
| 272 | drivetrain_right_encoder_->GetPeriod())); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 273 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 274 | position_builder.add_left_shifter_position( |
| 275 | hall_translate(drivetrain_left_hall_->GetVoltage())); |
| 276 | position_builder.add_right_shifter_position( |
| 277 | hall_translate(drivetrain_right_hall_->GetVoltage())); |
| 278 | |
| 279 | builder.Send(position_builder.Finish()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 280 | } |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 281 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 282 | |
Austin Schuh | 54667ac | 2019-02-02 16:44:49 -0800 | [diff] [blame] | 283 | void RunDmaIteration() { |
| 284 | const auto &values = constants::GetValues(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 285 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 286 | auto builder = shooter_position_sender_.MakeBuilder(); |
| 287 | shooter::Position::Builder shooter_builder = |
| 288 | builder.MakeBuilder<shooter::Position>(); |
| 289 | shooter_builder.add_theta_left( |
| 290 | shooter_translate(-shooter_left_encoder_->GetRaw())); |
| 291 | shooter_builder.add_theta_right( |
| 292 | shooter_translate(shooter_right_encoder_->GetRaw())); |
| 293 | builder.Send(shooter_builder.Finish()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 297 | auto builder = superstructure_position_sender_.MakeBuilder(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 298 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 299 | frc971::PotAndIndexPositionT intake; |
| 300 | CopyPosition(intake_encoder_, &intake, intake_translate, |
| 301 | intake_pot_translate, false, values.intake.pot_offset); |
| 302 | flatbuffers::Offset<frc971::PotAndIndexPosition> intake_offset = |
| 303 | frc971::PotAndIndexPosition::Pack(*builder.fbb(), &intake); |
| 304 | |
| 305 | frc971::PotAndIndexPositionT shoulder; |
| 306 | CopyPosition(shoulder_encoder_, &shoulder, shoulder_translate, |
| 307 | shoulder_pot_translate, false, values.shoulder.pot_offset); |
| 308 | flatbuffers::Offset<frc971::PotAndIndexPosition> shoulder_offset = |
| 309 | frc971::PotAndIndexPosition::Pack(*builder.fbb(), &shoulder); |
| 310 | |
| 311 | frc971::PotAndIndexPositionT wrist; |
| 312 | CopyPosition(wrist_encoder_, &wrist, wrist_translate, wrist_pot_translate, |
| 313 | true, values.wrist.pot_offset); |
| 314 | flatbuffers::Offset<frc971::PotAndIndexPosition> wrist_offset = |
| 315 | frc971::PotAndIndexPosition::Pack(*builder.fbb(), &wrist); |
| 316 | |
| 317 | superstructure::Position::Builder position_builder = |
| 318 | builder.MakeBuilder<superstructure::Position>(); |
| 319 | |
| 320 | position_builder.add_intake(intake_offset); |
| 321 | position_builder.add_shoulder(shoulder_offset); |
| 322 | position_builder.add_wrist(wrist_offset); |
| 323 | |
| 324 | builder.Send(position_builder.Finish()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 325 | } |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 326 | |
| 327 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 328 | auto builder = ball_detector_sender_.MakeBuilder(); |
| 329 | ::y2016::sensors::BallDetector::Builder ball_detector_builder = |
| 330 | builder.MakeBuilder<y2016::sensors::BallDetector>(); |
| 331 | ball_detector_builder.add_voltage(ball_detector_->GetVoltage()); |
| 332 | builder.Send(ball_detector_builder.Finish()); |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 333 | } |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 334 | |
| 335 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 336 | auto builder = auto_mode_sender_.MakeBuilder(); |
| 337 | ::frc971::autonomous::AutonomousMode::Builder auto_builder = |
| 338 | builder.MakeBuilder<frc971::autonomous::AutonomousMode>(); |
| 339 | int mode = 0; |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 340 | for (size_t i = 0; i < autonomous_modes_.size(); ++i) { |
| 341 | if (autonomous_modes_[i]->Get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 342 | mode |= 1 << i; |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 345 | auto_builder.add_mode(mode); |
| 346 | builder.Send(auto_builder.Finish()); |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 347 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 350 | private: |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 351 | ::aos::Sender<::y2016::sensors::BallDetector> ball_detector_sender_; |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 352 | ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 353 | ::aos::Sender<shooter::Position> shooter_position_sender_; |
| 354 | ::aos::Sender<superstructure::Position> superstructure_position_sender_; |
| 355 | ::aos::Sender<::frc971::control_loops::drivetrain::Position> |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 356 | drivetrain_position_sender_; |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 357 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 358 | ::std::unique_ptr<::frc::AnalogInput> drivetrain_left_hall_, |
| 359 | drivetrain_right_hall_; |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 360 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 361 | ::std::unique_ptr<::frc::Encoder> shooter_left_encoder_, |
| 362 | shooter_right_encoder_; |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 363 | ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_, |
| 364 | shoulder_encoder_, wrist_encoder_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 365 | ::std::unique_ptr<::frc::AnalogInput> ball_detector_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 366 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 367 | ::std::array<::std::unique_ptr<::frc::DigitalInput>, 4> autonomous_modes_; |
Brian Silverman | 68cb5c2 | 2016-03-20 18:11:14 -0700 | [diff] [blame] | 368 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 369 | ::frc::DigitalGlitchFilter hall_filter_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | class SolenoidWriter { |
| 373 | public: |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 374 | SolenoidWriter(::aos::ShmEventLoop *event_loop, |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 375 | ::frc971::wpilib::BufferedPcm *pcm) |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 376 | : pcm_(pcm), |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 377 | pneumatics_to_log_sender_( |
| 378 | event_loop->MakeSender<::frc971::wpilib::PneumaticsToLog>("/aos")), |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 379 | drivetrain_( |
| 380 | event_loop |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 381 | ->MakeFetcher<::frc971::control_loops::drivetrain::Output>( |
| 382 | "/drivetrain")), |
| 383 | shooter_(event_loop->MakeFetcher<shooter::Output>("/shooter")), |
| 384 | superstructure_( |
| 385 | event_loop |
| 386 | ->MakeFetcher<::y2016::control_loops::superstructure::Output>( |
| 387 | "/superstructure")) { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 388 | event_loop->set_name("Solenoids"); |
| 389 | event_loop->SetRuntimeRealtimePriority(27); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 390 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 391 | event_loop->OnRun([this]() { compressor_->Start(); }); |
| 392 | |
| 393 | event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); }, |
| 394 | ::std::chrono::milliseconds(20), |
| 395 | ::std::chrono::milliseconds(1)); |
| 396 | } |
| 397 | |
| 398 | void set_compressor(::std::unique_ptr<::frc::Compressor> compressor) { |
Campbell Crowley | 1ab5fab | 2016-02-21 13:39:31 -0800 | [diff] [blame] | 399 | compressor_ = ::std::move(compressor); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 402 | void set_drivetrain_shifter( |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 403 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 404 | drivetrain_shifter_ = ::std::move(s); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 407 | void set_climber_trigger( |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 408 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 409 | climber_trigger_ = ::std::move(s); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 412 | void set_traverse(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 413 | traverse_ = ::std::move(s); |
| 414 | } |
| 415 | |
| 416 | void set_traverse_latch( |
| 417 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 418 | traverse_latch_ = ::std::move(s); |
| 419 | } |
| 420 | |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 421 | void set_shooter_clamp( |
| 422 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 423 | shooter_clamp_ = ::std::move(s); |
| 424 | } |
| 425 | |
| 426 | void set_shooter_pusher( |
| 427 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 428 | shooter_pusher_ = ::std::move(s); |
| 429 | } |
| 430 | |
Sabina Davis | 2243cab | 2019-02-05 21:45:08 -0800 | [diff] [blame] | 431 | void set_lights(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Austin Schuh | e0729a6 | 2016-03-12 21:54:17 -0800 | [diff] [blame] | 432 | lights_ = ::std::move(s); |
| 433 | } |
| 434 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 435 | void set_flashlight(::std::unique_ptr<::frc::Relay> relay) { |
Austin Schuh | 8b89d33 | 2016-03-24 20:19:12 -0700 | [diff] [blame] | 436 | flashlight_ = ::std::move(relay); |
| 437 | } |
| 438 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 439 | private: |
| 440 | void Loop(const int iterations) { |
| 441 | if (iterations != 1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 442 | AOS_LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 443 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 444 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 445 | { |
| 446 | drivetrain_.Fetch(); |
| 447 | if (drivetrain_.get()) { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 448 | drivetrain_shifter_->Set( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 449 | !(drivetrain_->left_high() || drivetrain_->right_high())); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 450 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 451 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 452 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 453 | { |
| 454 | shooter_.Fetch(); |
| 455 | if (shooter_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 456 | shooter_clamp_->Set(shooter_->clamp_open()); |
| 457 | shooter_pusher_->Set(shooter_->push_to_shooter()); |
| 458 | lights_->Set(shooter_->lights_on()); |
| 459 | if (shooter_->forwards_flashlight()) { |
| 460 | if (shooter_->backwards_flashlight()) { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 461 | flashlight_->Set(::frc::Relay::kOn); |
Austin Schuh | b2c3338 | 2016-04-03 16:09:17 -0700 | [diff] [blame] | 462 | } else { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 463 | flashlight_->Set(::frc::Relay::kReverse); |
| 464 | } |
| 465 | } else { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 466 | if (shooter_->backwards_flashlight()) { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 467 | flashlight_->Set(::frc::Relay::kForward); |
| 468 | } else { |
| 469 | flashlight_->Set(::frc::Relay::kOff); |
Austin Schuh | b2c3338 | 2016-04-03 16:09:17 -0700 | [diff] [blame] | 470 | } |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 471 | } |
| 472 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 473 | } |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 474 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 475 | { |
| 476 | superstructure_.Fetch(); |
| 477 | if (superstructure_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 478 | climber_trigger_->Set(superstructure_->unfold_climber()); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 479 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 480 | traverse_->Set(superstructure_->traverse_down()); |
| 481 | traverse_latch_->Set(superstructure_->traverse_unlatched()); |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 482 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 483 | } |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 484 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 485 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 486 | auto builder = pneumatics_to_log_sender_.MakeBuilder(); |
| 487 | |
| 488 | ::frc971::wpilib::PneumaticsToLog::Builder to_log_builder = |
| 489 | builder.MakeBuilder<frc971::wpilib::PneumaticsToLog>(); |
| 490 | |
| 491 | to_log_builder.add_compressor_on(compressor_->Enabled()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 492 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 493 | pcm_->Flush(); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 494 | to_log_builder.add_read_solenoids(pcm_->GetAll()); |
| 495 | builder.Send(to_log_builder.Finish()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 499 | ::frc971::wpilib::BufferedPcm *pcm_; |
| 500 | aos::Sender<::frc971::wpilib::PneumaticsToLog> pneumatics_to_log_sender_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 501 | |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 502 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_shifter_, |
| 503 | shooter_clamp_, shooter_pusher_, lights_, traverse_, traverse_latch_, |
| 504 | climber_trigger_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 505 | ::std::unique_ptr<::frc::Relay> flashlight_; |
| 506 | ::std::unique_ptr<::frc::Compressor> compressor_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 507 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 508 | ::aos::Fetcher<::frc971::control_loops::drivetrain::Output> drivetrain_; |
| 509 | ::aos::Fetcher<shooter::Output> shooter_; |
| 510 | ::aos::Fetcher<::y2016::control_loops::superstructure::Output> |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 511 | superstructure_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 512 | }; |
| 513 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 514 | class ShooterWriter : public LoopOutputHandler<shooter::Output> { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 515 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 516 | ShooterWriter(::aos::EventLoop *event_loop) |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 517 | : LoopOutputHandler<shooter::Output>(event_loop, "/shooter") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 518 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 519 | void set_shooter_left_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 520 | shooter_left_talon_ = ::std::move(t); |
| 521 | } |
| 522 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 523 | void set_shooter_right_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 524 | shooter_right_talon_ = ::std::move(t); |
| 525 | } |
| 526 | |
| 527 | private: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 528 | void Write(const shooter::Output &output) override { |
| 529 | shooter_left_talon_->SetSpeed(output.voltage_left() / 12.0); |
| 530 | shooter_right_talon_->SetSpeed(-output.voltage_right() / 12.0); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 533 | void Stop() override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 534 | AOS_LOG(WARNING, "Shooter output too old.\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 535 | shooter_left_talon_->SetDisabled(); |
| 536 | shooter_right_talon_->SetDisabled(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 539 | ::std::unique_ptr<::frc::Talon> shooter_left_talon_, shooter_right_talon_; |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 540 | }; |
| 541 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 542 | class SuperstructureWriter : public LoopOutputHandler<superstructure::Output> { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 543 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 544 | SuperstructureWriter(::aos::EventLoop *event_loop) |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 545 | : LoopOutputHandler<superstructure::Output>(event_loop, |
| 546 | "/superstructure") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 547 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 548 | void set_intake_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 549 | intake_talon_ = ::std::move(t); |
| 550 | } |
| 551 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 552 | void set_shoulder_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 553 | shoulder_talon_ = ::std::move(t); |
| 554 | } |
| 555 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 556 | void set_wrist_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 557 | wrist_talon_ = ::std::move(t); |
| 558 | } |
| 559 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 560 | void set_top_rollers_talon(::std::unique_ptr<::frc::Talon> t) { |
Campbell Crowley | d4fd655 | 2016-02-21 17:53:46 -0800 | [diff] [blame] | 561 | top_rollers_talon_ = ::std::move(t); |
| 562 | } |
| 563 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 564 | void set_bottom_rollers_talon(::std::unique_ptr<::frc::Talon> t) { |
Campbell Crowley | d4fd655 | 2016-02-21 17:53:46 -0800 | [diff] [blame] | 565 | bottom_rollers_talon_ = ::std::move(t); |
Comran Morshed | f4cd764 | 2016-02-15 20:40:49 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 568 | void set_climber_talon(::std::unique_ptr<::frc::Talon> t) { |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 569 | climber_talon_ = ::std::move(t); |
| 570 | } |
| 571 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 572 | private: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 573 | virtual void Write(const superstructure::Output &output) override { |
| 574 | intake_talon_->SetSpeed(::aos::Clip(output.voltage_intake(), |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 575 | -kMaxBringupPower, kMaxBringupPower) / |
| 576 | 12.0); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 577 | shoulder_talon_->SetSpeed(::aos::Clip(-output.voltage_shoulder(), |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 578 | -kMaxBringupPower, kMaxBringupPower) / |
| 579 | 12.0); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 580 | wrist_talon_->SetSpeed(::aos::Clip(output.voltage_wrist(), |
| 581 | -kMaxBringupPower, kMaxBringupPower) / |
| 582 | 12.0); |
| 583 | top_rollers_talon_->SetSpeed(-output.voltage_top_rollers() / 12.0); |
| 584 | bottom_rollers_talon_->SetSpeed(-output.voltage_bottom_rollers() / 12.0); |
| 585 | climber_talon_->SetSpeed(-output.voltage_climber() / 12.0); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | virtual void Stop() override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 589 | AOS_LOG(WARNING, "Superstructure output too old.\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 590 | intake_talon_->SetDisabled(); |
| 591 | shoulder_talon_->SetDisabled(); |
| 592 | wrist_talon_->SetDisabled(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 595 | ::std::unique_ptr<::frc::Talon> intake_talon_, shoulder_talon_, wrist_talon_, |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 596 | top_rollers_talon_, bottom_rollers_talon_, climber_talon_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 597 | }; |
| 598 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 599 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 600 | public: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 601 | ::std::unique_ptr<::frc::Encoder> make_encoder(int index) { |
| 602 | return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false, |
| 603 | ::frc::Encoder::k4X); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | void Run() override { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 607 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 608 | aos::configuration::ReadConfig("config.json"); |
| 609 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 610 | // Thread 1. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 611 | ::aos::ShmEventLoop joystick_sender_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 612 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 613 | &joystick_sender_event_loop); |
| 614 | AddLoop(&joystick_sender_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 615 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 616 | // Thread 2. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 617 | ::aos::ShmEventLoop pdp_fetcher_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 618 | ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop); |
| 619 | AddLoop(&pdp_fetcher_event_loop); |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 620 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 621 | // Thread 3. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 622 | ::aos::ShmEventLoop sensor_reader_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 623 | SensorReader sensor_reader(&sensor_reader_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 624 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 625 | sensor_reader.set_drivetrain_left_encoder(make_encoder(5)); |
| 626 | sensor_reader.set_drivetrain_right_encoder(make_encoder(6)); |
| 627 | sensor_reader.set_drivetrain_left_hall(make_unique<::frc::AnalogInput>(5)); |
| 628 | sensor_reader.set_drivetrain_right_hall(make_unique<::frc::AnalogInput>(6)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 629 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 630 | sensor_reader.set_shooter_left_encoder(make_encoder(7)); |
| 631 | sensor_reader.set_shooter_right_encoder(make_encoder(-3)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 632 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 633 | sensor_reader.set_intake_encoder(make_encoder(0)); |
| 634 | sensor_reader.set_intake_index(make_unique<::frc::DigitalInput>(0)); |
| 635 | sensor_reader.set_intake_potentiometer(make_unique<::frc::AnalogInput>(0)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 636 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 637 | sensor_reader.set_shoulder_encoder(make_encoder(4)); |
| 638 | sensor_reader.set_shoulder_index(make_unique<::frc::DigitalInput>(2)); |
| 639 | sensor_reader.set_shoulder_potentiometer( |
| 640 | make_unique<::frc::AnalogInput>(2)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 641 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 642 | sensor_reader.set_wrist_encoder(make_encoder(1)); |
| 643 | sensor_reader.set_wrist_index(make_unique<::frc::DigitalInput>(1)); |
| 644 | sensor_reader.set_wrist_potentiometer(make_unique<::frc::AnalogInput>(1)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 645 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 646 | sensor_reader.set_ball_detector(make_unique<::frc::AnalogInput>(7)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 647 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 648 | sensor_reader.set_autonomous_mode(0, make_unique<::frc::DigitalInput>(9)); |
| 649 | sensor_reader.set_autonomous_mode(1, make_unique<::frc::DigitalInput>(8)); |
| 650 | sensor_reader.set_autonomous_mode(2, make_unique<::frc::DigitalInput>(7)); |
| 651 | sensor_reader.set_autonomous_mode(3, make_unique<::frc::DigitalInput>(6)); |
| 652 | AddLoop(&sensor_reader_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 653 | |
Brian Silverman | 003a473 | 2018-03-11 14:02:15 -0700 | [diff] [blame] | 654 | // TODO(Brian): This interacts poorly with the SpiRxClearer in ADIS16448. |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 655 | // Thread 4. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 656 | ::aos::ShmEventLoop gyro_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 657 | ::frc971::wpilib::GyroSender gyro_sender(&gyro_event_loop); |
| 658 | AddLoop(&gyro_event_loop); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 659 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 660 | // Thread 5. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 661 | ::aos::ShmEventLoop imu_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 662 | auto imu_trigger = make_unique<::frc::DigitalInput>(3); |
| 663 | ::frc971::wpilib::ADIS16448 imu(&imu_event_loop, ::frc::SPI::Port::kMXP, |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 664 | imu_trigger.get()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 665 | AddLoop(&imu_event_loop); |
Brian Silverman | 5f17a97 | 2016-02-28 01:49:32 -0500 | [diff] [blame] | 666 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 667 | // Thread 5. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 668 | ::aos::ShmEventLoop output_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 669 | ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop); |
Sabina Davis | b71bc28 | 2019-02-03 01:17:23 -0800 | [diff] [blame] | 670 | drivetrain_writer.set_left_controller0( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 671 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), false); |
Sabina Davis | b71bc28 | 2019-02-03 01:17:23 -0800 | [diff] [blame] | 672 | drivetrain_writer.set_right_controller0( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 673 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)), true); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 674 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 675 | ShooterWriter shooter_writer(&output_event_loop); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 676 | shooter_writer.set_shooter_left_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 677 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(9))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 678 | shooter_writer.set_shooter_right_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 679 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(8))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 680 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 681 | SuperstructureWriter superstructure_writer(&output_event_loop); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 682 | superstructure_writer.set_intake_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 683 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 684 | superstructure_writer.set_shoulder_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 685 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 686 | superstructure_writer.set_wrist_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 687 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2))); |
Campbell Crowley | d4fd655 | 2016-02-21 17:53:46 -0800 | [diff] [blame] | 688 | superstructure_writer.set_top_rollers_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 689 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1))); |
Austin Schuh | caa1ee9 | 2016-02-27 14:45:37 -0800 | [diff] [blame] | 690 | superstructure_writer.set_bottom_rollers_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 691 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(0))); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 692 | superstructure_writer.set_climber_talon( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 693 | ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 694 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 695 | AddLoop(&output_event_loop); |
| 696 | |
| 697 | // Thread 6. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 698 | ::aos::ShmEventLoop solenoid_writer_event_loop(&config.message()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 699 | ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm( |
| 700 | new ::frc971::wpilib::BufferedPcm()); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 701 | SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm.get()); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 702 | solenoid_writer.set_drivetrain_shifter(pcm->MakeSolenoid(0)); |
Austin Schuh | 843412b | 2016-03-20 16:48:46 -0700 | [diff] [blame] | 703 | solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2)); |
| 704 | solenoid_writer.set_traverse(pcm->MakeSolenoid(3)); |
Austin Schuh | caa1ee9 | 2016-02-27 14:45:37 -0800 | [diff] [blame] | 705 | solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(4)); |
| 706 | solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(5)); |
Austin Schuh | e0729a6 | 2016-03-12 21:54:17 -0800 | [diff] [blame] | 707 | solenoid_writer.set_lights(pcm->MakeSolenoid(6)); |
Comran Morshed | 71466fe | 2016-04-21 20:21:14 -0700 | [diff] [blame] | 708 | solenoid_writer.set_climber_trigger(pcm->MakeSolenoid(1)); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 709 | solenoid_writer.set_flashlight(make_unique<::frc::Relay>(0)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 710 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 711 | solenoid_writer.set_compressor(make_unique<::frc::Compressor>()); |
| 712 | AddLoop(&solenoid_writer_event_loop); |
Campbell Crowley | 1ab5fab | 2016-02-21 13:39:31 -0800 | [diff] [blame] | 713 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 714 | RunLoops(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 715 | } |
| 716 | }; |
| 717 | |
| 718 | } // namespace wpilib |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 719 | } // namespace y2016 |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 720 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 721 | AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot); |