Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <array> |
| 4 | #include <chrono> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 5 | #include <cinttypes> |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 6 | #include <cmath> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 7 | #include <cstdio> |
| 8 | #include <cstring> |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 9 | #include <functional> |
Vinay Siva | e52a6b3 | 2021-07-10 15:19:26 -0700 | [diff] [blame] | 10 | #include <memory> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 11 | #include <thread> |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 12 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 13 | #include "ctre/phoenix/CANifier.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 14 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 15 | #include "frc971/wpilib/ahal/AnalogInput.h" |
Austin Schuh | 9950f68 | 2021-11-06 15:27:58 -0700 | [diff] [blame] | 16 | #include "frc971/wpilib/ahal/Compressor.h" |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 17 | #include "frc971/wpilib/ahal/Counter.h" |
| 18 | #include "frc971/wpilib/ahal/DigitalGlitchFilter.h" |
| 19 | #include "frc971/wpilib/ahal/DriverStation.h" |
| 20 | #include "frc971/wpilib/ahal/Encoder.h" |
| 21 | #include "frc971/wpilib/ahal/Relay.h" |
| 22 | #include "frc971/wpilib/ahal/Servo.h" |
| 23 | #include "frc971/wpilib/ahal/VictorSP.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 24 | #undef ERROR |
| 25 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 26 | #include "aos/commonmath.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 27 | #include "aos/events/shm_event_loop.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 28 | #include "aos/init.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 29 | #include "aos/logging/logging.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 30 | #include "aos/time/time.h" |
| 31 | #include "aos/util/compiler_memory_barrier.h" |
| 32 | #include "aos/util/log_interval.h" |
| 33 | #include "aos/util/phased_loop.h" |
| 34 | #include "aos/util/wrapping_counter.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 35 | #include "frc971/control_loops/drivetrain/drivetrain_output_generated.h" |
| 36 | #include "frc971/control_loops/drivetrain/drivetrain_position_generated.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 37 | #include "frc971/wpilib/ADIS16448.h" |
| 38 | #include "frc971/wpilib/buffered_pcm.h" |
| 39 | #include "frc971/wpilib/buffered_solenoid.h" |
| 40 | #include "frc971/wpilib/dma.h" |
| 41 | #include "frc971/wpilib/dma_edge_counting.h" |
Sabina Davis | caa2a6b | 2019-02-03 01:15:37 -0800 | [diff] [blame] | 42 | #include "frc971/wpilib/drivetrain_writer.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 43 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 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 | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 46 | #include "frc971/wpilib/loop_output_handler.h" |
| 47 | #include "frc971/wpilib/pdp_fetcher.h" |
Austin Schuh | 6abf5b7 | 2019-02-02 20:20:54 -0800 | [diff] [blame] | 48 | #include "frc971/wpilib/sensor_reader.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 49 | #include "frc971/wpilib/wpilib_robot_base.h" |
| 50 | #include "y2018/constants.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 51 | #include "y2018/control_loops/superstructure/superstructure_output_generated.h" |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 52 | #include "y2018/control_loops/superstructure/superstructure_position_static.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 53 | #include "y2018/status_light_generated.h" |
| 54 | #include "y2018/vision/vision_generated.h" |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 55 | |
| 56 | #ifndef M_PI |
| 57 | #define M_PI 3.14159265358979323846 |
| 58 | #endif |
| 59 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 60 | using ::aos::monotonic_clock; |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 61 | using std::make_unique; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 62 | using ::y2018::constants::Values; |
| 63 | namespace chrono = ::std::chrono; |
| 64 | namespace superstructure = ::y2018::control_loops::superstructure; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 65 | |
| 66 | namespace y2018 { |
| 67 | namespace wpilib { |
| 68 | namespace { |
| 69 | |
| 70 | constexpr double kMaxBringupPower = 12.0; |
| 71 | |
| 72 | // TODO(Brian): Fix the interpretation of the result of GetRaw here and in the |
| 73 | // DMA stuff and then removing the * 2.0 in *_translate. |
| 74 | // The low bit is direction. |
| 75 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 76 | // TODO(brian): Use ::std::max instead once we have C++14 so that can be |
| 77 | // constexpr. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 78 | template <typename T> |
| 79 | constexpr T max(T a, T b) { |
| 80 | return (a > b) ? a : b; |
| 81 | } |
| 82 | |
| 83 | template <typename T, typename... Rest> |
| 84 | constexpr T max(T a, T b, T c, Rest... rest) { |
| 85 | return max(max(a, b), c, rest...); |
| 86 | } |
| 87 | |
| 88 | double drivetrain_translate(int32_t in) { |
Austin Schuh | e8a54c0 | 2018-03-05 00:25:58 -0800 | [diff] [blame] | 89 | return ((static_cast<double>(in) / |
| 90 | Values::kDrivetrainEncoderCountsPerRevolution()) * |
| 91 | (2.0 * M_PI)) * |
| 92 | Values::kDrivetrainEncoderRatio() * |
| 93 | control_loops::drivetrain::kWheelRadius; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | double drivetrain_velocity_translate(double in) { |
Austin Schuh | e8a54c0 | 2018-03-05 00:25:58 -0800 | [diff] [blame] | 97 | return (((1.0 / in) / Values::kDrivetrainCyclesPerRevolution()) * |
| 98 | (2.0 * M_PI)) * |
| 99 | Values::kDrivetrainEncoderRatio() * |
| 100 | control_loops::drivetrain::kWheelRadius; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | double proximal_pot_translate(double voltage) { |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 104 | return -voltage * Values::kProximalPotRatio() * |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 105 | (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
| 106 | } |
| 107 | |
| 108 | double distal_pot_translate(double voltage) { |
| 109 | return voltage * Values::kDistalPotRatio() * |
| 110 | (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
| 111 | } |
| 112 | |
| 113 | double intake_pot_translate(double voltage) { |
| 114 | return voltage * Values::kIntakeMotorPotRatio() * |
| 115 | (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
| 116 | } |
| 117 | |
| 118 | double intake_spring_translate(double voltage) { |
| 119 | return voltage * Values::kIntakeSpringRatio() * (2 * M_PI /*radians*/) / |
| 120 | (5.0 /*volts*/); |
| 121 | } |
| 122 | |
| 123 | // TODO() figure out differnce between max and min voltages on shifter pots. |
| 124 | // Returns value from 0.0 to 1.0, with 0.0 being close to low gear so it can be |
| 125 | // passed drectly into the drivetrain position queue. |
| 126 | double drivetrain_shifter_pot_translate(double voltage) { |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 127 | return (voltage - Values::kDrivetrainShifterPotMinVoltage()) / |
| 128 | (Values::kDrivetrainShifterPotMaxVoltage() - |
| 129 | Values::kDrivetrainShifterPotMinVoltage()); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | constexpr double kMaxFastEncoderPulsesPerSecond = |
| 133 | max(Values::kMaxDrivetrainEncoderPulsesPerSecond(), |
| 134 | Values::kMaxIntakeMotorEncoderPulsesPerSecond()); |
| 135 | static_assert(kMaxFastEncoderPulsesPerSecond <= 1300000, |
| 136 | "fast encoders are too fast"); |
| 137 | |
| 138 | constexpr double kMaxMediumEncoderPulsesPerSecond = |
| 139 | max(Values::kMaxProximalEncoderPulsesPerSecond(), |
| 140 | Values::kMaxDistalEncoderPulsesPerSecond()); |
| 141 | static_assert(kMaxMediumEncoderPulsesPerSecond <= 400000, |
| 142 | "medium encoders are too fast"); |
| 143 | |
| 144 | // Class to send position messages with sensor readings to our loops. |
Austin Schuh | 6abf5b7 | 2019-02-02 20:20:54 -0800 | [diff] [blame] | 145 | class SensorReader : public ::frc971::wpilib::SensorReader { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 146 | public: |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 147 | SensorReader(::aos::ShmEventLoop *event_loop) |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 148 | : ::frc971::wpilib::SensorReader(event_loop), |
| 149 | superstructure_position_sender_( |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 150 | event_loop->MakeSender<superstructure::PositionStatic>( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 151 | "/superstructure")), |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 152 | drivetrain_position_sender_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 153 | event_loop |
| 154 | ->MakeSender<::frc971::control_loops::drivetrain::Position>( |
| 155 | "/drivetrain")) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 156 | // Set to filter out anything shorter than 1/4 of the minimum pulse width |
| 157 | // we should ever see. |
Austin Schuh | 6abf5b7 | 2019-02-02 20:20:54 -0800 | [diff] [blame] | 158 | UpdateFastEncoderFilterHz(kMaxFastEncoderPulsesPerSecond); |
| 159 | UpdateMediumEncoderFilterHz(kMaxMediumEncoderPulsesPerSecond); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void set_left_drivetrain_shifter_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 163 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 164 | left_drivetrain_shifter_ = ::std::move(potentiometer); |
| 165 | } |
| 166 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 167 | void set_right_drivetrain_shifter_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 168 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 169 | right_drivetrain_shifter_ = ::std::move(potentiometer); |
| 170 | } |
| 171 | |
| 172 | // Proximal joint. |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 173 | void set_proximal_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 174 | medium_encoder_filter_.Add(encoder.get()); |
| 175 | proximal_encoder_.set_encoder(::std::move(encoder)); |
| 176 | } |
| 177 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 178 | void set_proximal_absolute_pwm( |
| 179 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 180 | proximal_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 181 | } |
| 182 | |
| 183 | void set_proximal_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 184 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 185 | proximal_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 186 | } |
| 187 | |
| 188 | // Distal joint. |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 189 | void set_distal_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 190 | medium_encoder_filter_.Add(encoder.get()); |
| 191 | distal_encoder_.set_encoder(::std::move(encoder)); |
| 192 | } |
| 193 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 194 | void set_distal_absolute_pwm( |
| 195 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 196 | fast_encoder_filter_.Add(absolute_pwm.get()); |
| 197 | distal_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 198 | } |
| 199 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 200 | void set_distal_potentiometer( |
| 201 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 202 | distal_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 203 | } |
| 204 | |
| 205 | // Left intake side. |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 206 | void set_left_intake_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 207 | fast_encoder_filter_.Add(encoder.get()); |
| 208 | left_intake_encoder_.set_encoder(::std::move(encoder)); |
| 209 | } |
| 210 | |
| 211 | void set_left_intake_absolute_pwm( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 212 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 213 | fast_encoder_filter_.Add(absolute_pwm.get()); |
| 214 | left_intake_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 215 | } |
| 216 | |
| 217 | void set_left_intake_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 218 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 219 | left_intake_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 220 | } |
| 221 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 222 | void set_left_intake_spring_angle( |
| 223 | ::std::unique_ptr<frc::AnalogInput> encoder) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 224 | left_intake_spring_angle_ = ::std::move(encoder); |
| 225 | } |
| 226 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 227 | void set_left_intake_cube_detector( |
| 228 | ::std::unique_ptr<frc::DigitalInput> input) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 229 | left_intake_cube_detector_ = ::std::move(input); |
| 230 | } |
| 231 | |
| 232 | // Right intake side. |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 233 | void set_right_intake_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 234 | fast_encoder_filter_.Add(encoder.get()); |
| 235 | right_intake_encoder_.set_encoder(::std::move(encoder)); |
| 236 | } |
| 237 | |
| 238 | void set_right_intake_absolute_pwm( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 239 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 240 | fast_encoder_filter_.Add(absolute_pwm.get()); |
| 241 | right_intake_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 242 | } |
| 243 | |
| 244 | void set_right_intake_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 245 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 246 | right_intake_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 247 | } |
| 248 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 249 | void set_right_intake_spring_angle( |
| 250 | ::std::unique_ptr<frc::AnalogInput> encoder) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 251 | right_intake_spring_angle_ = ::std::move(encoder); |
| 252 | } |
| 253 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 254 | void set_right_intake_cube_detector( |
| 255 | ::std::unique_ptr<frc::DigitalInput> input) { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 256 | right_intake_cube_detector_ = ::std::move(input); |
| 257 | } |
| 258 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 259 | void set_claw_beambreak(::std::unique_ptr<frc::DigitalInput> input) { |
Austin Schuh | 4ef51af | 2018-03-04 01:08:45 -0800 | [diff] [blame] | 260 | claw_beambreak_ = ::std::move(input); |
| 261 | } |
| 262 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 263 | void set_box_back_beambreak(::std::unique_ptr<frc::DigitalInput> input) { |
Austin Schuh | 4ef51af | 2018-03-04 01:08:45 -0800 | [diff] [blame] | 264 | box_back_beambreak_ = ::std::move(input); |
| 265 | } |
| 266 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 267 | void set_lidar_lite_input( |
| 268 | ::std::unique_ptr<frc::DigitalInput> lidar_lite_input) { |
Austin Schuh | 8e5950d | 2018-03-21 20:29:40 -0700 | [diff] [blame] | 269 | lidar_lite_input_ = ::std::move(lidar_lite_input); |
| 270 | lidar_lite_.set_input(lidar_lite_input_.get()); |
| 271 | } |
| 272 | |
Austin Schuh | 6abf5b7 | 2019-02-02 20:20:54 -0800 | [diff] [blame] | 273 | void Start() { AddToDMA(&lidar_lite_); } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 274 | |
| 275 | void RunIteration() { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 276 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 277 | auto builder = drivetrain_position_sender_.MakeBuilder(); |
| 278 | frc971::control_loops::drivetrain::Position::Builder drivetrain_builder = |
| 279 | builder.MakeBuilder<frc971::control_loops::drivetrain::Position>(); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 280 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 281 | drivetrain_builder.add_left_encoder( |
| 282 | drivetrain_translate(drivetrain_left_encoder_->GetRaw())); |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 283 | drivetrain_builder.add_left_speed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 284 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod())); |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 285 | drivetrain_builder.add_left_shifter_position( |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 286 | drivetrain_shifter_pot_translate( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 287 | left_drivetrain_shifter_->GetVoltage())); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 288 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 289 | drivetrain_builder.add_right_encoder( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 290 | -drivetrain_translate(drivetrain_right_encoder_->GetRaw())); |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 291 | drivetrain_builder.add_right_speed(-drivetrain_velocity_translate( |
| 292 | drivetrain_right_encoder_->GetPeriod())); |
| 293 | drivetrain_builder.add_right_shifter_position( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 294 | drivetrain_shifter_pot_translate( |
| 295 | right_drivetrain_shifter_->GetVoltage())); |
| 296 | |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 297 | builder.CheckOk(builder.Send(drivetrain_builder.Finish())); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 298 | } |
Austin Schuh | 6abf5b7 | 2019-02-02 20:20:54 -0800 | [diff] [blame] | 299 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 300 | |
Austin Schuh | 6abf5b7 | 2019-02-02 20:20:54 -0800 | [diff] [blame] | 301 | void RunDmaIteration() { |
| 302 | const auto values = constants::GetValues(); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 303 | |
| 304 | { |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 305 | aos::Sender<superstructure::PositionStatic>::StaticBuilder builder = |
| 306 | superstructure_position_sender_.MakeStaticBuilder(); |
| 307 | |
| 308 | superstructure::ArmPositionStatic *arm_position = builder->add_arm(); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 309 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 310 | // Proximal arm |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 311 | CopyPosition(proximal_encoder_, arm_position->add_proximal(), |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 312 | Values::kProximalEncoderCountsPerRevolution(), |
| 313 | Values::kProximalEncoderRatio(), proximal_pot_translate, |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 314 | true, values.arm_proximal.potentiometer_offset); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 315 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 316 | // Distal arm |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 317 | CopyPosition(distal_encoder_, arm_position->add_distal(), |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 318 | Values::kDistalEncoderCountsPerRevolution(), |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 319 | Values::kDistalEncoderRatio(), distal_pot_translate, true, |
| 320 | values.arm_distal.potentiometer_offset); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 321 | |
| 322 | // Left intake |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 323 | superstructure::IntakeElasticSensorsStatic *left_intake = |
| 324 | builder->add_left_intake(); |
| 325 | |
| 326 | CopyPosition(left_intake_encoder_, left_intake->add_motor_position(), |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 327 | Values::kIntakeMotorEncoderCountsPerRevolution(), |
| 328 | Values::kIntakeMotorEncoderRatio(), intake_pot_translate, |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 329 | false, values.left_intake.potentiometer_offset); |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 330 | |
| 331 | left_intake->set_spring_angle( |
| 332 | intake_spring_translate(left_intake_spring_angle_->GetVoltage()) + |
| 333 | values.left_intake.spring_offset); |
| 334 | left_intake->set_beam_break(!left_intake_cube_detector_->Get()); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 335 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 336 | // Right intake |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 337 | superstructure::IntakeElasticSensorsStatic *right_intake = |
| 338 | builder->add_right_intake(); |
| 339 | CopyPosition(right_intake_encoder_, right_intake->add_motor_position(), |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 340 | Values::kIntakeMotorEncoderCountsPerRevolution(), |
| 341 | Values::kIntakeMotorEncoderRatio(), intake_pot_translate, |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 342 | true, values.right_intake.potentiometer_offset); |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 343 | right_intake->set_spring_angle( |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 344 | -intake_spring_translate(right_intake_spring_angle_->GetVoltage()) + |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 345 | values.right_intake.spring_offset); |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 346 | right_intake->set_beam_break(!right_intake_cube_detector_->Get()); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 347 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 348 | builder->set_claw_beambreak_triggered(!claw_beambreak_->Get()); |
| 349 | builder->set_box_back_beambreak_triggered(!box_back_beambreak_->Get()); |
Austin Schuh | 4ef51af | 2018-03-04 01:08:45 -0800 | [diff] [blame] | 350 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 351 | builder->set_box_distance(lidar_lite_.last_width() / 0.00001 / 100.0 / 2); |
Austin Schuh | 8e5950d | 2018-03-21 20:29:40 -0700 | [diff] [blame] | 352 | |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 353 | builder.CheckOk(builder.Send()); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 354 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 357 | private: |
Maxwell Henderson | cb78f35 | 2024-01-15 00:27:16 -0800 | [diff] [blame] | 358 | ::aos::Sender<superstructure::PositionStatic> superstructure_position_sender_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 359 | ::aos::Sender<::frc971::control_loops::drivetrain::Position> |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 360 | drivetrain_position_sender_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 361 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 362 | ::std::unique_ptr<frc::AnalogInput> left_drivetrain_shifter_, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 363 | right_drivetrain_shifter_; |
| 364 | |
| 365 | ::frc971::wpilib::AbsoluteEncoderAndPotentiometer proximal_encoder_, |
| 366 | distal_encoder_; |
| 367 | |
| 368 | ::frc971::wpilib::AbsoluteEncoderAndPotentiometer left_intake_encoder_, |
| 369 | right_intake_encoder_; |
| 370 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 371 | ::std::unique_ptr<frc::AnalogInput> left_intake_spring_angle_, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 372 | right_intake_spring_angle_; |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 373 | ::std::unique_ptr<frc::DigitalInput> left_intake_cube_detector_, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 374 | right_intake_cube_detector_; |
| 375 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 376 | ::std::unique_ptr<frc::DigitalInput> claw_beambreak_; |
| 377 | ::std::unique_ptr<frc::DigitalInput> box_back_beambreak_; |
Austin Schuh | 4ef51af | 2018-03-04 01:08:45 -0800 | [diff] [blame] | 378 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 379 | ::std::unique_ptr<frc::DigitalInput> lidar_lite_input_; |
Austin Schuh | 8e5950d | 2018-03-21 20:29:40 -0700 | [diff] [blame] | 380 | ::frc971::wpilib::DMAPulseWidthReader lidar_lite_; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | class SolenoidWriter { |
| 384 | public: |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 385 | SolenoidWriter(::aos::ShmEventLoop *event_loop, |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 386 | ::frc971::wpilib::BufferedPcm *pcm) |
| 387 | : event_loop_(event_loop), |
| 388 | drivetrain_fetcher_( |
| 389 | event_loop |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 390 | ->MakeFetcher<::frc971::control_loops::drivetrain::Output>( |
| 391 | "/drivetrain")), |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 392 | superstructure_fetcher_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 393 | event_loop->MakeFetcher<superstructure::Output>("/superstructure")), |
| 394 | status_light_fetcher_( |
| 395 | event_loop->MakeFetcher<::y2018::StatusLight>("/superstructure")), |
Austin Schuh | 300f2f6 | 2019-05-27 13:49:23 -0700 | [diff] [blame] | 396 | vision_status_fetcher_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 397 | event_loop->MakeFetcher<::y2018::vision::VisionStatus>("/vision")), |
| 398 | pneumatics_to_log_sender_( |
| 399 | event_loop->MakeSender<::frc971::wpilib::PneumaticsToLog>("/aos")), |
Austin Schuh | 9950f68 | 2021-11-06 15:27:58 -0700 | [diff] [blame] | 400 | pcm_(pcm), |
| 401 | compressor_(0) { |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 402 | event_loop->set_name("Solenoids"); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 403 | event_loop_->SetRuntimeRealtimePriority(27); |
| 404 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 405 | event_loop_->AddPhasedLoop([this](int iterations) { Loop(iterations); }, |
| 406 | ::std::chrono::milliseconds(20), |
| 407 | ::std::chrono::milliseconds(1)); |
| 408 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 409 | |
| 410 | // left drive |
| 411 | // right drive |
| 412 | // |
| 413 | // claw |
| 414 | // arm brakes |
| 415 | // hook release |
| 416 | // fork release |
| 417 | void set_left_drivetrain_shifter( |
| 418 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 419 | left_drivetrain_shifter_ = ::std::move(s); |
| 420 | } |
| 421 | void set_right_drivetrain_shifter( |
| 422 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 423 | right_drivetrain_shifter_ = ::std::move(s); |
| 424 | } |
| 425 | |
| 426 | void set_claw(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 427 | claw_ = ::std::move(s); |
| 428 | } |
| 429 | |
| 430 | void set_arm_brakes(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 431 | arm_brakes_ = ::std::move(s); |
| 432 | } |
| 433 | |
| 434 | void set_hook(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 435 | hook_ = ::std::move(s); |
| 436 | } |
| 437 | |
| 438 | void set_forks(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 439 | forks_ = ::std::move(s); |
| 440 | } |
| 441 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 442 | void Loop(const int iterations) { |
| 443 | if (iterations != 1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 444 | AOS_LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 445 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 446 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 447 | { |
| 448 | drivetrain_fetcher_.Fetch(); |
| 449 | if (drivetrain_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 450 | left_drivetrain_shifter_->Set(!drivetrain_fetcher_->left_high()); |
| 451 | right_drivetrain_shifter_->Set(!drivetrain_fetcher_->right_high()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 454 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 455 | { |
| 456 | superstructure_fetcher_.Fetch(); |
| 457 | if (superstructure_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 458 | claw_->Set(!superstructure_fetcher_->claw_grabbed()); |
| 459 | arm_brakes_->Set(superstructure_fetcher_->release_arm_brake()); |
| 460 | hook_->Set(superstructure_fetcher_->hook_release()); |
| 461 | forks_->Set(superstructure_fetcher_->forks_release()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 466 | auto builder = pneumatics_to_log_sender_.MakeBuilder(); |
| 467 | |
| 468 | ::frc971::wpilib::PneumaticsToLog::Builder to_log_builder = |
| 469 | builder.MakeBuilder<frc971::wpilib::PneumaticsToLog>(); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 470 | |
| 471 | pcm_->Flush(); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 472 | to_log_builder.add_read_solenoids(pcm_->GetAll()); |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 473 | (void)builder.Send(to_log_builder.Finish()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | monotonic_clock::time_point monotonic_now = event_loop_->monotonic_now(); |
| 477 | status_light_fetcher_.Fetch(); |
| 478 | // If we don't have a light request (or it's an old one), we are borked. |
| 479 | // Flash the red light slowly. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 480 | StatusLightT color; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 481 | if (!status_light_fetcher_.get() || |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 482 | monotonic_now > status_light_fetcher_.context().monotonic_event_time + |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 483 | chrono::milliseconds(100)) { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 484 | color.red = 0.0; |
| 485 | color.green = 0.0; |
| 486 | color.blue = 0.0; |
| 487 | |
| 488 | vision_status_fetcher_.Fetch(); |
| 489 | ++light_flash_; |
| 490 | if (light_flash_ > 10) { |
| 491 | color.red = 0.5; |
| 492 | } else if (!vision_status_fetcher_.get() || |
| 493 | monotonic_now > |
Austin Schuh | ad15482 | 2019-12-27 15:45:13 -0800 | [diff] [blame] | 494 | vision_status_fetcher_.context().monotonic_event_time + |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 495 | chrono::seconds(1)) { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 496 | color.red = 0.5; |
| 497 | color.green = 0.5; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 500 | if (light_flash_ > 20) { |
| 501 | light_flash_ = 0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 502 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 503 | } else { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 504 | status_light_fetcher_->UnPackTo(&color); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 505 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 506 | SetColor(color); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 509 | void SetColor(const StatusLightT &status_light) { |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 510 | // Save CAN bandwidth and CPU at the cost of RT. Only change the light when |
| 511 | // it actually changes. This is pretty low priority anyways. |
| 512 | static int time_since_last_send = 0; |
| 513 | ++time_since_last_send; |
| 514 | if (time_since_last_send > 10) { |
| 515 | time_since_last_send = 0; |
| 516 | } |
| 517 | if (status_light.green != last_green_ || time_since_last_send == 0) { |
| 518 | canifier_.SetLEDOutput(1.0 - status_light.green, |
| 519 | ::ctre::phoenix::CANifier::LEDChannelB); |
| 520 | last_green_ = status_light.green; |
| 521 | } |
| 522 | |
| 523 | if (status_light.blue != last_blue_ || time_since_last_send == 0) { |
| 524 | canifier_.SetLEDOutput(1.0 - status_light.blue, |
| 525 | ::ctre::phoenix::CANifier::LEDChannelA); |
| 526 | last_blue_ = status_light.blue; |
| 527 | } |
| 528 | |
| 529 | if (status_light.red != last_red_ || time_since_last_send == 0) { |
| 530 | canifier_.SetLEDOutput(1.0 - status_light.red, |
| 531 | ::ctre::phoenix::CANifier::LEDChannelC); |
| 532 | last_red_ = status_light.red; |
| 533 | } |
| 534 | } |
| 535 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 536 | void Quit() { run_ = false; } |
| 537 | |
| 538 | private: |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 539 | ::aos::EventLoop *event_loop_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 540 | ::aos::Fetcher<::frc971::control_loops::drivetrain::Output> |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 541 | drivetrain_fetcher_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 542 | ::aos::Fetcher<superstructure::Output> superstructure_fetcher_; |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 543 | ::aos::Fetcher<::y2018::StatusLight> status_light_fetcher_; |
Austin Schuh | 300f2f6 | 2019-05-27 13:49:23 -0700 | [diff] [blame] | 544 | ::aos::Fetcher<::y2018::vision::VisionStatus> vision_status_fetcher_; |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 545 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 546 | aos::Sender<::frc971::wpilib::PneumaticsToLog> pneumatics_to_log_sender_; |
| 547 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 548 | ::frc971::wpilib::BufferedPcm *pcm_; |
| 549 | |
| 550 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> |
| 551 | left_drivetrain_shifter_, right_drivetrain_shifter_, claw_, arm_brakes_, |
| 552 | hook_, forks_; |
| 553 | |
Brian Silverman | 37281fc | 2018-03-11 18:42:17 -0700 | [diff] [blame] | 554 | ::ctre::phoenix::CANifier canifier_{0}; |
| 555 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 556 | ::std::atomic<bool> run_{true}; |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 557 | |
| 558 | double last_red_ = -1.0; |
| 559 | double last_green_ = -1.0; |
| 560 | double last_blue_ = -1.0; |
| 561 | |
Austin Schuh | 9950f68 | 2021-11-06 15:27:58 -0700 | [diff] [blame] | 562 | frc::Compressor compressor_; |
| 563 | |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 564 | int light_flash_ = 0; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 565 | }; |
| 566 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 567 | class SuperstructureWriter |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 568 | : public ::frc971::wpilib::LoopOutputHandler<superstructure::Output> { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 569 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 570 | SuperstructureWriter(::aos::EventLoop *event_loop) |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 571 | : ::frc971::wpilib::LoopOutputHandler<superstructure::Output>( |
| 572 | event_loop, "/superstructure") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 573 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 574 | void set_proximal_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 575 | proximal_victor_ = ::std::move(t); |
| 576 | } |
| 577 | void set_distal_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 578 | distal_victor_ = ::std::move(t); |
| 579 | } |
| 580 | |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 581 | void set_hanger_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 582 | hanger_victor_ = ::std::move(t); |
| 583 | } |
| 584 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 585 | void set_left_intake_elastic_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 586 | left_intake_elastic_victor_ = ::std::move(t); |
| 587 | } |
| 588 | void set_right_intake_elastic_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 589 | right_intake_elastic_victor_ = ::std::move(t); |
| 590 | } |
| 591 | |
| 592 | void set_left_intake_rollers_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 593 | left_intake_rollers_victor_ = ::std::move(t); |
| 594 | } |
| 595 | |
| 596 | void set_right_intake_rollers_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 597 | right_intake_rollers_victor_ = ::std::move(t); |
| 598 | } |
| 599 | |
| 600 | private: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 601 | virtual void Write(const superstructure::Output &output) override { |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 602 | left_intake_elastic_victor_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 603 | ::aos::Clip(-output.left_intake()->voltage_elastic(), -kMaxBringupPower, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 604 | kMaxBringupPower) / |
| 605 | 12.0); |
| 606 | |
| 607 | right_intake_elastic_victor_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 608 | ::aos::Clip(output.right_intake()->voltage_elastic(), -kMaxBringupPower, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 609 | kMaxBringupPower) / |
| 610 | 12.0); |
| 611 | |
| 612 | left_intake_rollers_victor_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 613 | ::aos::Clip(-output.left_intake()->voltage_rollers(), -kMaxBringupPower, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 614 | kMaxBringupPower) / |
| 615 | 12.0); |
| 616 | |
| 617 | right_intake_rollers_victor_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 618 | ::aos::Clip(output.right_intake()->voltage_rollers(), -kMaxBringupPower, |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 619 | kMaxBringupPower) / |
| 620 | 12.0); |
| 621 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 622 | proximal_victor_->SetSpeed(::aos::Clip(-output.voltage_proximal(), |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 623 | -kMaxBringupPower, |
| 624 | kMaxBringupPower) / |
| 625 | 12.0); |
| 626 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 627 | distal_victor_->SetSpeed(::aos::Clip(output.voltage_distal(), |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 628 | -kMaxBringupPower, kMaxBringupPower) / |
| 629 | 12.0); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 630 | hanger_victor_->SetSpeed(::aos::Clip(-output.voltage_winch(), |
| 631 | -kMaxBringupPower, kMaxBringupPower) / |
| 632 | 12.0); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | virtual void Stop() override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 636 | AOS_LOG(WARNING, "Superstructure output too old.\n"); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 637 | |
| 638 | left_intake_rollers_victor_->SetDisabled(); |
| 639 | right_intake_rollers_victor_->SetDisabled(); |
| 640 | left_intake_elastic_victor_->SetDisabled(); |
| 641 | right_intake_elastic_victor_->SetDisabled(); |
| 642 | |
| 643 | proximal_victor_->SetDisabled(); |
| 644 | distal_victor_->SetDisabled(); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 645 | hanger_victor_->SetDisabled(); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | ::std::unique_ptr<::frc::VictorSP> left_intake_rollers_victor_, |
| 649 | right_intake_rollers_victor_, left_intake_elastic_victor_, |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 650 | right_intake_elastic_victor_, proximal_victor_, distal_victor_, |
| 651 | hanger_victor_; |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 652 | }; |
| 653 | |
| 654 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 655 | public: |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 656 | ::std::unique_ptr<frc::Encoder> make_encoder(int index) { |
| 657 | return make_unique<frc::Encoder>(10 + index * 2, 11 + index * 2, false, |
| 658 | frc::Encoder::k4X); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | void Run() override { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 662 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 663 | aos::configuration::ReadConfig("aos_config.json"); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 664 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 665 | // Thread 1. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 666 | ::aos::ShmEventLoop joystick_sender_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 667 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 668 | &joystick_sender_event_loop); |
| 669 | AddLoop(&joystick_sender_event_loop); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 670 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 671 | // Thread 2. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 672 | ::aos::ShmEventLoop pdp_fetcher_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 673 | ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop); |
| 674 | AddLoop(&pdp_fetcher_event_loop); |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 675 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 676 | // Thread 3. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 677 | ::aos::ShmEventLoop sensor_reader_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 678 | SensorReader sensor_reader(&sensor_reader_event_loop); |
| 679 | sensor_reader.set_drivetrain_left_encoder(make_encoder(0)); |
| 680 | sensor_reader.set_left_drivetrain_shifter_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 681 | make_unique<frc::AnalogInput>(6)); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 682 | sensor_reader.set_drivetrain_right_encoder(make_encoder(1)); |
| 683 | sensor_reader.set_right_drivetrain_shifter_potentiometer( |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 684 | make_unique<frc::AnalogInput>(7)); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 685 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 686 | sensor_reader.set_proximal_encoder(make_encoder(4)); |
| 687 | sensor_reader.set_proximal_absolute_pwm(make_unique<frc::DigitalInput>(2)); |
| 688 | sensor_reader.set_proximal_potentiometer(make_unique<frc::AnalogInput>(2)); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 689 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 690 | sensor_reader.set_distal_encoder(make_encoder(2)); |
| 691 | sensor_reader.set_distal_absolute_pwm(make_unique<frc::DigitalInput>(3)); |
| 692 | sensor_reader.set_distal_potentiometer(make_unique<frc::AnalogInput>(3)); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 693 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 694 | sensor_reader.set_right_intake_encoder(make_encoder(5)); |
| 695 | sensor_reader.set_right_intake_absolute_pwm( |
| 696 | make_unique<frc::DigitalInput>(7)); |
| 697 | sensor_reader.set_right_intake_potentiometer( |
| 698 | make_unique<frc::AnalogInput>(1)); |
| 699 | sensor_reader.set_right_intake_spring_angle( |
| 700 | make_unique<frc::AnalogInput>(5)); |
| 701 | sensor_reader.set_right_intake_cube_detector( |
| 702 | make_unique<frc::DigitalInput>(1)); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 703 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 704 | sensor_reader.set_left_intake_encoder(make_encoder(3)); |
| 705 | sensor_reader.set_left_intake_absolute_pwm( |
| 706 | make_unique<frc::DigitalInput>(4)); |
| 707 | sensor_reader.set_left_intake_potentiometer( |
| 708 | make_unique<frc::AnalogInput>(0)); |
| 709 | sensor_reader.set_left_intake_spring_angle( |
| 710 | make_unique<frc::AnalogInput>(4)); |
| 711 | sensor_reader.set_left_intake_cube_detector( |
| 712 | make_unique<frc::DigitalInput>(0)); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 713 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 714 | sensor_reader.set_claw_beambreak(make_unique<frc::DigitalInput>(8)); |
| 715 | sensor_reader.set_box_back_beambreak(make_unique<frc::DigitalInput>(9)); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 716 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 717 | sensor_reader.set_pwm_trigger(true); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 718 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 719 | sensor_reader.set_lidar_lite_input(make_unique<frc::DigitalInput>(22)); |
| 720 | AddLoop(&sensor_reader_event_loop); |
Austin Schuh | 8e5950d | 2018-03-21 20:29:40 -0700 | [diff] [blame] | 721 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 722 | // Thread 4. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 723 | ::aos::ShmEventLoop imu_event_loop(&config.message()); |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 724 | auto imu_trigger = make_unique<frc::DigitalInput>(5); |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 725 | ::frc971::wpilib::ADIS16448 imu( |
| 726 | &imu_event_loop, frc::SPI::Port::kOnboardCS1, imu_trigger.get()); |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 727 | imu.SetDummySPI(frc::SPI::Port::kOnboardCS2); |
| 728 | auto imu_reset = make_unique<frc::DigitalOutput>(6); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 729 | imu.set_reset(imu_reset.get()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 730 | AddLoop(&imu_event_loop); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 731 | |
Austin Schuh | e8a54c0 | 2018-03-05 00:25:58 -0800 | [diff] [blame] | 732 | // While as of 2/9/18 the drivetrain Victors are SPX, it appears as though |
| 733 | // they are identical, as far as DrivetrainWriter is concerned, to the SP |
| 734 | // variety so all the Victors are written as SPs. |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 735 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 736 | // Thread 5. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 737 | ::aos::ShmEventLoop output_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 738 | |
| 739 | ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop); |
Sabina Davis | caa2a6b | 2019-02-03 01:15:37 -0800 | [diff] [blame] | 740 | drivetrain_writer.set_left_controller0( |
| 741 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(2)), false); |
| 742 | drivetrain_writer.set_right_controller0( |
| 743 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(3)), true); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 744 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 745 | SuperstructureWriter superstructure_writer(&output_event_loop); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 746 | superstructure_writer.set_left_intake_elastic_victor( |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 747 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(4))); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 748 | superstructure_writer.set_left_intake_rollers_victor( |
| 749 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(5))); |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 750 | superstructure_writer.set_right_intake_elastic_victor( |
| 751 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(7))); |
| 752 | superstructure_writer.set_right_intake_rollers_victor( |
| 753 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(6))); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 754 | superstructure_writer.set_proximal_victor( |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 755 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(0))); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 756 | superstructure_writer.set_distal_victor( |
Austin Schuh | 6829f76 | 2018-03-02 21:36:01 -0800 | [diff] [blame] | 757 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(1))); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 758 | superstructure_writer.set_hanger_victor( |
| 759 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(8))); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 760 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 761 | AddLoop(&output_event_loop); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 762 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 763 | // Thread 6. |
Austin Schuh | 01a9f2a | 2019-05-27 13:36:30 -0700 | [diff] [blame] | 764 | // This is a separate event loop because we want to run it at much lower |
| 765 | // priority. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 766 | ::aos::ShmEventLoop solenoid_writer_event_loop(&config.message()); |
Austin Schuh | bfbaa37 | 2019-02-15 23:05:31 -0800 | [diff] [blame] | 767 | ::frc971::wpilib::BufferedPcm pcm; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 768 | SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, &pcm); |
Austin Schuh | bfbaa37 | 2019-02-15 23:05:31 -0800 | [diff] [blame] | 769 | solenoid_writer.set_left_drivetrain_shifter(pcm.MakeSolenoid(0)); |
| 770 | solenoid_writer.set_right_drivetrain_shifter(pcm.MakeSolenoid(1)); |
| 771 | solenoid_writer.set_claw(pcm.MakeSolenoid(2)); |
| 772 | solenoid_writer.set_arm_brakes(pcm.MakeSolenoid(3)); |
| 773 | solenoid_writer.set_hook(pcm.MakeSolenoid(4)); |
| 774 | solenoid_writer.set_forks(pcm.MakeSolenoid(5)); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 775 | AddLoop(&solenoid_writer_event_loop); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 776 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 777 | RunLoops(); |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 778 | } |
| 779 | }; |
| 780 | |
| 781 | } // namespace |
| 782 | } // namespace wpilib |
| 783 | } // namespace y2018 |
| 784 | |
| 785 | AOS_ROBOT_CLASS(::y2018::wpilib::WPILibRobot); |