Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <array> |
| 4 | #include <chrono> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 5 | #include <cinttypes> |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 6 | #include <cmath> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 7 | #include <cstdio> |
| 8 | #include <cstring> |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 9 | #include <functional> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 10 | #include <memory> |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 11 | #include <mutex> |
| 12 | #include <thread> |
| 13 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 14 | #include "frc971/wpilib/ahal/AnalogInput.h" |
| 15 | #include "frc971/wpilib/ahal/Counter.h" |
| 16 | #include "frc971/wpilib/ahal/DigitalGlitchFilter.h" |
| 17 | #include "frc971/wpilib/ahal/DriverStation.h" |
| 18 | #include "frc971/wpilib/ahal/Encoder.h" |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 19 | #include "frc971/wpilib/ahal/TalonFX.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 20 | #include "frc971/wpilib/ahal/VictorSP.h" |
| 21 | #undef ERROR |
| 22 | |
| 23 | #include "aos/commonmath.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" |
Austin Schuh | 83873c3 | 2020-02-22 14:58:39 -0800 | [diff] [blame] | 28 | #include "aos/network/team_number.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 29 | #include "aos/realtime.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 30 | #include "aos/time/time.h" |
| 31 | #include "aos/util/log_interval.h" |
| 32 | #include "aos/util/phased_loop.h" |
| 33 | #include "aos/util/wrapping_counter.h" |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 34 | #include "ctre/phoenix/motorcontrol/can/TalonFX.h" |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 35 | #include "ctre/phoenix/motorcontrol/can/VictorSPX.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 36 | #include "frc971/autonomous/auto_mode_generated.h" |
| 37 | #include "frc971/control_loops/drivetrain/drivetrain_position_generated.h" |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 38 | #include "frc971/input/robot_state_generated.h" |
James Kuszmaul | a244a91 | 2020-01-18 13:50:50 -0800 | [diff] [blame] | 39 | #include "frc971/wpilib/ADIS16470.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 40 | #include "frc971/wpilib/buffered_pcm.h" |
| 41 | #include "frc971/wpilib/buffered_solenoid.h" |
| 42 | #include "frc971/wpilib/dma.h" |
| 43 | #include "frc971/wpilib/drivetrain_writer.h" |
| 44 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
| 45 | #include "frc971/wpilib/joystick_sender.h" |
| 46 | #include "frc971/wpilib/logging_generated.h" |
| 47 | #include "frc971/wpilib/loop_output_handler.h" |
| 48 | #include "frc971/wpilib/pdp_fetcher.h" |
| 49 | #include "frc971/wpilib/sensor_reader.h" |
| 50 | #include "frc971/wpilib/wpilib_robot_base.h" |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 51 | #include "gflags/gflags.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 52 | #include "y2020/constants.h" |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 53 | #include "y2020/control_loops/superstructure/shooter/shooter_tuning_readings_generated.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 54 | #include "y2020/control_loops/superstructure/superstructure_output_generated.h" |
| 55 | #include "y2020/control_loops/superstructure/superstructure_position_generated.h" |
| 56 | |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 57 | DEFINE_bool(shooter_tuning, true, |
| 58 | "If true, reads from ball beambreak sensors and sends shooter " |
| 59 | "tuning readings"); |
| 60 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 61 | using ::aos::monotonic_clock; |
| 62 | using ::y2020::constants::Values; |
| 63 | namespace superstructure = ::y2020::control_loops::superstructure; |
| 64 | namespace chrono = ::std::chrono; |
Vinay Siva | e52a6b3 | 2021-07-10 15:19:26 -0700 | [diff] [blame] | 65 | using std::make_unique; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 66 | |
| 67 | namespace y2020 { |
| 68 | namespace wpilib { |
| 69 | namespace { |
| 70 | |
| 71 | constexpr double kMaxBringupPower = 12.0; |
| 72 | |
| 73 | // TODO(Brian): Fix the interpretation of the result of GetRaw here and in the |
| 74 | // DMA stuff and then removing the * 2.0 in *_translate. |
| 75 | // The low bit is direction. |
| 76 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 77 | double drivetrain_translate(int32_t in) { |
| 78 | return ((static_cast<double>(in) / |
| 79 | Values::kDrivetrainEncoderCountsPerRevolution()) * |
| 80 | (2.0 * M_PI)) * |
| 81 | Values::kDrivetrainEncoderRatio() * |
| 82 | control_loops::drivetrain::kWheelRadius; |
| 83 | } |
| 84 | |
| 85 | double drivetrain_velocity_translate(double in) { |
| 86 | return (((1.0 / in) / Values::kDrivetrainCyclesPerRevolution()) * |
| 87 | (2.0 * M_PI)) * |
| 88 | Values::kDrivetrainEncoderRatio() * |
| 89 | control_loops::drivetrain::kWheelRadius; |
| 90 | } |
| 91 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 92 | double turret_pot_translate(double voltage) { |
| 93 | return voltage * Values::kTurretPotRatio() * |
| 94 | (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
| 95 | } |
| 96 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 97 | constexpr double kMaxFastEncoderPulsesPerSecond = |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 98 | std::max({Values::kMaxControlPanelEncoderPulsesPerSecond(), |
| 99 | Values::kMaxFinisherEncoderPulsesPerSecond(), |
| 100 | Values::kMaxAcceleratorEncoderPulsesPerSecond()}); |
| 101 | static_assert(kMaxFastEncoderPulsesPerSecond <= 1000000.0, |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 102 | "fast encoders are too fast"); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 103 | constexpr double kMaxMediumEncoderPulsesPerSecond = |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 104 | std::max({Values::kMaxDrivetrainEncoderPulsesPerSecond(), |
| 105 | Values::kMaxHoodEncoderPulsesPerSecond(), |
| 106 | Values::kMaxIntakeEncoderPulsesPerSecond(), |
| 107 | Values::kMaxTurretEncoderPulsesPerSecond()}); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 108 | |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 109 | static_assert(kMaxMediumEncoderPulsesPerSecond <= 400000.0, |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 110 | "medium encoders are too fast"); |
| 111 | |
| 112 | } // namespace |
| 113 | |
| 114 | // Class to send position messages with sensor readings to our loops. |
| 115 | class SensorReader : public ::frc971::wpilib::SensorReader { |
| 116 | public: |
| 117 | SensorReader(::aos::ShmEventLoop *event_loop) |
| 118 | : ::frc971::wpilib::SensorReader(event_loop), |
| 119 | auto_mode_sender_( |
| 120 | event_loop->MakeSender<::frc971::autonomous::AutonomousMode>( |
| 121 | "/autonomous")), |
| 122 | superstructure_position_sender_( |
| 123 | event_loop->MakeSender<superstructure::Position>( |
| 124 | "/superstructure")), |
| 125 | drivetrain_position_sender_( |
| 126 | event_loop |
| 127 | ->MakeSender<::frc971::control_loops::drivetrain::Position>( |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 128 | "/drivetrain")), |
| 129 | shooter_tuning_readings_sender_( |
| 130 | event_loop->MakeSender<superstructure::shooter::TuningReadings>( |
| 131 | "/superstructure")) { |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 132 | // Set to filter out anything shorter than 1/4 of the minimum pulse width |
| 133 | // we should ever see. |
| 134 | UpdateFastEncoderFilterHz(kMaxFastEncoderPulsesPerSecond); |
| 135 | UpdateMediumEncoderFilterHz(kMaxMediumEncoderPulsesPerSecond); |
| 136 | } |
| 137 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 138 | // Hood |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 139 | void set_hood_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
| 140 | medium_encoder_filter_.Add(encoder.get()); |
| 141 | hood_encoder_.set_encoder(::std::move(encoder)); |
| 142 | } |
| 143 | |
| 144 | void set_hood_absolute_pwm( |
| 145 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
| 146 | hood_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 147 | } |
| 148 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 149 | void set_hood_single_turn_absolute_pwm( |
| 150 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
| 151 | hood_encoder_.set_single_turn_absolute_pwm(::std::move(absolute_pwm)); |
| 152 | } |
| 153 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 154 | // Intake |
| 155 | |
| 156 | void set_intake_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
| 157 | medium_encoder_filter_.Add(encoder.get()); |
| 158 | intake_joint_encoder_.set_encoder(::std::move(encoder)); |
| 159 | } |
| 160 | |
| 161 | void set_intake_absolute_pwm( |
| 162 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
| 163 | intake_joint_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 164 | } |
| 165 | |
| 166 | // Turret |
| 167 | |
| 168 | void set_turret_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
| 169 | medium_encoder_filter_.Add(encoder.get()); |
| 170 | turret_encoder_.set_encoder(::std::move(encoder)); |
| 171 | } |
| 172 | |
| 173 | void set_turret_absolute_pwm( |
| 174 | ::std::unique_ptr<frc::DigitalInput> absolute_pwm) { |
| 175 | turret_encoder_.set_absolute_pwm(::std::move(absolute_pwm)); |
| 176 | } |
| 177 | |
| 178 | void set_turret_potentiometer( |
| 179 | ::std::unique_ptr<frc::AnalogInput> potentiometer) { |
| 180 | turret_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 181 | } |
| 182 | |
| 183 | // Shooter |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 184 | void set_finisher_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 185 | fast_encoder_filter_.Add(encoder.get()); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 186 | finisher_encoder_ = ::std::move(encoder); |
| 187 | } |
| 188 | void set_left_accelerator_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
| 189 | fast_encoder_filter_.Add(encoder.get()); |
| 190 | left_accelerator_encoder_ = ::std::move(encoder); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 193 | void set_right_accelerator_encoder(::std::unique_ptr<frc::Encoder> encoder) { |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 194 | fast_encoder_filter_.Add(encoder.get()); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 195 | right_accelerator_encoder_ = ::std::move(encoder); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 198 | // Auto mode switches. |
| 199 | void set_autonomous_mode(int i, ::std::unique_ptr<frc::DigitalInput> sensor) { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 200 | medium_encoder_filter_.Add(sensor.get()); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 201 | autonomous_modes_.at(i) = ::std::move(sensor); |
| 202 | } |
| 203 | |
James Kuszmaul | a244a91 | 2020-01-18 13:50:50 -0800 | [diff] [blame] | 204 | void set_imu(frc971::wpilib::ADIS16470 *imu) { imu_ = imu; } |
| 205 | |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 206 | void set_ball_beambreak_inputs(::std::unique_ptr<frc::DigitalInput> sensor1, |
| 207 | ::std::unique_ptr<frc::DigitalInput> sensor2) { |
| 208 | ball_beambreak_inputs_[0] = ::std::move(sensor1); |
| 209 | ball_beambreak_inputs_[1] = ::std::move(sensor2); |
| 210 | ball_beambreak_reader_.set_input_one(sensor1.get()); |
| 211 | ball_beambreak_reader_.set_input_two(sensor2.get()); |
| 212 | } |
| 213 | |
| 214 | void Start() override { |
| 215 | if (FLAGS_shooter_tuning) { |
| 216 | AddToDMA(&ball_beambreak_reader_); |
| 217 | } |
| 218 | } |
| 219 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 220 | void RunIteration() override { |
James Kuszmaul | a244a91 | 2020-01-18 13:50:50 -0800 | [diff] [blame] | 221 | CHECK_NOTNULL(imu_)->DoReads(); |
| 222 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 223 | { |
| 224 | auto builder = drivetrain_position_sender_.MakeBuilder(); |
| 225 | frc971::control_loops::drivetrain::Position::Builder drivetrain_builder = |
| 226 | builder.MakeBuilder<frc971::control_loops::drivetrain::Position>(); |
| 227 | drivetrain_builder.add_left_encoder( |
| 228 | drivetrain_translate(drivetrain_left_encoder_->GetRaw())); |
| 229 | drivetrain_builder.add_left_speed( |
| 230 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod())); |
| 231 | |
| 232 | drivetrain_builder.add_right_encoder( |
| 233 | -drivetrain_translate(drivetrain_right_encoder_->GetRaw())); |
| 234 | drivetrain_builder.add_right_speed(-drivetrain_velocity_translate( |
| 235 | drivetrain_right_encoder_->GetPeriod())); |
| 236 | |
| 237 | builder.Send(drivetrain_builder.Finish()); |
| 238 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 239 | const auto values = constants::GetValues(); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 240 | |
| 241 | { |
| 242 | auto builder = superstructure_position_sender_.MakeBuilder(); |
Austin Schuh | 18ca45f | 2020-02-29 22:58:49 -0800 | [diff] [blame] | 243 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 244 | // TODO(alex): check new absolute encoder api. |
| 245 | // Hood |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 246 | frc971::AbsoluteAndAbsolutePositionT hood; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 247 | CopyPosition(hood_encoder_, &hood, |
| 248 | Values::kHoodEncoderCountsPerRevolution(), |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 249 | Values::kHoodEncoderRatio(), |
| 250 | Values::kHoodSingleTurnEncoderRatio(), false); |
| 251 | flatbuffers::Offset<frc971::AbsoluteAndAbsolutePosition> hood_offset = |
| 252 | frc971::AbsoluteAndAbsolutePosition::Pack(*builder.fbb(), &hood); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 253 | |
| 254 | // Intake |
| 255 | frc971::AbsolutePositionT intake_joint; |
| 256 | CopyPosition(intake_joint_encoder_, &intake_joint, |
| 257 | Values::kIntakeEncoderCountsPerRevolution(), |
| 258 | Values::kIntakeEncoderRatio(), false); |
| 259 | flatbuffers::Offset<frc971::AbsolutePosition> intake_joint_offset = |
| 260 | frc971::AbsolutePosition::Pack(*builder.fbb(), &intake_joint); |
| 261 | |
| 262 | // Turret |
| 263 | frc971::PotAndAbsolutePositionT turret; |
| 264 | CopyPosition(turret_encoder_, &turret, |
| 265 | Values::kTurretEncoderCountsPerRevolution(), |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 266 | Values::kTurretEncoderRatio(), turret_pot_translate, true, |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 267 | values.turret.potentiometer_offset); |
| 268 | flatbuffers::Offset<frc971::PotAndAbsolutePosition> turret_offset = |
| 269 | frc971::PotAndAbsolutePosition::Pack(*builder.fbb(), &turret); |
| 270 | |
| 271 | // Shooter |
| 272 | y2020::control_loops::superstructure::ShooterPositionT shooter; |
| 273 | shooter.theta_finisher = |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 274 | encoder_translate(-finisher_encoder_->GetRaw(), |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 275 | Values::kFinisherEncoderCountsPerRevolution(), |
| 276 | Values::kFinisherEncoderRatio()); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 277 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 278 | shooter.theta_accelerator_left = |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 279 | encoder_translate(-left_accelerator_encoder_->GetRaw(), |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 280 | Values::kAcceleratorEncoderCountsPerRevolution(), |
| 281 | Values::kAcceleratorEncoderRatio()); |
| 282 | shooter.theta_accelerator_right = |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 283 | encoder_translate(right_accelerator_encoder_->GetRaw(), |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 284 | Values::kAcceleratorEncoderCountsPerRevolution(), |
| 285 | Values::kAcceleratorEncoderRatio()); |
| 286 | flatbuffers::Offset<y2020::control_loops::superstructure::ShooterPosition> |
| 287 | shooter_offset = |
| 288 | y2020::control_loops::superstructure::ShooterPosition::Pack( |
| 289 | *builder.fbb(), &shooter); |
| 290 | |
Austin Schuh | 18ca45f | 2020-02-29 22:58:49 -0800 | [diff] [blame] | 291 | superstructure::Position::Builder position_builder = |
| 292 | builder.MakeBuilder<superstructure::Position>(); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 293 | position_builder.add_hood(hood_offset); |
| 294 | position_builder.add_intake_joint(intake_joint_offset); |
| 295 | position_builder.add_turret(turret_offset); |
| 296 | position_builder.add_shooter(shooter_offset); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 297 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 298 | builder.Send(position_builder.Finish()); |
| 299 | } |
| 300 | |
| 301 | { |
| 302 | auto builder = auto_mode_sender_.MakeBuilder(); |
| 303 | |
| 304 | uint32_t mode = 0; |
| 305 | for (size_t i = 0; i < autonomous_modes_.size(); ++i) { |
| 306 | if (autonomous_modes_[i] && autonomous_modes_[i]->Get()) { |
| 307 | mode |= 1 << i; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | auto auto_mode_builder = |
| 312 | builder.MakeBuilder<frc971::autonomous::AutonomousMode>(); |
| 313 | |
| 314 | auto_mode_builder.add_mode(mode); |
| 315 | |
| 316 | builder.Send(auto_mode_builder.Finish()); |
| 317 | } |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 318 | |
| 319 | if (FLAGS_shooter_tuning && |
| 320 | ball_beambreak_reader_.pulses_detected() > balls_detected_) { |
| 321 | balls_detected_ = ball_beambreak_reader_.pulses_detected(); |
| 322 | |
| 323 | // Distance between beambreak sensors, in meters. |
| 324 | constexpr double kDistanceBetweenBeambreaks = 0.4813; |
| 325 | |
| 326 | auto builder = shooter_tuning_readings_sender_.MakeBuilder(); |
| 327 | auto shooter_tuning_readings_builder = |
| 328 | builder.MakeBuilder<superstructure::shooter::TuningReadings>(); |
| 329 | shooter_tuning_readings_builder.add_velocity_ball( |
| 330 | kDistanceBetweenBeambreaks / ball_beambreak_reader_.last_width()); |
| 331 | builder.Send(shooter_tuning_readings_builder.Finish()); |
| 332 | } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | private: |
| 336 | ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_; |
| 337 | ::aos::Sender<superstructure::Position> superstructure_position_sender_; |
| 338 | ::aos::Sender<::frc971::control_loops::drivetrain::Position> |
| 339 | drivetrain_position_sender_; |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 340 | ::aos::Sender<superstructure::shooter::TuningReadings> |
| 341 | shooter_tuning_readings_sender_; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 342 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 343 | ::frc971::wpilib::AbsoluteEncoderAndPotentiometer turret_encoder_; |
| 344 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 345 | ::frc971::wpilib::AbsoluteAndAbsoluteEncoder hood_encoder_; |
| 346 | |
| 347 | ::frc971::wpilib::AbsoluteEncoder intake_joint_encoder_; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 348 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 349 | ::std::unique_ptr<::frc::Encoder> finisher_encoder_, |
milind-u | 3d68aa7 | 2021-09-26 12:19:03 -0700 | [diff] [blame] | 350 | left_accelerator_encoder_, right_accelerator_encoder_; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 351 | ::std::array<::std::unique_ptr<frc::DigitalInput>, 2> autonomous_modes_; |
James Kuszmaul | a244a91 | 2020-01-18 13:50:50 -0800 | [diff] [blame] | 352 | |
| 353 | frc971::wpilib::ADIS16470 *imu_ = nullptr; |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 354 | |
| 355 | // Used to interface with the two beam break sensors that the ball for tuning |
| 356 | // shooter parameters has to pass through. |
| 357 | // We will time how long it takes to pass between the two sensors to get its |
| 358 | // velocity. |
| 359 | std::array<std::unique_ptr<frc::DigitalInput>, 2> ball_beambreak_inputs_; |
| 360 | frc971::wpilib::DMAPulseSeparationReader ball_beambreak_reader_; |
| 361 | int balls_detected_ = 0; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 362 | }; |
| 363 | |
| 364 | class SuperstructureWriter |
| 365 | : public ::frc971::wpilib::LoopOutputHandler<superstructure::Output> { |
| 366 | public: |
| 367 | SuperstructureWriter(::aos::EventLoop *event_loop) |
| 368 | : ::frc971::wpilib::LoopOutputHandler<superstructure::Output>( |
| 369 | event_loop, "/superstructure") {} |
| 370 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 371 | void set_hood_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 372 | hood_victor_ = ::std::move(t); |
| 373 | } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 374 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 375 | void set_intake_joint_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 376 | intake_joint_victor_ = ::std::move(t); |
| 377 | } |
| 378 | |
| 379 | void set_intake_roller_falcon( |
| 380 | ::std::unique_ptr<::ctre::phoenix::motorcontrol::can::TalonFX> t) { |
| 381 | intake_roller_falcon_ = ::std::move(t); |
| 382 | intake_roller_falcon_->ConfigSupplyCurrentLimit( |
| 383 | {true, Values::kIntakeRollerSupplyCurrentLimit(), |
| 384 | Values::kIntakeRollerSupplyCurrentLimit(), 0}); |
| 385 | intake_roller_falcon_->ConfigStatorCurrentLimit( |
| 386 | {true, Values::kIntakeRollerStatorCurrentLimit(), |
| 387 | Values::kIntakeRollerStatorCurrentLimit(), 0}); |
| 388 | } |
| 389 | |
| 390 | void set_turret_victor(::std::unique_ptr<::frc::VictorSP> t) { |
| 391 | turret_victor_ = ::std::move(t); |
| 392 | } |
| 393 | |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 394 | void set_feeder_falcon( |
| 395 | ::std::unique_ptr<::ctre::phoenix::motorcontrol::can::TalonFX> t) { |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 396 | feeder_falcon_ = ::std::move(t); |
Austin Schuh | 3399d12 | 2021-03-20 14:29:20 -0700 | [diff] [blame] | 397 | { |
| 398 | auto result = feeder_falcon_->ConfigSupplyCurrentLimit( |
| 399 | {true, Values::kFeederSupplyCurrentLimit(), |
| 400 | Values::kFeederSupplyCurrentLimit(), 0}); |
| 401 | if (result != ctre::phoenix::OKAY) { |
| 402 | LOG(WARNING) << "Failed to configure feeder supply current limit: " |
| 403 | << result; |
| 404 | } |
| 405 | } |
| 406 | { |
| 407 | auto result = feeder_falcon_->ConfigStatorCurrentLimit( |
| 408 | {true, Values::kFeederStatorCurrentLimit(), |
| 409 | Values::kFeederStatorCurrentLimit(), 0}); |
| 410 | if (result != ctre::phoenix::OKAY) { |
| 411 | LOG(WARNING) << "Failed to configure feeder stator current limit: " |
| 412 | << result; |
| 413 | } |
| 414 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 417 | void set_accelerator_left_falcon(::std::unique_ptr<::frc::TalonFX> t) { |
| 418 | accelerator_left_falcon_ = ::std::move(t); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 421 | void set_accelerator_right_falcon(::std::unique_ptr<::frc::TalonFX> t) { |
| 422 | accelerator_right_falcon_ = ::std::move(t); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 425 | void set_finisher_falcon0(::std::unique_ptr<::frc::TalonFX> t) { |
| 426 | finisher_falcon0_ = ::std::move(t); |
| 427 | } |
| 428 | |
| 429 | void set_finisher_falcon1(::std::unique_ptr<::frc::TalonFX> t) { |
| 430 | finisher_falcon1_ = ::std::move(t); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void set_climber_falcon( |
| 434 | ::std::unique_ptr<::ctre::phoenix::motorcontrol::can::TalonFX> t) { |
| 435 | climber_falcon_ = ::std::move(t); |
| 436 | climber_falcon_->ConfigSupplyCurrentLimit( |
| 437 | {true, Values::kClimberSupplyCurrentLimit(), |
| 438 | Values::kClimberSupplyCurrentLimit(), 0}); |
| 439 | } |
| 440 | |
| 441 | private: |
| 442 | void Write(const superstructure::Output &output) override { |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 443 | hood_victor_->SetSpeed(std::clamp(-output.hood_voltage(), -kMaxBringupPower, |
| 444 | kMaxBringupPower) / |
| 445 | 12.0); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 446 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 447 | intake_joint_victor_->SetSpeed(std::clamp(-output.intake_joint_voltage(), |
| 448 | -kMaxBringupPower, |
| 449 | kMaxBringupPower) / |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 450 | 12.0); |
| 451 | |
| 452 | intake_roller_falcon_->Set( |
| 453 | ctre::phoenix::motorcontrol::ControlMode::PercentOutput, |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 454 | std::clamp(-output.intake_roller_voltage(), -kMaxBringupPower, |
| 455 | kMaxBringupPower) / |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 456 | 12.0); |
| 457 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 458 | turret_victor_->SetSpeed(std::clamp(-output.turret_voltage(), |
| 459 | -kMaxBringupPower, kMaxBringupPower) / |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 460 | 12.0); |
| 461 | |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 462 | feeder_falcon_->Set(ctre::phoenix::motorcontrol::ControlMode::PercentOutput, |
| 463 | std::clamp(output.feeder_voltage(), -kMaxBringupPower, |
| 464 | kMaxBringupPower) / |
| 465 | 12.0); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 466 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 467 | accelerator_left_falcon_->SetSpeed( |
| 468 | std::clamp(-output.accelerator_left_voltage(), -kMaxBringupPower, |
| 469 | kMaxBringupPower) / |
| 470 | 12.0); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 471 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 472 | accelerator_right_falcon_->SetSpeed( |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 473 | std::clamp(output.accelerator_right_voltage(), -kMaxBringupPower, |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 474 | kMaxBringupPower) / |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 475 | 12.0); |
| 476 | |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 477 | finisher_falcon1_->SetSpeed(std::clamp(output.finisher_voltage(), |
| 478 | -kMaxBringupPower, |
| 479 | kMaxBringupPower) / |
| 480 | 12.0); |
| 481 | finisher_falcon0_->SetSpeed(std::clamp(-output.finisher_voltage(), |
| 482 | -kMaxBringupPower, |
| 483 | kMaxBringupPower) / |
| 484 | 12.0); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 485 | |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 486 | if (climber_falcon_) { |
| 487 | climber_falcon_->Set( |
| 488 | ctre::phoenix::motorcontrol::ControlMode::PercentOutput, |
Tyler Chatow | 1039e43 | 2020-02-28 21:37:50 -0800 | [diff] [blame] | 489 | std::clamp(-output.climber_voltage(), -kMaxBringupPower, |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 490 | kMaxBringupPower) / |
| 491 | 12.0); |
| 492 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void Stop() override { |
| 496 | AOS_LOG(WARNING, "Superstructure output too old.\n"); |
| 497 | hood_victor_->SetDisabled(); |
| 498 | intake_joint_victor_->SetDisabled(); |
| 499 | turret_victor_->SetDisabled(); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 500 | accelerator_left_falcon_->SetDisabled(); |
| 501 | accelerator_right_falcon_->SetDisabled(); |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 502 | finisher_falcon0_->SetDisabled(); |
| 503 | finisher_falcon1_->SetDisabled(); |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 504 | feeder_falcon_->Set(ctre::phoenix::motorcontrol::ControlMode::Disabled, 0); |
| 505 | intake_roller_falcon_->Set( |
| 506 | ctre::phoenix::motorcontrol::ControlMode::Disabled, 0); |
| 507 | climber_falcon_->Set(ctre::phoenix::motorcontrol::ControlMode::Disabled, 0); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | ::std::unique_ptr<::frc::VictorSP> hood_victor_, intake_joint_victor_, |
milind-u | 3d68aa7 | 2021-09-26 12:19:03 -0700 | [diff] [blame] | 511 | turret_victor_; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 512 | |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 513 | ::std::unique_ptr<::frc::TalonFX> accelerator_left_falcon_, |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 514 | accelerator_right_falcon_, finisher_falcon0_, finisher_falcon1_; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 515 | |
| 516 | ::std::unique_ptr<::ctre::phoenix::motorcontrol::can::TalonFX> |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 517 | intake_roller_falcon_, climber_falcon_, feeder_falcon_; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 521 | public: |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 522 | ::std::unique_ptr<frc::Encoder> make_encoder( |
| 523 | int index, frc::Encoder::EncodingType encodingType = frc::Encoder::k4X) { |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 524 | return make_unique<frc::Encoder>(10 + index * 2, 11 + index * 2, false, |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 525 | encodingType); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void Run() override { |
| 529 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 530 | aos::configuration::ReadConfig("config.json"); |
| 531 | |
| 532 | // Thread 1. |
| 533 | ::aos::ShmEventLoop joystick_sender_event_loop(&config.message()); |
| 534 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 535 | &joystick_sender_event_loop); |
| 536 | AddLoop(&joystick_sender_event_loop); |
| 537 | |
| 538 | // Thread 2. |
| 539 | ::aos::ShmEventLoop pdp_fetcher_event_loop(&config.message()); |
| 540 | ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop); |
| 541 | AddLoop(&pdp_fetcher_event_loop); |
| 542 | |
| 543 | // Thread 3. |
| 544 | ::aos::ShmEventLoop sensor_reader_event_loop(&config.message()); |
| 545 | SensorReader sensor_reader(&sensor_reader_event_loop); |
Austin Schuh | f7db58c | 2020-02-29 22:57:43 -0800 | [diff] [blame] | 546 | sensor_reader.set_pwm_trigger(true); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 547 | sensor_reader.set_drivetrain_left_encoder(make_encoder(0)); |
| 548 | sensor_reader.set_drivetrain_right_encoder(make_encoder(1)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 549 | // TODO: pin numbers |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 550 | sensor_reader.set_hood_encoder( |
| 551 | make_unique<frc::Encoder>(22, 23, false, frc::Encoder::k4X)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 552 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 553 | sensor_reader.set_hood_absolute_pwm(make_unique<frc::DigitalInput>(25)); |
| 554 | sensor_reader.set_hood_single_turn_absolute_pwm( |
| 555 | make_unique<frc::DigitalInput>(24)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 556 | |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 557 | sensor_reader.set_intake_encoder(make_encoder(5)); |
| 558 | sensor_reader.set_intake_absolute_pwm(make_unique<frc::DigitalInput>(1)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 559 | |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 560 | sensor_reader.set_turret_encoder(make_encoder(2)); |
| 561 | sensor_reader.set_turret_absolute_pwm(make_unique<frc::DigitalInput>(0)); |
| 562 | sensor_reader.set_turret_potentiometer(make_unique<frc::AnalogInput>(0)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 563 | |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 564 | sensor_reader.set_finisher_encoder( |
| 565 | make_unique<frc::Encoder>(3, 2, false, frc::Encoder::k4X)); |
| 566 | sensor_reader.set_left_accelerator_encoder(make_encoder(4)); |
| 567 | sensor_reader.set_right_accelerator_encoder(make_encoder(3)); |
| 568 | |
milind-u | 4b31c4d | 2021-09-18 16:08:23 -0700 | [diff] [blame] | 569 | if (FLAGS_shooter_tuning) { |
| 570 | sensor_reader.set_ball_beambreak_inputs( |
| 571 | make_unique<frc::DigitalInput>(6), make_unique<frc::DigitalInput>(7)); |
| 572 | } |
| 573 | |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 574 | // Note: If ADIS16470 is plugged in directly to the roboRIO SPI port without |
| 575 | // the Spartan Board, then trigger is on 26, reset 27, and chip select is |
| 576 | // CS0. |
Austin Schuh | 83873c3 | 2020-02-22 14:58:39 -0800 | [diff] [blame] | 577 | frc::SPI::Port spi_port = frc::SPI::Port::kOnboardCS2; |
| 578 | std::unique_ptr<frc::DigitalInput> imu_trigger; |
| 579 | std::unique_ptr<frc::DigitalOutput> imu_reset; |
| 580 | if (::aos::network::GetTeamNumber() == |
| 581 | constants::Values::kCodingRobotTeamNumber) { |
| 582 | imu_trigger = make_unique<frc::DigitalInput>(26); |
| 583 | imu_reset = make_unique<frc::DigitalOutput>(27); |
| 584 | spi_port = frc::SPI::Port::kOnboardCS0; |
| 585 | } else { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 586 | imu_trigger = make_unique<frc::DigitalInput>(9); |
| 587 | imu_reset = make_unique<frc::DigitalOutput>(8); |
Austin Schuh | 83873c3 | 2020-02-22 14:58:39 -0800 | [diff] [blame] | 588 | } |
| 589 | auto spi = make_unique<frc::SPI>(spi_port); |
James Kuszmaul | a244a91 | 2020-01-18 13:50:50 -0800 | [diff] [blame] | 590 | frc971::wpilib::ADIS16470 imu(&sensor_reader_event_loop, spi.get(), |
| 591 | imu_trigger.get(), imu_reset.get()); |
| 592 | sensor_reader.set_imu(&imu); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 593 | AddLoop(&sensor_reader_event_loop); |
| 594 | |
| 595 | // Thread 4. |
| 596 | ::aos::ShmEventLoop output_event_loop(&config.message()); |
James Kuszmaul | 57c2baa | 2020-01-19 14:52:52 -0800 | [diff] [blame] | 597 | output_event_loop.set_name("output_writer"); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 598 | ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop); |
| 599 | drivetrain_writer.set_left_controller0( |
| 600 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(0)), true); |
| 601 | drivetrain_writer.set_right_controller0( |
| 602 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(1)), false); |
| 603 | |
| 604 | SuperstructureWriter superstructure_writer(&output_event_loop); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 605 | superstructure_writer.set_hood_victor(make_unique<frc::VictorSP>(8)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 606 | superstructure_writer.set_intake_joint_victor( |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 607 | make_unique<frc::VictorSP>(2)); |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 608 | superstructure_writer.set_intake_roller_falcon( |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 609 | make_unique<::ctre::phoenix::motorcontrol::can::TalonFX>(0)); |
| 610 | superstructure_writer.set_turret_victor(make_unique<frc::VictorSP>(7)); |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 611 | superstructure_writer.set_feeder_falcon( |
| 612 | make_unique<ctre::phoenix::motorcontrol::can::TalonFX>(1)); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 613 | superstructure_writer.set_accelerator_left_falcon( |
| 614 | make_unique<::frc::TalonFX>(5)); |
| 615 | superstructure_writer.set_accelerator_right_falcon( |
| 616 | make_unique<::frc::TalonFX>(4)); |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 617 | superstructure_writer.set_finisher_falcon0(make_unique<::frc::TalonFX>(9)); |
| 618 | superstructure_writer.set_finisher_falcon1(make_unique<::frc::TalonFX>(3)); |
Sabina Davis | c2e4bdb | 2020-02-23 13:44:58 -0800 | [diff] [blame] | 619 | // TODO: check port |
Tyler Chatow | 1039e43 | 2020-02-28 21:37:50 -0800 | [diff] [blame] | 620 | superstructure_writer.set_climber_falcon( |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 621 | make_unique<::ctre::phoenix::motorcontrol::can::TalonFX>(2)); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 622 | |
| 623 | AddLoop(&output_event_loop); |
| 624 | |
| 625 | RunLoops(); |
| 626 | } |
| 627 | }; |
| 628 | |
| 629 | } // namespace wpilib |
| 630 | } // namespace y2020 |
| 631 | |
| 632 | AOS_ROBOT_CLASS(::y2020::wpilib::WPILibRobot); |