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