Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <array> |
| 4 | #include <chrono> |
| 5 | #include <cinttypes> |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 6 | #include <cstdio> |
| 7 | #include <cstring> |
| 8 | #include <functional> |
| 9 | #include <memory> |
| 10 | #include <mutex> |
| 11 | #include <thread> |
| 12 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 13 | #include "absl/flags/flag.h" |
| 14 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 15 | #include "frc971/wpilib/ahal/AnalogInput.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 16 | #include "frc971/wpilib/ahal/DriverStation.h" |
| 17 | #include "frc971/wpilib/ahal/Encoder.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 18 | #include "frc971/wpilib/ahal/TalonFX.h" |
| 19 | #include "frc971/wpilib/ahal/VictorSP.h" |
| 20 | #undef ERROR |
| 21 | |
| 22 | #include "ctre/phoenix/cci/Diagnostics_CCI.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 23 | |
| 24 | #include "aos/commonmath.h" |
| 25 | #include "aos/containers/sized_array.h" |
| 26 | #include "aos/events/event_loop.h" |
| 27 | #include "aos/events/shm_event_loop.h" |
| 28 | #include "aos/init.h" |
| 29 | #include "aos/logging/logging.h" |
| 30 | #include "aos/realtime.h" |
| 31 | #include "aos/time/time.h" |
| 32 | #include "aos/util/log_interval.h" |
| 33 | #include "aos/util/phased_loop.h" |
| 34 | #include "aos/util/wrapping_counter.h" |
| 35 | #include "frc971/autonomous/auto_mode_generated.h" |
| 36 | #include "frc971/can_configuration_generated.h" |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 37 | #include "frc971/constants/constants_sender_lib.h" |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 38 | #include "frc971/control_loops/drivetrain/drivetrain_can_position_static.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 39 | #include "frc971/control_loops/drivetrain/drivetrain_position_generated.h" |
| 40 | #include "frc971/input/robot_state_generated.h" |
| 41 | #include "frc971/queues/gyro_generated.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 42 | #include "frc971/wpilib/buffered_pcm.h" |
| 43 | #include "frc971/wpilib/buffered_solenoid.h" |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 44 | #include "frc971/wpilib/can_drivetrain_writer.h" |
| 45 | #include "frc971/wpilib/can_sensor_reader.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 46 | #include "frc971/wpilib/dma.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 47 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 48 | #include "frc971/wpilib/generic_can_writer.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 49 | #include "frc971/wpilib/joystick_sender.h" |
| 50 | #include "frc971/wpilib/logging_generated.h" |
| 51 | #include "frc971/wpilib/loop_output_handler.h" |
| 52 | #include "frc971/wpilib/pdp_fetcher.h" |
| 53 | #include "frc971/wpilib/sensor_reader.h" |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 54 | #include "frc971/wpilib/talonfx.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 55 | #include "frc971/wpilib/wpilib_robot_base.h" |
| 56 | #include "y2024/constants.h" |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 57 | #include "y2024/constants/constants_generated.h" |
Filip Kujawa | 70183d6 | 2024-03-02 17:02:51 -0800 | [diff] [blame] | 58 | #include "y2024/control_loops/superstructure/led_indicator.h" |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 59 | #include "y2024/control_loops/superstructure/superstructure_can_position_static.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 60 | #include "y2024/control_loops/superstructure/superstructure_output_generated.h" |
| 61 | #include "y2024/control_loops/superstructure/superstructure_position_generated.h" |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 62 | #include "y2024/control_loops/superstructure/superstructure_position_static.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 63 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 64 | ABSL_FLAG(bool, ctre_diag_server, false, |
| 65 | "If true, enable the diagnostics server for interacting with " |
| 66 | "devices on the CAN bus using Phoenix Tuner"); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 67 | |
| 68 | using ::aos::monotonic_clock; |
| 69 | using ::frc971::CANConfiguration; |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 70 | using ::frc971::control_loops::drivetrain::CANPositionStatic; |
| 71 | using ::frc971::wpilib::TalonFX; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 72 | using ::y2024::constants::Values; |
| 73 | namespace superstructure = ::y2024::control_loops::superstructure; |
| 74 | namespace drivetrain = ::y2024::control_loops::drivetrain; |
| 75 | namespace chrono = ::std::chrono; |
| 76 | using std::make_unique; |
| 77 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 78 | namespace y2024::wpilib { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 79 | namespace { |
| 80 | |
| 81 | constexpr double kMaxBringupPower = 12.0; |
| 82 | |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 83 | double climber_pot_translate(double voltage) { |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 84 | return voltage * Values::kClimberPotMetersPerVolt(); |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 87 | double extend_pot_translate(double voltage) { |
| 88 | return voltage * Values::kExtendPotMetersPerVolt(); |
| 89 | } |
| 90 | |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 91 | double catapult_pot_translate(double voltage) { |
| 92 | return voltage * Values::kCatapultPotRadiansPerVolt(); |
| 93 | } |
| 94 | |
| 95 | double turret_pot_translate(double voltage) { |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 96 | return -1 * voltage * Values::kTurretPotRadiansPerVolt(); |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | double altitude_pot_translate(double voltage) { |
Maxwell Henderson | 0b6fed6 | 2024-02-23 11:05:09 -0800 | [diff] [blame] | 100 | return -1 * voltage * Values::kAltitudePotRadiansPerVolt(); |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 103 | double drivetrain_velocity_translate(double in) { |
| 104 | return (((1.0 / in) / Values::kDrivetrainCyclesPerRevolution()) * |
| 105 | (2.0 * M_PI)) * |
| 106 | Values::kDrivetrainEncoderRatio() * |
| 107 | control_loops::drivetrain::kWheelRadius; |
| 108 | } |
| 109 | |
| 110 | constexpr double kMaxFastEncoderPulsesPerSecond = std::max({ |
| 111 | Values::kMaxDrivetrainEncoderPulsesPerSecond(), |
Maxwell Henderson | 1de1549 | 2024-02-07 11:09:47 -0800 | [diff] [blame] | 112 | Values::kMaxIntakePivotEncoderPulsesPerSecond(), |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 113 | Values::kMaxExtendEncoderPulsesPerSecond(), |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 114 | Values::kMaxCatapultEncoderPulsesPerSecond(), |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 115 | }); |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 116 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 117 | static_assert(kMaxFastEncoderPulsesPerSecond <= 1300000, |
| 118 | "fast encoders are too fast"); |
| 119 | |
| 120 | } // namespace |
| 121 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 122 | // Class to send position messages with sensor readings to our loops. |
| 123 | class SensorReader : public ::frc971::wpilib::SensorReader { |
| 124 | public: |
| 125 | SensorReader(::aos::ShmEventLoop *event_loop, |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 126 | const Constants *robot_constants) |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 127 | : ::frc971::wpilib::SensorReader(event_loop), |
Austin Schuh | 6bdcc37 | 2024-06-27 14:49:11 -0700 | [diff] [blame] | 128 | robot_constants_(robot_constants), |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 129 | auto_mode_sender_( |
| 130 | event_loop->MakeSender<::frc971::autonomous::AutonomousMode>( |
| 131 | "/autonomous")), |
| 132 | superstructure_position_sender_( |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 133 | event_loop->MakeSender<superstructure::PositionStatic>( |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 134 | "/superstructure")), |
| 135 | drivetrain_position_sender_( |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 136 | event_loop->MakeSender< |
| 137 | ::frc971::control_loops::drivetrain::PositionStatic>( |
| 138 | "/drivetrain")), |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 139 | gyro_sender_(event_loop->MakeSender<::frc971::sensors::GyroReading>( |
Maxwell Henderson | afc5c6d | 2024-02-20 15:34:13 -0800 | [diff] [blame] | 140 | "/drivetrain")) { |
| 141 | UpdateFastEncoderFilterHz(kMaxFastEncoderPulsesPerSecond); |
| 142 | event_loop->SetRuntimeAffinity(aos::MakeCpusetFromCpus({0})); |
| 143 | }; |
| 144 | void Start() override { |
| 145 | AddToDMA(&imu_yaw_rate_reader_); |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 146 | if (aos::network::GetTeamNumber() != 9971) { |
| 147 | AddToDMA(&turret_encoder_.reader()); |
| 148 | AddToDMA(&altitude_encoder_.reader()); |
| 149 | } |
Maxwell Henderson | afc5c6d | 2024-02-20 15:34:13 -0800 | [diff] [blame] | 150 | } |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 151 | |
| 152 | // Auto mode switches. |
| 153 | void set_autonomous_mode(int i, ::std::unique_ptr<frc::DigitalInput> sensor) { |
| 154 | autonomous_modes_.at(i) = ::std::move(sensor); |
| 155 | } |
| 156 | |
| 157 | void set_yaw_rate_input(::std::unique_ptr<frc::DigitalInput> sensor) { |
| 158 | imu_yaw_rate_input_ = ::std::move(sensor); |
| 159 | imu_yaw_rate_reader_.set_input(imu_yaw_rate_input_.get()); |
| 160 | } |
| 161 | |
| 162 | void RunIteration() override { |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 163 | if (aos::network::GetTeamNumber() != 9971) { |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 164 | aos::Sender<superstructure::PositionStatic>::StaticBuilder builder = |
| 165 | superstructure_position_sender_.MakeStaticBuilder(); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 166 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 167 | CopyPosition(intake_pivot_encoder_, builder->add_intake_pivot(), |
| 168 | Values::kIntakePivotEncoderCountsPerRevolution(), |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 169 | Values::kIntakePivotEncoderRatio(), /* reversed: */ false); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 170 | |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 171 | CopyPosition(*climber_potentiometer_, builder->add_climber(), |
Maxwell Henderson | 9e3b310 | 2024-02-20 15:35:02 -0800 | [diff] [blame] | 172 | climber_pot_translate, false, |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 173 | robot_constants_->robot()->climber_potentiometer_offset()); |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 174 | |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 175 | CopyPosition(extend_encoder_, builder->add_extend(), |
Maxwell Henderson | 9e3b310 | 2024-02-20 15:35:02 -0800 | [diff] [blame] | 176 | Values::kExtendEncoderCountsPerRevolution(), |
| 177 | Values::kExtendEncoderMetersPerRadian(), |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 178 | extend_pot_translate, false, |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 179 | robot_constants_->robot() |
| 180 | ->extend_constants() |
| 181 | ->potentiometer_offset()); |
| 182 | |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 183 | CopyPosition(catapult_encoder_, builder->add_catapult(), |
| 184 | Values::kCatapultEncoderCountsPerRevolution(), |
| 185 | Values::kCatapultEncoderRatio(), catapult_pot_translate, |
| 186 | true, |
| 187 | robot_constants_->robot() |
| 188 | ->catapult_constants() |
| 189 | ->potentiometer_offset()); |
| 190 | |
| 191 | CopyPosition(turret_encoder_, builder->add_turret(), |
| 192 | Values::kTurretEncoderCountsPerRevolution(), |
| 193 | Values::kTurretEncoderRatio(), turret_pot_translate, true, |
| 194 | robot_constants_->robot() |
| 195 | ->turret_constants() |
| 196 | ->potentiometer_offset()); |
| 197 | |
| 198 | CopyPosition(altitude_encoder_, builder->add_altitude(), |
| 199 | Values::kAltitudeEncoderCountsPerRevolution(), |
| 200 | Values::kAltitudeEncoderRatio(), altitude_pot_translate, |
| 201 | true, |
| 202 | robot_constants_->robot() |
| 203 | ->altitude_constants() |
| 204 | ->potentiometer_offset()); |
| 205 | |
Niko Sohmers | ed7ffc4 | 2024-02-03 16:05:19 -0800 | [diff] [blame] | 206 | builder->set_transfer_beambreak(transfer_beam_break_->Get()); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 207 | builder->set_extend_beambreak(extend_beam_break_->Get()); |
Maxwell Henderson | 576b0c9 | 2024-02-23 17:10:48 -0800 | [diff] [blame] | 208 | builder->set_catapult_beambreak(catapult_beam_break_->Get()); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 209 | builder.CheckOk(builder.Send()); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 212 | SendDrivetrainPosition(drivetrain_position_sender_.MakeStaticBuilder(), |
| 213 | drivetrain_velocity_translate, |
Maxwell Henderson | 9e3b310 | 2024-02-20 15:35:02 -0800 | [diff] [blame] | 214 | constants::Values::DrivetrainEncoderToMeters, true, |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 215 | false); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 216 | |
| 217 | { |
| 218 | auto builder = gyro_sender_.MakeBuilder(); |
| 219 | ::frc971::sensors::GyroReading::Builder gyro_reading_builder = |
| 220 | builder.MakeBuilder<::frc971::sensors::GyroReading>(); |
| 221 | // +/- 2000 deg / sec |
| 222 | constexpr double kMaxVelocity = 4000; // degrees / second |
| 223 | constexpr double kVelocityRadiansPerSecond = |
| 224 | kMaxVelocity / 360 * (2.0 * M_PI); |
| 225 | |
| 226 | // Only part of the full range is used to prevent being 100% on or off. |
| 227 | constexpr double kScaledRangeLow = 0.1; |
| 228 | constexpr double kScaledRangeHigh = 0.9; |
| 229 | |
| 230 | constexpr double kPWMFrequencyHz = 200; |
| 231 | double velocity_duty_cycle = |
| 232 | imu_yaw_rate_reader_.last_width() * kPWMFrequencyHz; |
| 233 | |
| 234 | constexpr double kDutyCycleScale = |
| 235 | 1 / (kScaledRangeHigh - kScaledRangeLow); |
| 236 | // scale from 0.1 - 0.9 to 0 - 1 |
| 237 | double rescaled_velocity_duty_cycle = |
| 238 | (velocity_duty_cycle - kScaledRangeLow) * kDutyCycleScale; |
| 239 | |
| 240 | if (!std::isnan(rescaled_velocity_duty_cycle)) { |
| 241 | gyro_reading_builder.add_velocity((rescaled_velocity_duty_cycle - 0.5) * |
| 242 | kVelocityRadiansPerSecond); |
| 243 | } |
| 244 | builder.CheckOk(builder.Send(gyro_reading_builder.Finish())); |
| 245 | } |
| 246 | |
| 247 | { |
| 248 | auto builder = auto_mode_sender_.MakeBuilder(); |
| 249 | |
| 250 | uint32_t mode = 0; |
| 251 | for (size_t i = 0; i < autonomous_modes_.size(); ++i) { |
| 252 | if (autonomous_modes_[i] && autonomous_modes_[i]->Get()) { |
| 253 | mode |= 1 << i; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | auto auto_mode_builder = |
| 258 | builder.MakeBuilder<frc971::autonomous::AutonomousMode>(); |
| 259 | |
| 260 | auto_mode_builder.add_mode(mode); |
| 261 | |
| 262 | builder.CheckOk(builder.Send(auto_mode_builder.Finish())); |
| 263 | } |
| 264 | } |
| 265 | |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 266 | void set_climber_potentiometer( |
| 267 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
| 268 | climber_potentiometer_ = ::std::move(potentiometer); |
| 269 | } |
| 270 | |
Maxwell Henderson | 6291783 | 2024-02-07 11:08:11 -0800 | [diff] [blame] | 271 | void set_intake_pivot(::std::unique_ptr<frc::Encoder> encoder, |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 272 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 273 | fast_encoder_filter_.Add(encoder.get()); |
| 274 | intake_pivot_encoder_.set_encoder(::std::move(encoder)); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 275 | intake_pivot_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Niko Sohmers | ed7ffc4 | 2024-02-03 16:05:19 -0800 | [diff] [blame] | 278 | void set_transfer_beambreak(::std::unique_ptr<frc::DigitalInput> sensor) { |
| 279 | transfer_beam_break_ = ::std::move(sensor); |
| 280 | } |
| 281 | |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 282 | void set_extend_beambreak(::std::unique_ptr<frc::DigitalInput> sensor) { |
| 283 | extend_beam_break_ = ::std::move(sensor); |
| 284 | } |
| 285 | |
Maxwell Henderson | 576b0c9 | 2024-02-23 17:10:48 -0800 | [diff] [blame] | 286 | void set_catapult_beambreak(::std::unique_ptr<frc::DigitalInput> sensor) { |
| 287 | catapult_beam_break_ = ::std::move(sensor); |
| 288 | } |
| 289 | |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 290 | void set_extend(::std::unique_ptr<frc::Encoder> encoder, |
| 291 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm, |
| 292 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
| 293 | fast_encoder_filter_.Add(encoder.get()); |
| 294 | extend_encoder_.set_encoder(::std::move(encoder)); |
| 295 | extend_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 296 | extend_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 297 | } |
| 298 | |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 299 | void set_catapult(::std::unique_ptr<frc::Encoder> encoder, |
| 300 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm, |
| 301 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
| 302 | fast_encoder_filter_.Add(encoder.get()); |
| 303 | catapult_encoder_.set_encoder(::std::move(encoder)); |
| 304 | catapult_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 305 | catapult_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 306 | } |
| 307 | |
| 308 | void set_turret(::std::unique_ptr<frc::Encoder> encoder, |
| 309 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm, |
| 310 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
| 311 | fast_encoder_filter_.Add(encoder.get()); |
| 312 | turret_encoder_.set_encoder(::std::move(encoder)); |
| 313 | turret_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 314 | turret_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 315 | } |
| 316 | |
| 317 | void set_altitude(::std::unique_ptr<frc::Encoder> encoder, |
| 318 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm, |
| 319 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
| 320 | fast_encoder_filter_.Add(encoder.get()); |
| 321 | altitude_encoder_.set_encoder(::std::move(encoder)); |
| 322 | altitude_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 323 | altitude_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 324 | } |
| 325 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 326 | private: |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 327 | const Constants *robot_constants_; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 328 | |
| 329 | aos::Sender<frc971::autonomous::AutonomousMode> auto_mode_sender_; |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 330 | aos::Sender<superstructure::PositionStatic> superstructure_position_sender_; |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 331 | aos::Sender<frc971::control_loops::drivetrain::PositionStatic> |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 332 | drivetrain_position_sender_; |
| 333 | ::aos::Sender<::frc971::sensors::GyroReading> gyro_sender_; |
| 334 | |
| 335 | std::array<std::unique_ptr<frc::DigitalInput>, 2> autonomous_modes_; |
| 336 | |
Maxwell Henderson | 576b0c9 | 2024-02-23 17:10:48 -0800 | [diff] [blame] | 337 | std::unique_ptr<frc::DigitalInput> imu_yaw_rate_input_, transfer_beam_break_, |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 338 | extend_beam_break_, catapult_beam_break_; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 339 | |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 340 | std::unique_ptr<frc::AnalogInput> climber_potentiometer_; |
| 341 | |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 342 | frc971::wpilib::AbsoluteEncoder intake_pivot_encoder_; |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 343 | frc971::wpilib::AbsoluteEncoderAndPotentiometer catapult_encoder_, |
| 344 | extend_encoder_; |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 345 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 346 | frc971::wpilib::DMAPulseWidthReader imu_yaw_rate_reader_; |
Maxwell Henderson | afc5c6d | 2024-02-20 15:34:13 -0800 | [diff] [blame] | 347 | |
| 348 | frc971::wpilib::DMAAbsoluteEncoderAndPotentiometer turret_encoder_, |
| 349 | altitude_encoder_; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 350 | }; |
| 351 | |
Maxwell Henderson | abcc92a | 2024-02-21 19:06:26 -0800 | [diff] [blame] | 352 | class SuperstructurePWMWriter |
| 353 | : public ::frc971::wpilib::LoopOutputHandler<superstructure::Output> { |
| 354 | public: |
| 355 | SuperstructurePWMWriter(aos::EventLoop *event_loop) |
| 356 | : frc971::wpilib::LoopOutputHandler<superstructure::Output>( |
| 357 | event_loop, "/superstructure") {} |
| 358 | |
| 359 | void set_catapult_kraken_one(::std::unique_ptr<::frc::TalonFX> t) { |
| 360 | catapult_kraken_one_ = ::std::move(t); |
| 361 | } |
| 362 | void set_catapult_kraken_two(::std::unique_ptr<::frc::TalonFX> t) { |
| 363 | catapult_kraken_two_ = ::std::move(t); |
| 364 | } |
| 365 | |
| 366 | private: |
| 367 | void Stop() override { |
| 368 | AOS_LOG(WARNING, "Superstructure output too old.\n"); |
| 369 | catapult_kraken_one_->SetDisabled(); |
| 370 | catapult_kraken_two_->SetDisabled(); |
| 371 | } |
| 372 | |
| 373 | void Write(const superstructure::Output &output) override { |
| 374 | WritePwm(output.catapult_voltage(), catapult_kraken_one_.get()); |
Maxwell Henderson | 12d427b | 2024-02-22 13:57:45 -0800 | [diff] [blame] | 375 | WritePwm(output.catapult_voltage(), catapult_kraken_two_.get()); |
Maxwell Henderson | abcc92a | 2024-02-21 19:06:26 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | template <typename T> |
| 379 | static void WritePwm(const double voltage, T *motor) { |
| 380 | motor->SetSpeed(std::clamp(voltage, -kMaxBringupPower, kMaxBringupPower) / |
| 381 | 12.0); |
| 382 | } |
| 383 | ::std::unique_ptr<::frc::TalonFX> catapult_kraken_one_, catapult_kraken_two_; |
| 384 | }; |
| 385 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 386 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 387 | public: |
| 388 | ::std::unique_ptr<frc::Encoder> make_encoder(int index) { |
| 389 | return make_unique<frc::Encoder>(10 + index * 2, 11 + index * 2, false, |
| 390 | frc::Encoder::k4X); |
| 391 | } |
| 392 | |
| 393 | void Run() override { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 394 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 395 | aos::configuration::ReadConfig("aos_config.json"); |
| 396 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 397 | frc971::constants::WaitForConstants<y2024::Constants>(&config.message()); |
| 398 | |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 399 | const int team_number = aos::network::GetTeamNumber(); |
| 400 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 401 | ::aos::ShmEventLoop constant_fetcher_event_loop(&config.message()); |
| 402 | frc971::constants::ConstantsFetcher<Constants> constants_fetcher( |
| 403 | &constant_fetcher_event_loop); |
| 404 | const Constants *robot_constants = &constants_fetcher.constants(); |
| 405 | |
Maxwell Henderson | ca7c9b6 | 2024-02-21 13:20:09 -0800 | [diff] [blame] | 406 | AddLoop(&constant_fetcher_event_loop); |
| 407 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 408 | // Thread 1. |
| 409 | ::aos::ShmEventLoop joystick_sender_event_loop(&config.message()); |
| 410 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 411 | &joystick_sender_event_loop); |
| 412 | AddLoop(&joystick_sender_event_loop); |
| 413 | |
| 414 | // Thread 2. |
| 415 | ::aos::ShmEventLoop pdp_fetcher_event_loop(&config.message()); |
| 416 | ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop); |
| 417 | AddLoop(&pdp_fetcher_event_loop); |
| 418 | |
| 419 | // Thread 3. |
| 420 | ::aos::ShmEventLoop sensor_reader_event_loop(&config.message()); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 421 | SensorReader sensor_reader(&sensor_reader_event_loop, robot_constants); |
Austin Schuh | 65b4f9d | 2024-03-17 16:03:10 -0700 | [diff] [blame] | 422 | sensor_reader.set_pwm_trigger(false); |
Maxwell Henderson | 9e3b310 | 2024-02-20 15:35:02 -0800 | [diff] [blame] | 423 | sensor_reader.set_drivetrain_left_encoder( |
Maxwell Henderson | 9e3b310 | 2024-02-20 15:35:02 -0800 | [diff] [blame] | 424 | std::make_unique<frc::Encoder>(8, 9)); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 425 | sensor_reader.set_drivetrain_right_encoder( |
| 426 | std::make_unique<frc::Encoder>(6, 7)); |
Maxwell Henderson | 9e3b310 | 2024-02-20 15:35:02 -0800 | [diff] [blame] | 427 | sensor_reader.set_yaw_rate_input(make_unique<frc::DigitalInput>(25)); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 428 | |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 429 | if (team_number != 9971) { |
| 430 | sensor_reader.set_intake_pivot(make_encoder(3), |
| 431 | make_unique<frc::DigitalInput>(3)); |
| 432 | sensor_reader.set_transfer_beambreak(make_unique<frc::DigitalInput>(23)); |
| 433 | sensor_reader.set_extend_beambreak(make_unique<frc::DigitalInput>(24)); |
| 434 | sensor_reader.set_catapult_beambreak(make_unique<frc::DigitalInput>(22)); |
Niko Sohmers | 4d93d4c | 2024-03-24 14:48:26 -0700 | [diff] [blame] | 435 | sensor_reader.set_climber_potentiometer(make_unique<frc::AnalogInput>(4)); |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 436 | sensor_reader.set_extend(make_encoder(5), |
| 437 | make_unique<frc::DigitalInput>(5), |
| 438 | make_unique<frc::AnalogInput>(5)); |
| 439 | sensor_reader.set_catapult(make_encoder(0), |
| 440 | make_unique<frc::DigitalInput>(0), |
| 441 | make_unique<frc::AnalogInput>(0)); |
| 442 | sensor_reader.set_turret(make_encoder(2), |
| 443 | make_unique<frc::DigitalInput>(2), |
| 444 | make_unique<frc::AnalogInput>(2)); |
| 445 | sensor_reader.set_altitude(make_encoder(1), |
| 446 | make_unique<frc::DigitalInput>(1), |
| 447 | make_unique<frc::AnalogInput>(1)); |
| 448 | } |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 449 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 450 | AddLoop(&sensor_reader_event_loop); |
| 451 | |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 452 | if (team_number == 9971) { |
| 453 | std::vector<ctre::phoenix6::BaseStatusSignal *> signal_registry; |
| 454 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 455 | if (!absl::GetFlag(FLAGS_ctre_diag_server)) { |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 456 | c_Phoenix_Diagnostics_SetSecondsToStart(-1); |
| 457 | c_Phoenix_Diagnostics_Dispose(); |
| 458 | } |
| 459 | |
| 460 | const CurrentLimits *current_limits = |
| 461 | robot_constants->common()->current_limits(); |
| 462 | |
| 463 | std::shared_ptr<TalonFX> right_front = std::make_shared<TalonFX>( |
| 464 | 2, true, "Drivetrain Bus", &signal_registry, |
| 465 | current_limits->drivetrain_supply_current_limit(), |
| 466 | current_limits->drivetrain_stator_current_limit()); |
| 467 | std::shared_ptr<TalonFX> right_back = std::make_shared<TalonFX>( |
| 468 | 1, true, "Drivetrain Bus", &signal_registry, |
| 469 | current_limits->drivetrain_supply_current_limit(), |
| 470 | current_limits->drivetrain_stator_current_limit()); |
| 471 | std::shared_ptr<TalonFX> left_front = std::make_shared<TalonFX>( |
| 472 | 4, false, "Drivetrain Bus", &signal_registry, |
| 473 | current_limits->drivetrain_supply_current_limit(), |
| 474 | current_limits->drivetrain_stator_current_limit()); |
| 475 | std::shared_ptr<TalonFX> left_back = std::make_shared<TalonFX>( |
| 476 | 5, false, "Drivetrain Bus", &signal_registry, |
| 477 | current_limits->drivetrain_supply_current_limit(), |
| 478 | current_limits->drivetrain_stator_current_limit()); |
| 479 | |
| 480 | ctre::phoenix::platform::can::CANComm_SetRxSchedPriority( |
| 481 | constants::Values::kDrivetrainRxPriority, true, "Drivetrain Bus"); |
| 482 | ctre::phoenix::platform::can::CANComm_SetTxSchedPriority( |
| 483 | constants::Values::kDrivetrainWriterPriority, true, "Drivetrain Bus"); |
| 484 | |
| 485 | ::aos::ShmEventLoop can_sensor_reader_event_loop(&config.message()); |
| 486 | can_sensor_reader_event_loop.set_name("CANSensorReader"); |
| 487 | |
| 488 | std::vector<std::shared_ptr<TalonFX>> drivetrain_krakens; |
| 489 | |
| 490 | for (auto talonfx : {right_front, right_back, left_front, left_back}) { |
| 491 | drivetrain_krakens.push_back(talonfx); |
| 492 | } |
| 493 | |
| 494 | aos::Sender<frc971::control_loops::drivetrain::CANPositionStatic> |
| 495 | drivetrain_can_position_sender = |
| 496 | can_sensor_reader_event_loop.MakeSender< |
| 497 | frc971::control_loops::drivetrain::CANPositionStatic>( |
| 498 | "/drivetrain"); |
| 499 | |
| 500 | frc971::wpilib::CANSensorReader can_sensor_reader( |
| 501 | &can_sensor_reader_event_loop, std::move(signal_registry), |
| 502 | drivetrain_krakens, |
| 503 | [drivetrain_krakens, |
| 504 | &drivetrain_can_position_sender](ctre::phoenix::StatusCode status) { |
| 505 | aos::Sender<frc971::control_loops::drivetrain::CANPositionStatic>:: |
| 506 | StaticBuilder drivetrain_can_builder = |
| 507 | drivetrain_can_position_sender.MakeStaticBuilder(); |
| 508 | |
| 509 | auto drivetrain_falcon_vector = |
Austin Schuh | 6bdcc37 | 2024-06-27 14:49:11 -0700 | [diff] [blame] | 510 | drivetrain_can_builder->add_talonfxs(); |
| 511 | CHECK(drivetrain_falcon_vector != nullptr); |
Maxwell Henderson | 3c00b7d | 2024-03-21 21:17:51 -0700 | [diff] [blame] | 512 | |
| 513 | for (auto talonfx : drivetrain_krakens) { |
| 514 | talonfx->SerializePosition( |
| 515 | drivetrain_falcon_vector->emplace_back(), |
| 516 | control_loops::drivetrain::kHighOutputRatio); |
| 517 | } |
| 518 | |
| 519 | drivetrain_can_builder->set_status(static_cast<int>(status)); |
| 520 | |
| 521 | drivetrain_can_builder.CheckOk(drivetrain_can_builder.Send()); |
| 522 | }); |
| 523 | |
| 524 | AddLoop(&can_sensor_reader_event_loop); |
| 525 | |
| 526 | ::aos::ShmEventLoop can_output_event_loop(&config.message()); |
| 527 | can_output_event_loop.set_name("CANOutputWriter"); |
| 528 | |
| 529 | frc971::wpilib::CANDrivetrainWriter can_drivetrain_writer( |
| 530 | &can_output_event_loop); |
| 531 | |
| 532 | can_drivetrain_writer.set_talonfxs({right_front, right_back}, |
| 533 | {left_front, left_back}); |
| 534 | can_output_event_loop.MakeWatcher( |
| 535 | "/roborio", [&can_drivetrain_writer]( |
| 536 | const frc971::CANConfiguration &configuration) { |
| 537 | can_drivetrain_writer.HandleCANConfiguration(configuration); |
| 538 | }); |
| 539 | |
| 540 | AddLoop(&can_output_event_loop); |
| 541 | |
| 542 | RunLoops(); |
| 543 | return; |
| 544 | } |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 545 | // Thread 4. |
| 546 | // Set up CAN. |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 547 | if (!absl::GetFlag(FLAGS_ctre_diag_server)) { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 548 | c_Phoenix_Diagnostics_SetSecondsToStart(-1); |
| 549 | c_Phoenix_Diagnostics_Dispose(); |
| 550 | } |
| 551 | |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 552 | std::vector<ctre::phoenix6::BaseStatusSignal *> canivore_signal_registry; |
| 553 | std::vector<ctre::phoenix6::BaseStatusSignal *> rio_signal_registry; |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 554 | |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 555 | const CurrentLimits *current_limits = |
| 556 | robot_constants->common()->current_limits(); |
| 557 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 558 | std::shared_ptr<TalonFX> right_front = std::make_shared<TalonFX>( |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 559 | 2, true, "Drivetrain Bus", &canivore_signal_registry, |
James Kuszmaul | afab1c8 | 2024-05-04 14:24:24 -0700 | [diff] [blame] | 560 | current_limits->drivetrain_stator_current_limit(), |
| 561 | current_limits->drivetrain_supply_current_limit()); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 562 | std::shared_ptr<TalonFX> right_back = std::make_shared<TalonFX>( |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 563 | 1, true, "Drivetrain Bus", &canivore_signal_registry, |
James Kuszmaul | afab1c8 | 2024-05-04 14:24:24 -0700 | [diff] [blame] | 564 | current_limits->drivetrain_stator_current_limit(), |
| 565 | current_limits->drivetrain_supply_current_limit()); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 566 | std::shared_ptr<TalonFX> left_front = std::make_shared<TalonFX>( |
Maxwell Henderson | 7be07d5 | 2024-02-20 07:59:16 -0800 | [diff] [blame] | 567 | 4, false, "Drivetrain Bus", &canivore_signal_registry, |
James Kuszmaul | afab1c8 | 2024-05-04 14:24:24 -0700 | [diff] [blame] | 568 | current_limits->drivetrain_stator_current_limit(), |
| 569 | current_limits->drivetrain_supply_current_limit()); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 570 | std::shared_ptr<TalonFX> left_back = std::make_shared<TalonFX>( |
Maxwell Henderson | 7be07d5 | 2024-02-20 07:59:16 -0800 | [diff] [blame] | 571 | 5, false, "Drivetrain Bus", &canivore_signal_registry, |
James Kuszmaul | afab1c8 | 2024-05-04 14:24:24 -0700 | [diff] [blame] | 572 | current_limits->drivetrain_stator_current_limit(), |
| 573 | current_limits->drivetrain_supply_current_limit()); |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 574 | std::shared_ptr<TalonFX> intake_pivot = std::make_shared<TalonFX>( |
Maxwell Henderson | 30ea8b3 | 2024-02-22 16:14:05 -0800 | [diff] [blame] | 575 | 6, false, "Drivetrain Bus", &canivore_signal_registry, |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 576 | current_limits->intake_pivot_stator_current_limit(), |
| 577 | current_limits->intake_pivot_supply_current_limit()); |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 578 | std::shared_ptr<TalonFX> altitude = std::make_shared<TalonFX>( |
Maxwell Henderson | 30ea8b3 | 2024-02-22 16:14:05 -0800 | [diff] [blame] | 579 | 9, false, "Drivetrain Bus", &canivore_signal_registry, |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 580 | current_limits->altitude_stator_current_limit(), |
| 581 | current_limits->altitude_supply_current_limit()); |
| 582 | std::shared_ptr<TalonFX> turret = std::make_shared<TalonFX>( |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 583 | 3, true, "Drivetrain Bus", &canivore_signal_registry, |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 584 | current_limits->turret_stator_current_limit(), |
| 585 | current_limits->turret_supply_current_limit()); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 586 | std::shared_ptr<TalonFX> climber = std::make_shared<TalonFX>( |
James Kuszmaul | 42a8745 | 2024-04-05 17:30:47 -0700 | [diff] [blame] | 587 | 7, false, "rio", &rio_signal_registry, |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 588 | current_limits->climber_stator_current_limit(), |
| 589 | current_limits->climber_supply_current_limit()); |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame] | 590 | std::shared_ptr<TalonFX> extend = |
Niko Sohmers | 58461f5 | 2024-03-20 20:12:10 -0700 | [diff] [blame] | 591 | (robot_constants->robot()->disable_extend()) |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame] | 592 | ? nullptr |
| 593 | : std::make_shared<TalonFX>( |
| 594 | 12, false, "Drivetrain Bus", &canivore_signal_registry, |
| 595 | current_limits->extend_stator_current_limit(), |
| 596 | current_limits->extend_supply_current_limit()); |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 597 | std::shared_ptr<TalonFX> intake_roller = std::make_shared<TalonFX>( |
Maxwell Henderson | 7be07d5 | 2024-02-20 07:59:16 -0800 | [diff] [blame] | 598 | 8, false, "rio", &rio_signal_registry, |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 599 | current_limits->intake_roller_stator_current_limit(), |
| 600 | current_limits->intake_roller_supply_current_limit()); |
Maxwell Henderson | 7b7754b | 2024-02-22 16:50:35 -0800 | [diff] [blame] | 601 | std::shared_ptr<TalonFX> retention_roller = std::make_shared<TalonFX>( |
Maxwell Henderson | efead39 | 2024-02-23 19:10:50 -0800 | [diff] [blame] | 602 | 10, true, "rio", &rio_signal_registry, |
Maxwell Henderson | fe73565 | 2024-02-23 19:22:31 -0800 | [diff] [blame] | 603 | current_limits->retention_roller_stator_current_limit(), |
| 604 | current_limits->retention_roller_supply_current_limit()); |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 605 | std::shared_ptr<TalonFX> transfer_roller = std::make_shared<TalonFX>( |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 606 | 11, true, "rio", &rio_signal_registry, |
Maxwell Henderson | fb3bfea | 2024-02-03 19:24:46 -0800 | [diff] [blame] | 607 | current_limits->transfer_roller_stator_current_limit(), |
| 608 | current_limits->transfer_roller_supply_current_limit()); |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 609 | std::shared_ptr<TalonFX> extend_roller = std::make_shared<TalonFX>( |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 610 | 13, true, "rio", &rio_signal_registry, |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 611 | current_limits->extend_roller_stator_current_limit(), |
| 612 | current_limits->extend_roller_supply_current_limit()); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 613 | std::shared_ptr<TalonFX> catapult_one = std::make_shared<TalonFX>( |
| 614 | 14, false, "Drivetrain Bus", &canivore_signal_registry, |
| 615 | current_limits->catapult_stator_current_limit(), |
| 616 | current_limits->catapult_supply_current_limit()); |
| 617 | std::shared_ptr<TalonFX> catapult_two = std::make_shared<TalonFX>( |
| 618 | 15, false, "Drivetrain Bus", &canivore_signal_registry, |
| 619 | current_limits->catapult_stator_current_limit(), |
| 620 | current_limits->catapult_supply_current_limit()); |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 621 | |
Stephan Pleines | 5aabf63 | 2024-03-13 20:31:18 -0700 | [diff] [blame] | 622 | transfer_roller->set_neutral_mode( |
| 623 | ctre::phoenix6::signals::NeutralModeValue::Coast); |
| 624 | intake_roller->set_neutral_mode( |
| 625 | ctre::phoenix6::signals::NeutralModeValue::Coast); |
| 626 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 627 | ctre::phoenix::platform::can::CANComm_SetRxSchedPriority( |
| 628 | constants::Values::kDrivetrainRxPriority, true, "Drivetrain Bus"); |
| 629 | ctre::phoenix::platform::can::CANComm_SetTxSchedPriority( |
Austin Schuh | 46e0d10 | 2024-03-17 16:04:57 -0700 | [diff] [blame] | 630 | constants::Values::kDrivetrainWriterPriority, true, "Drivetrain Bus"); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 631 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 632 | ::aos::ShmEventLoop can_sensor_reader_event_loop(&config.message()); |
| 633 | can_sensor_reader_event_loop.set_name("CANSensorReader"); |
| 634 | |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 635 | ::aos::ShmEventLoop rio_sensor_reader_event_loop(&config.message()); |
| 636 | rio_sensor_reader_event_loop.set_name("RioSensorReader"); |
| 637 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 638 | // Creating list of talonfx for CANSensorReader |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 639 | std::vector<std::shared_ptr<TalonFX>> drivetrain_talonfxs; |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 640 | std::vector<std::shared_ptr<TalonFX>> canivore_talonfxs; |
| 641 | std::vector<std::shared_ptr<TalonFX>> rio_talonfxs; |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 642 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 643 | for (auto talonfx : {right_front, right_back, left_front, left_back}) { |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 644 | drivetrain_talonfxs.push_back(talonfx); |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 645 | canivore_talonfxs.push_back(talonfx); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 648 | for (auto talonfx : |
Austin Schuh | 95764db | 2024-03-01 19:21:09 -0800 | [diff] [blame] | 649 | {intake_pivot, turret, altitude, catapult_one, catapult_two, extend}) { |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame] | 650 | if (talonfx != nullptr) { |
| 651 | canivore_talonfxs.push_back(talonfx); |
| 652 | } |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 653 | } |
| 654 | |
Austin Schuh | 95764db | 2024-03-01 19:21:09 -0800 | [diff] [blame] | 655 | for (auto talonfx : {intake_roller, transfer_roller, climber, extend_roller, |
| 656 | retention_roller}) { |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 657 | rio_talonfxs.push_back(talonfx); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | aos::Sender<frc971::control_loops::drivetrain::CANPositionStatic> |
| 661 | drivetrain_can_position_sender = |
| 662 | can_sensor_reader_event_loop.MakeSender< |
| 663 | frc971::control_loops::drivetrain::CANPositionStatic>( |
| 664 | "/drivetrain"); |
| 665 | |
| 666 | aos::Sender<y2024::control_loops::superstructure::CANPositionStatic> |
| 667 | superstructure_can_position_sender = |
| 668 | can_sensor_reader_event_loop.MakeSender< |
| 669 | y2024::control_loops::superstructure::CANPositionStatic>( |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 670 | "/superstructure/canivore"); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 671 | |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 672 | frc971::wpilib::CANSensorReader canivore_can_sensor_reader( |
| 673 | &can_sensor_reader_event_loop, std::move(canivore_signal_registry), |
| 674 | canivore_talonfxs, |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 675 | [drivetrain_talonfxs, &intake_pivot, &turret, &altitude, &catapult_one, |
| 676 | &catapult_two, &drivetrain_can_position_sender, |
Austin Schuh | 95764db | 2024-03-01 19:21:09 -0800 | [diff] [blame] | 677 | &superstructure_can_position_sender, |
| 678 | &extend](ctre::phoenix::StatusCode status) { |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 679 | aos::Sender<frc971::control_loops::drivetrain::CANPositionStatic>:: |
| 680 | StaticBuilder drivetrain_can_builder = |
| 681 | drivetrain_can_position_sender.MakeStaticBuilder(); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 682 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 683 | auto drivetrain_falcon_vector = |
Austin Schuh | 6bdcc37 | 2024-06-27 14:49:11 -0700 | [diff] [blame] | 684 | drivetrain_can_builder->add_talonfxs(); |
| 685 | CHECK(drivetrain_falcon_vector != nullptr); |
Maxwell Henderson | 9116e5b | 2024-01-21 12:14:26 -0800 | [diff] [blame] | 686 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 687 | for (auto talonfx : drivetrain_talonfxs) { |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 688 | talonfx->SerializePosition( |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 689 | drivetrain_falcon_vector->emplace_back(), |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 690 | control_loops::drivetrain::kHighOutputRatio); |
| 691 | } |
| 692 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 693 | drivetrain_can_builder->set_status(static_cast<int>(status)); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 694 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 695 | drivetrain_can_builder.CheckOk(drivetrain_can_builder.Send()); |
| 696 | |
| 697 | aos::Sender<y2024::control_loops::superstructure::CANPositionStatic>:: |
| 698 | StaticBuilder superstructure_can_builder = |
| 699 | superstructure_can_position_sender.MakeStaticBuilder(); |
| 700 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 701 | intake_pivot->SerializePosition( |
| 702 | superstructure_can_builder->add_intake_pivot(), |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 703 | control_loops::superstructure::intake_pivot::kOutputRatio); |
Niko Sohmers | 27d92c6 | 2024-02-19 14:15:07 -0800 | [diff] [blame] | 704 | turret->SerializePosition( |
| 705 | superstructure_can_builder->add_turret(), |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 706 | control_loops::superstructure::turret::kOutputRatio); |
| 707 | altitude->SerializePosition( |
| 708 | superstructure_can_builder->add_altitude(), |
| 709 | control_loops::superstructure::altitude::kOutputRatio); |
| 710 | catapult_one->SerializePosition( |
| 711 | superstructure_can_builder->add_catapult_one(), |
| 712 | control_loops::superstructure::catapult::kOutputRatio); |
| 713 | catapult_two->SerializePosition( |
| 714 | superstructure_can_builder->add_catapult_two(), |
| 715 | control_loops::superstructure::catapult::kOutputRatio); |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame] | 716 | if (extend != nullptr) { |
| 717 | extend->SerializePosition(superstructure_can_builder->add_extend(), |
| 718 | superstructure::extend::kOutputRatio); |
| 719 | } |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 720 | |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 721 | superstructure_can_builder->set_status(static_cast<int>(status)); |
| 722 | superstructure_can_builder.CheckOk(superstructure_can_builder.Send()); |
| 723 | }); |
| 724 | |
| 725 | aos::Sender<y2024::control_loops::superstructure::CANPositionStatic> |
| 726 | superstructure_rio_position_sender = |
| 727 | rio_sensor_reader_event_loop.MakeSender< |
| 728 | y2024::control_loops::superstructure::CANPositionStatic>( |
| 729 | "/superstructure/rio"); |
| 730 | |
| 731 | frc971::wpilib::CANSensorReader rio_can_sensor_reader( |
| 732 | &rio_sensor_reader_event_loop, std::move(rio_signal_registry), |
| 733 | rio_talonfxs, |
Austin Schuh | 95764db | 2024-03-01 19:21:09 -0800 | [diff] [blame] | 734 | [&intake_roller, &transfer_roller, &climber, &extend_roller, |
Maxwell Henderson | 7b7754b | 2024-02-22 16:50:35 -0800 | [diff] [blame] | 735 | &retention_roller, &superstructure_rio_position_sender]( |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 736 | ctre::phoenix::StatusCode status) { |
| 737 | aos::Sender<y2024::control_loops::superstructure::CANPositionStatic>:: |
| 738 | StaticBuilder superstructure_can_builder = |
| 739 | superstructure_rio_position_sender.MakeStaticBuilder(); |
| 740 | |
| 741 | intake_roller->SerializePosition( |
| 742 | superstructure_can_builder->add_intake_roller(), |
Filip Kujawa | ce385c3 | 2024-02-16 10:39:49 -0800 | [diff] [blame] | 743 | constants::Values::kIntakeRollerOutputRatio); |
Niko Sohmers | ed7ffc4 | 2024-02-03 16:05:19 -0800 | [diff] [blame] | 744 | transfer_roller->SerializePosition( |
| 745 | superstructure_can_builder->add_transfer_roller(), |
Filip Kujawa | ce385c3 | 2024-02-16 10:39:49 -0800 | [diff] [blame] | 746 | constants::Values::kIntakeRollerOutputRatio); |
| 747 | climber->SerializePosition(superstructure_can_builder->add_climber(), |
| 748 | superstructure::climber::kOutputRatio); |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 749 | extend_roller->SerializePosition( |
| 750 | superstructure_can_builder->add_extend_roller(), |
Filip Kujawa | ce385c3 | 2024-02-16 10:39:49 -0800 | [diff] [blame] | 751 | constants::Values::kExtendRollerOutputRatio); |
Maxwell Henderson | 7b7754b | 2024-02-22 16:50:35 -0800 | [diff] [blame] | 752 | retention_roller->SerializePosition( |
| 753 | superstructure_can_builder->add_retention_roller(), 1.0); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 754 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 755 | superstructure_can_builder->set_status(static_cast<int>(status)); |
| 756 | superstructure_can_builder.CheckOk(superstructure_can_builder.Send()); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 757 | }, |
| 758 | frc971::wpilib::CANSensorReader::SignalSync::kNoSync); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 759 | |
| 760 | AddLoop(&can_sensor_reader_event_loop); |
Niko Sohmers | 8427395 | 2024-02-14 18:40:55 -0800 | [diff] [blame] | 761 | AddLoop(&rio_sensor_reader_event_loop); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 762 | |
| 763 | // Thread 5. |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 764 | ::aos::ShmEventLoop can_output_event_loop(&config.message()); |
| 765 | can_output_event_loop.set_name("CANOutputWriter"); |
| 766 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 767 | frc971::wpilib::CANDrivetrainWriter can_drivetrain_writer( |
| 768 | &can_output_event_loop); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 769 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 770 | frc971::wpilib::GenericCANWriter<control_loops::superstructure::Output> |
| 771 | can_superstructure_writer( |
| 772 | &can_output_event_loop, |
| 773 | [](const control_loops::superstructure::Output &output, |
| 774 | const std::map<std::string_view, std::shared_ptr<TalonFX>> |
| 775 | &talonfx_map) { |
| 776 | talonfx_map.find("intake_pivot") |
| 777 | ->second->WriteVoltage(output.intake_pivot_voltage()); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 778 | talonfx_map.find("altitude") |
| 779 | ->second->WriteVoltage(output.altitude_voltage()); |
| 780 | talonfx_map.find("catapult_one") |
| 781 | ->second->WriteVoltage(output.catapult_voltage()); |
| 782 | talonfx_map.find("catapult_two") |
| 783 | ->second->WriteVoltage(output.catapult_voltage()); |
| 784 | talonfx_map.find("turret")->second->WriteVoltage( |
| 785 | output.turret_voltage()); |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 786 | talonfx_map.find("climber")->second->WriteVoltage( |
| 787 | output.climber_voltage()); |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame] | 788 | if (talonfx_map.find("extend") != talonfx_map.end()) { |
| 789 | talonfx_map.find("extend")->second->WriteVoltage( |
| 790 | output.extend_voltage()); |
| 791 | } |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 792 | talonfx_map.find("intake_roller") |
| 793 | ->second->WriteVoltage(output.intake_roller_voltage()); |
| 794 | talonfx_map.find("transfer_roller") |
| 795 | ->second->WriteVoltage(output.transfer_roller_voltage()); |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 796 | talonfx_map.find("extend_roller") |
| 797 | ->second->WriteVoltage(output.extend_roller_voltage()); |
Maxwell Henderson | 7b7754b | 2024-02-22 16:50:35 -0800 | [diff] [blame] | 798 | talonfx_map.find("retention_roller") |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 799 | ->second->WriteCurrent( |
| 800 | output.retention_roller_stator_current_limit(), |
| 801 | output.retention_roller_voltage()); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 802 | }); |
| 803 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 804 | can_drivetrain_writer.set_talonfxs({right_front, right_back}, |
| 805 | {left_front, left_back}); |
| 806 | |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 807 | can_superstructure_writer.add_talonfx("intake_pivot", intake_pivot); |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 808 | can_superstructure_writer.add_talonfx("altitude", altitude); |
| 809 | can_superstructure_writer.add_talonfx("catapult_one", catapult_one); |
| 810 | can_superstructure_writer.add_talonfx("catapult_two", catapult_two); |
| 811 | can_superstructure_writer.add_talonfx("turret", turret); |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 812 | can_superstructure_writer.add_talonfx("climber", climber); |
Niko Sohmers | 58461f5 | 2024-03-20 20:12:10 -0700 | [diff] [blame] | 813 | if (!robot_constants->robot()->disable_extend()) { |
Niko Sohmers | 77bf1fd | 2024-03-16 23:22:57 -0700 | [diff] [blame] | 814 | can_superstructure_writer.add_talonfx("extend", extend); |
| 815 | } |
Maxwell Henderson | 3d68e14 | 2024-02-25 09:58:11 -0800 | [diff] [blame] | 816 | can_superstructure_writer.add_talonfx("intake_roller", intake_roller); |
| 817 | can_superstructure_writer.add_talonfx("transfer_roller", transfer_roller); |
Filip Kujawa | d75252a | 2024-02-10 16:54:35 -0800 | [diff] [blame] | 818 | can_superstructure_writer.add_talonfx("extend_roller", extend_roller); |
Maxwell Henderson | 7b7754b | 2024-02-22 16:50:35 -0800 | [diff] [blame] | 819 | can_superstructure_writer.add_talonfx("retention_roller", retention_roller); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 820 | |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 821 | can_output_event_loop.MakeWatcher( |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 822 | "/roborio", [&can_drivetrain_writer, &can_superstructure_writer]( |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 823 | const frc971::CANConfiguration &configuration) { |
| 824 | can_drivetrain_writer.HandleCANConfiguration(configuration); |
Niko Sohmers | 1259b2a | 2024-01-29 18:00:37 -0800 | [diff] [blame] | 825 | can_superstructure_writer.HandleCANConfiguration(configuration); |
Maxwell Henderson | f75800f | 2024-01-12 19:52:05 -0800 | [diff] [blame] | 826 | }); |
| 827 | |
| 828 | AddLoop(&can_output_event_loop); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 829 | |
Filip Kujawa | 70183d6 | 2024-03-02 17:02:51 -0800 | [diff] [blame] | 830 | // Thread 6 |
| 831 | // Setup led_indicator |
| 832 | ::aos::ShmEventLoop led_indicator_event_loop(&config.message()); |
| 833 | led_indicator_event_loop.set_name("LedIndicator"); |
| 834 | control_loops::superstructure::LedIndicator led_indicator( |
| 835 | &led_indicator_event_loop); |
| 836 | AddLoop(&led_indicator_event_loop); |
| 837 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 838 | RunLoops(); |
| 839 | } |
| 840 | }; |
| 841 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 842 | } // namespace y2024::wpilib |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 843 | |
| 844 | AOS_ROBOT_CLASS(::y2024::wpilib::WPILibRobot); |