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