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