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