Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 1 | #include <inttypes.h> |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 5 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 6 | #include <array> |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 7 | #include <chrono> |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 8 | #include <cmath> |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 9 | #include <functional> |
| 10 | #include <mutex> |
| 11 | #include <thread> |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 12 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 13 | #include "frc971/wpilib/ahal/AnalogInput.h" |
| 14 | #include "frc971/wpilib/ahal/Compressor.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" |
| 19 | #include "frc971/wpilib/ahal/Relay.h" |
| 20 | #include "frc971/wpilib/ahal/Servo.h" |
| 21 | #include "frc971/wpilib/ahal/VictorSP.h" |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 22 | #undef ERROR |
| 23 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 24 | #include "aos/commonmath.h" |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 25 | #include "aos/events/shm-event-loop.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 26 | #include "aos/init.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 27 | #include "aos/logging/logging.h" |
| 28 | #include "aos/logging/queue_logging.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 29 | #include "aos/make_unique.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 30 | #include "aos/robot_state/robot_state.q.h" |
| 31 | #include "aos/stl_mutex/stl_mutex.h" |
| 32 | #include "aos/time/time.h" |
| 33 | #include "aos/util/compiler_memory_barrier.h" |
| 34 | #include "aos/util/log_interval.h" |
| 35 | #include "aos/util/phased_loop.h" |
| 36 | #include "aos/util/wrapping_counter.h" |
Philipp Schrader | 996a2a2 | 2017-02-22 05:02:48 +0000 | [diff] [blame] | 37 | #include "frc971/autonomous/auto.q.h" |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 38 | #include "frc971/control_loops/control_loops.q.h" |
| 39 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 40 | #include "frc971/wpilib/ADIS16448.h" |
| 41 | #include "frc971/wpilib/buffered_pcm.h" |
| 42 | #include "frc971/wpilib/buffered_solenoid.h" |
| 43 | #include "frc971/wpilib/dma.h" |
| 44 | #include "frc971/wpilib/dma_edge_counting.h" |
Sabina Davis | 7af11ad | 2019-02-03 01:16:45 -0800 | [diff] [blame] | 45 | #include "frc971/wpilib/drivetrain_writer.h" |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 46 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
| 47 | #include "frc971/wpilib/interrupt_edge_counting.h" |
| 48 | #include "frc971/wpilib/joystick_sender.h" |
| 49 | #include "frc971/wpilib/logging.q.h" |
| 50 | #include "frc971/wpilib/loop_output_handler.h" |
| 51 | #include "frc971/wpilib/pdp_fetcher.h" |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 52 | #include "frc971/wpilib/sensor_reader.h" |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 53 | #include "frc971/wpilib/wpilib_robot_base.h" |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 54 | #include "y2017/constants.h" |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 55 | #include "y2017/control_loops/superstructure/superstructure.q.h" |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 56 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 57 | #ifndef M_PI |
| 58 | #define M_PI 3.14159265358979323846 |
| 59 | #endif |
| 60 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 61 | using ::y2017::control_loops::SuperstructureQueue; |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 62 | using ::y2017::constants::Values; |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 63 | using ::aos::monotonic_clock; |
| 64 | namespace chrono = ::std::chrono; |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 65 | using namespace frc; |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 66 | using aos::make_unique; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 67 | |
| 68 | namespace y2017 { |
| 69 | namespace wpilib { |
| 70 | namespace { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 71 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 72 | constexpr double kMaxBringupPower = 12.0; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 73 | |
| 74 | // TODO(Brian): Fix the interpretation of the result of GetRaw here and in the |
| 75 | // DMA stuff and then removing the * 2.0 in *_translate. |
| 76 | // The low bit is direction. |
| 77 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 78 | // TODO(brian): Use ::std::max instead once we have C++14 so that can be |
| 79 | // constexpr. |
| 80 | template <typename T> |
| 81 | constexpr T max(T a, T b) { |
| 82 | return (a > b) ? a : b; |
| 83 | } |
| 84 | template <typename T, typename... Rest> |
| 85 | constexpr T max(T a, T b, T c, Rest... rest) { |
| 86 | return max(max(a, b), c, rest...); |
| 87 | } |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 88 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 89 | double drivetrain_translate(int32_t in) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 90 | return static_cast<double>(in) / |
| 91 | Values::kDrivetrainEncoderCountsPerRevolution * |
| 92 | Values::kDrivetrainEncoderRatio * 2.0 * M_PI; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | double drivetrain_velocity_translate(double in) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 96 | return (1.0 / in) / Values::kDrivetrainCyclesPerRevolution * |
| 97 | Values::kDrivetrainEncoderRatio * 2.0 * M_PI; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 100 | // TODO(Travis): Make sure the number of turns is right. |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 101 | double intake_pot_translate(double voltage) { |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 102 | return voltage * Values::kIntakePotRatio * (3.0 /*turns*/ / 5.0 /*volts*/) * |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 103 | (2 * M_PI /*radians*/); |
| 104 | } |
| 105 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 106 | constexpr double kMaxFastEncoderPulsesPerSecond = |
| 107 | max(Values::kMaxDrivetrainEncoderPulsesPerSecond, |
| 108 | Values::kMaxShooterEncoderPulsesPerSecond); |
| 109 | static_assert(kMaxFastEncoderPulsesPerSecond <= 1300000, |
| 110 | "fast encoders are too fast"); |
| 111 | constexpr double kMaxMediumEncoderPulsesPerSecond = |
| 112 | max(Values::kMaxIntakeEncoderPulsesPerSecond, |
| 113 | Values::kMaxTurretEncoderPulsesPerSecond, |
| 114 | Values::kMaxIndexerEncoderPulsesPerSecond); |
| 115 | static_assert(kMaxMediumEncoderPulsesPerSecond <= 400000, |
| 116 | "medium encoders are too fast"); |
| 117 | constexpr double kMaxSlowEncoderPulsesPerSecond = |
| 118 | Values::kMaxHoodEncoderPulsesPerSecond; |
| 119 | static_assert(kMaxSlowEncoderPulsesPerSecond <= 100000, |
| 120 | "slow encoders are too fast"); |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 121 | static_assert(kMaxSlowEncoderPulsesPerSecond < kMaxMediumEncoderPulsesPerSecond, |
| 122 | "slow encoders are faster than medium?"); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 123 | |
| 124 | // Class to send position messages with sensor readings to our loops. |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 125 | class SensorReader : public ::frc971::wpilib::SensorReader { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 126 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 127 | SensorReader(::aos::EventLoop *event_loop) |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 128 | : ::frc971::wpilib::SensorReader(event_loop), |
| 129 | auto_mode_sender_( |
| 130 | event_loop->MakeSender<::frc971::autonomous::AutonomousMode>( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 131 | ".frc971.autonomous.auto_mode")), |
| 132 | superstructure_position_sender_( |
| 133 | event_loop->MakeSender<SuperstructureQueue::Position>( |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 134 | ".y2017.control_loops.superstructure_queue.position")), |
| 135 | drivetrain_position_sender_( |
| 136 | event_loop->MakeSender< |
| 137 | ::frc971::control_loops::DrivetrainQueue::Position>( |
| 138 | ".frc971.control_loops.drivetrain_queue.position")) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 139 | // Set to filter out anything shorter than 1/4 of the minimum pulse width |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 140 | // we should ever see. |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 141 | UpdateFastEncoderFilterHz(kMaxFastEncoderPulsesPerSecond); |
| 142 | UpdateMediumEncoderFilterHz(kMaxMediumEncoderPulsesPerSecond); |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 143 | hall_filter_.SetPeriodNanoSeconds(100000); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 146 | void set_shooter_encoder(::std::unique_ptr<Encoder> encoder) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 147 | fast_encoder_filter_.Add(encoder.get()); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 148 | shooter_encoder_ = ::std::move(encoder); |
| 149 | } |
| 150 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 151 | void set_intake_encoder(::std::unique_ptr<Encoder> encoder) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 152 | medium_encoder_filter_.Add(encoder.get()); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 153 | intake_encoder_.set_encoder(::std::move(encoder)); |
| 154 | } |
| 155 | |
| 156 | void set_intake_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) { |
| 157 | intake_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 158 | } |
| 159 | |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 160 | void set_intake_absolute(::std::unique_ptr<DigitalInput> input) { |
| 161 | intake_encoder_.set_absolute_pwm(::std::move(input)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 164 | void set_indexer_encoder(::std::unique_ptr<Encoder> encoder) { |
| 165 | medium_encoder_filter_.Add(encoder.get()); |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 166 | indexer_counter_.set_encoder(encoder.get()); |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 167 | indexer_encoder_ = ::std::move(encoder); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 170 | void set_indexer_hall(::std::unique_ptr<DigitalInput> input) { |
| 171 | hall_filter_.Add(input.get()); |
| 172 | indexer_counter_.set_input(input.get()); |
| 173 | indexer_hall_ = ::std::move(input); |
| 174 | } |
| 175 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 176 | void set_turret_encoder(::std::unique_ptr<Encoder> encoder) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 177 | medium_encoder_filter_.Add(encoder.get()); |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 178 | turret_counter_.set_encoder(encoder.get()); |
| 179 | turret_encoder_ = ::std::move(encoder); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 182 | void set_turret_hall(::std::unique_ptr<DigitalInput> input) { |
| 183 | hall_filter_.Add(input.get()); |
| 184 | turret_counter_.set_input(input.get()); |
| 185 | turret_hall_ = ::std::move(input); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 188 | void set_hood_encoder(::std::unique_ptr<Encoder> encoder) { |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 189 | medium_encoder_filter_.Add(encoder.get()); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 190 | hood_encoder_.set_encoder(::std::move(encoder)); |
| 191 | } |
| 192 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 193 | void set_hood_index(::std::unique_ptr<DigitalInput> index) { |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 194 | medium_encoder_filter_.Add(index.get()); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 195 | hood_encoder_.set_index(::std::move(index)); |
| 196 | } |
| 197 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 198 | void set_autonomous_mode(int i, ::std::unique_ptr<DigitalInput> sensor) { |
| 199 | autonomous_modes_.at(i) = ::std::move(sensor); |
| 200 | } |
| 201 | |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 202 | void Start() { |
| 203 | AddToDMA(&indexer_counter_); |
| 204 | AddToDMA(&hood_encoder_); |
| 205 | AddToDMA(&turret_counter_); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void RunIteration() { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 209 | { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 210 | auto drivetrain_message = drivetrain_position_sender_.MakeMessage(); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 211 | drivetrain_message->right_encoder = |
| 212 | drivetrain_translate(drivetrain_right_encoder_->GetRaw()); |
Austin Schuh | 0fc1e6d | 2017-02-21 02:04:10 -0800 | [diff] [blame] | 213 | drivetrain_message->right_speed = |
| 214 | drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod()); |
| 215 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 216 | drivetrain_message->left_encoder = |
| 217 | -drivetrain_translate(drivetrain_left_encoder_->GetRaw()); |
| 218 | drivetrain_message->left_speed = |
| 219 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod()); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 220 | |
| 221 | drivetrain_message.Send(); |
| 222 | } |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 223 | } |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 224 | |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 225 | void RunDMAIteration() { |
| 226 | const auto values = constants::GetValues(); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 227 | |
| 228 | { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 229 | auto superstructure_message = superstructure_position_sender_.MakeMessage(); |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 230 | CopyPosition(intake_encoder_, &superstructure_message->intake, |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 231 | Values::kIntakeEncoderCountsPerRevolution, |
Austin Schuh | 0fc1e6d | 2017-02-21 02:04:10 -0800 | [diff] [blame] | 232 | Values::kIntakeEncoderRatio, intake_pot_translate, true, |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 233 | values.intake.pot_offset); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 234 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 235 | CopyPosition(indexer_counter_, &superstructure_message->column.indexer, |
| 236 | Values::kIndexerEncoderCountsPerRevolution, |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 237 | Values::kIndexerEncoderRatio, true); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 238 | |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 239 | superstructure_message->theta_shooter = |
| 240 | encoder_translate(shooter_encoder_->GetRaw(), |
| 241 | Values::kShooterEncoderCountsPerRevolution, |
| 242 | Values::kShooterEncoderRatio); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 243 | |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 244 | CopyPosition(hood_encoder_, &superstructure_message->hood, |
| 245 | Values::kHoodEncoderCountsPerRevolution, |
Austin Schuh | 0fc1e6d | 2017-02-21 02:04:10 -0800 | [diff] [blame] | 246 | Values::kHoodEncoderRatio, true); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 247 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 248 | CopyPosition(turret_counter_, &superstructure_message->column.turret, |
Brian Silverman | 50826c0 | 2017-02-18 14:40:25 -0800 | [diff] [blame] | 249 | Values::kTurretEncoderCountsPerRevolution, |
Austin Schuh | d5ccb86 | 2017-03-11 22:06:36 -0800 | [diff] [blame] | 250 | Values::kTurretEncoderRatio, false); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 251 | |
| 252 | superstructure_message.Send(); |
| 253 | } |
| 254 | |
| 255 | { |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 256 | auto auto_mode_message = auto_mode_sender_.MakeMessage(); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 257 | auto_mode_message->mode = 0; |
| 258 | for (size_t i = 0; i < autonomous_modes_.size(); ++i) { |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 259 | if (autonomous_modes_[i] && autonomous_modes_[i]->Get()) { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 260 | auto_mode_message->mode |= 1 << i; |
| 261 | } |
| 262 | } |
| 263 | LOG_STRUCT(DEBUG, "auto mode", *auto_mode_message); |
| 264 | auto_mode_message.Send(); |
| 265 | } |
| 266 | } |
| 267 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 268 | private: |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 269 | ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_; |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 270 | ::aos::Sender<SuperstructureQueue::Position> superstructure_position_sender_; |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 271 | ::aos::Sender<::frc971::control_loops::DrivetrainQueue::Position> |
| 272 | drivetrain_position_sender_; |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 273 | |
Austin Schuh | bf29b6f | 2019-02-02 21:45:27 -0800 | [diff] [blame] | 274 | DigitalGlitchFilter hall_filter_; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 275 | |
Austin Schuh | 2a3e063 | 2018-02-19 16:24:49 -0800 | [diff] [blame] | 276 | ::frc971::wpilib::AbsoluteEncoderAndPotentiometer intake_encoder_; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 277 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 278 | ::std::unique_ptr<Encoder> indexer_encoder_; |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 279 | ::std::unique_ptr<DigitalInput> indexer_hall_; |
| 280 | ::frc971::wpilib::DMAEdgeCounter indexer_counter_; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 281 | |
Brian | ef030df | 2017-03-05 15:06:04 -0800 | [diff] [blame] | 282 | ::std::unique_ptr<Encoder> turret_encoder_; |
| 283 | ::std::unique_ptr<DigitalInput> turret_hall_; |
| 284 | ::frc971::wpilib::DMAEdgeCounter turret_counter_; |
| 285 | |
Brian Silverman | 7cce2d3 | 2017-02-19 21:48:48 -0800 | [diff] [blame] | 286 | ::frc971::wpilib::DMAEncoder hood_encoder_; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 287 | ::std::unique_ptr<Encoder> shooter_encoder_; |
| 288 | |
| 289 | ::std::array<::std::unique_ptr<DigitalInput>, 4> autonomous_modes_; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 290 | }; |
| 291 | |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 292 | class SolenoidWriter { |
| 293 | public: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 294 | SolenoidWriter(::aos::EventLoop *event_loop) |
| 295 | : superstructure_output_fetcher_( |
| 296 | event_loop->MakeFetcher<SuperstructureQueue::Output>( |
| 297 | ".y2017.control_loops.superstructure_queue.output")) { |
| 298 | event_loop->set_name("Solenoids"); |
| 299 | event_loop->SetRuntimeRealtimePriority(27); |
| 300 | |
| 301 | event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); }, |
| 302 | ::std::chrono::milliseconds(20), |
| 303 | ::std::chrono::milliseconds(1)); |
| 304 | } |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 305 | |
| 306 | ::frc971::wpilib::BufferedPcm *pcm() { return &pcm_; } |
| 307 | |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 308 | void set_lights(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 309 | lights_ = ::std::move(s); |
| 310 | } |
| 311 | |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 312 | void set_rgb_light(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 313 | rgb_lights_ = ::std::move(s); |
| 314 | } |
| 315 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 316 | void Loop(const int iterations) { |
| 317 | if (iterations != 1) { |
| 318 | LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 319 | } |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 320 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 321 | { |
| 322 | superstructure_output_fetcher_.Fetch(); |
| 323 | if (superstructure_output_fetcher_.get()) { |
| 324 | LOG_STRUCT(DEBUG, "solenoids", *superstructure_output_fetcher_); |
| 325 | lights_->Set(superstructure_output_fetcher_->lights_on); |
| 326 | rgb_lights_->Set(superstructure_output_fetcher_->red_light_on | |
| 327 | superstructure_output_fetcher_->green_light_on | |
| 328 | superstructure_output_fetcher_->blue_light_on); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | pcm_.Flush(); |
| 333 | } |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 334 | |
| 335 | private: |
| 336 | ::frc971::wpilib::BufferedPcm pcm_; |
| 337 | |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 338 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> lights_, rgb_lights_; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 339 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 340 | ::aos::Fetcher<::y2017::control_loops::SuperstructureQueue::Output> |
| 341 | superstructure_output_fetcher_; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 342 | }; |
| 343 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 344 | class SuperstructureWriter |
| 345 | : public ::frc971::wpilib::LoopOutputHandler<SuperstructureQueue::Output> { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 346 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 347 | SuperstructureWriter(::aos::EventLoop *event_loop) |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 348 | : ::frc971::wpilib::LoopOutputHandler<SuperstructureQueue::Output>( |
| 349 | event_loop, ".y2017.control_loops.superstructure_queue.output") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 350 | |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 351 | void set_intake_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 352 | intake_victor_ = ::std::move(t); |
| 353 | } |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 354 | void set_intake_rollers_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 355 | intake_rollers_victor_ = ::std::move(t); |
| 356 | } |
| 357 | |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 358 | void set_indexer_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 359 | indexer_victor_ = ::std::move(t); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 360 | } |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 361 | void set_indexer_roller_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 362 | indexer_roller_victor_ = ::std::move(t); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 365 | void set_gear_servo(::std::unique_ptr<::frc::Servo> t) { |
| 366 | gear_servo_ = ::std::move(t); |
| 367 | } |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 368 | void set_shooter_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 369 | shooter_victor_ = ::std::move(t); |
| 370 | } |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 371 | void set_turret_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 372 | turret_victor_ = ::std::move(t); |
| 373 | } |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 374 | void set_hood_victor(::std::unique_ptr<::frc::VictorSP> t) { |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 375 | hood_victor_ = ::std::move(t); |
| 376 | } |
| 377 | |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 378 | void set_red_light(::std::unique_ptr<DigitalOutput> t) { |
| 379 | red_light_ = ::std::move(t); |
| 380 | } |
| 381 | void set_green_light(::std::unique_ptr<DigitalOutput> t) { |
| 382 | green_light_ = ::std::move(t); |
| 383 | } |
| 384 | void set_blue_light(::std::unique_ptr<DigitalOutput> t) { |
| 385 | blue_light_ = ::std::move(t); |
| 386 | } |
| 387 | |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 388 | private: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 389 | virtual void Write(const SuperstructureQueue::Output &output) override { |
| 390 | LOG_STRUCT(DEBUG, "will output", output); |
| 391 | intake_victor_->SetSpeed(::aos::Clip(output.voltage_intake, |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 392 | -kMaxBringupPower, kMaxBringupPower) / |
| 393 | 12.0); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 394 | intake_rollers_victor_->SetSpeed(output.voltage_intake_rollers / 12.0); |
| 395 | indexer_victor_->SetSpeed(-output.voltage_indexer / 12.0); |
| 396 | indexer_roller_victor_->SetSpeed(output.voltage_indexer_rollers / 12.0); |
| 397 | turret_victor_->SetSpeed(::aos::Clip(-output.voltage_turret, |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 398 | -kMaxBringupPower, kMaxBringupPower) / |
| 399 | 12.0); |
| 400 | hood_victor_->SetSpeed( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 401 | ::aos::Clip(output.voltage_hood, -kMaxBringupPower, kMaxBringupPower) / |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 402 | 12.0); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 403 | shooter_victor_->SetSpeed(output.voltage_shooter / 12.0); |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 404 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 405 | red_light_->Set(output.red_light_on); |
| 406 | green_light_->Set(output.green_light_on); |
| 407 | blue_light_->Set(output.blue_light_on); |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 408 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 409 | gear_servo_->SetPosition(output.gear_servo); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | virtual void Stop() override { |
| 413 | LOG(WARNING, "Superstructure output too old.\n"); |
| 414 | intake_victor_->SetDisabled(); |
| 415 | intake_rollers_victor_->SetDisabled(); |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 416 | indexer_victor_->SetDisabled(); |
| 417 | indexer_roller_victor_->SetDisabled(); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 418 | turret_victor_->SetDisabled(); |
| 419 | hood_victor_->SetDisabled(); |
| 420 | shooter_victor_->SetDisabled(); |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 421 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 422 | gear_servo_->SetRaw(0); |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 423 | |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 424 | red_light_->Set(true); |
| 425 | green_light_->Set(true); |
| 426 | blue_light_->Set(true); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 429 | ::std::unique_ptr<::frc::VictorSP> intake_victor_, intake_rollers_victor_, |
| 430 | indexer_victor_, indexer_roller_victor_, shooter_victor_, turret_victor_, |
| 431 | hood_victor_; |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 432 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 433 | ::std::unique_ptr<::frc::Servo> gear_servo_; |
| 434 | |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 435 | ::std::unique_ptr<DigitalOutput> red_light_, green_light_, blue_light_; |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 439 | public: |
| 440 | ::std::unique_ptr<Encoder> make_encoder(int index) { |
| 441 | return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false, |
| 442 | Encoder::k4X); |
| 443 | } |
| 444 | |
| 445 | void Run() override { |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 446 | // Thread 1. |
| 447 | ::aos::ShmEventLoop joystick_sender_event_loop; |
| 448 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 449 | &joystick_sender_event_loop); |
| 450 | AddLoop(&joystick_sender_event_loop); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 451 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 452 | // Thread 2. |
| 453 | ::aos::ShmEventLoop pdp_fetcher_event_loop; |
| 454 | ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop); |
| 455 | AddLoop(&pdp_fetcher_event_loop); |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 456 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 457 | // Thread 3. |
| 458 | ::aos::ShmEventLoop sensor_reader_event_loop; |
| 459 | SensorReader sensor_reader(&sensor_reader_event_loop); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 460 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 461 | sensor_reader.set_drivetrain_left_encoder(make_encoder(0)); |
| 462 | sensor_reader.set_drivetrain_right_encoder(make_encoder(1)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 463 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 464 | sensor_reader.set_intake_encoder(make_encoder(3)); |
| 465 | sensor_reader.set_intake_absolute(make_unique<DigitalInput>(0)); |
| 466 | sensor_reader.set_intake_potentiometer(make_unique<AnalogInput>(4)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 467 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 468 | sensor_reader.set_indexer_encoder(make_encoder(5)); |
| 469 | sensor_reader.set_indexer_hall(make_unique<DigitalInput>(4)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 470 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 471 | sensor_reader.set_turret_encoder(make_encoder(6)); |
| 472 | sensor_reader.set_turret_hall(make_unique<DigitalInput>(2)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 473 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 474 | sensor_reader.set_hood_encoder(make_encoder(4)); |
| 475 | sensor_reader.set_hood_index(make_unique<DigitalInput>(1)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 476 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 477 | sensor_reader.set_shooter_encoder(make_encoder(2)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 478 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 479 | sensor_reader.set_autonomous_mode(0, make_unique<DigitalInput>(9)); |
| 480 | sensor_reader.set_autonomous_mode(1, make_unique<DigitalInput>(8)); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 481 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 482 | sensor_reader.set_pwm_trigger(true); |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 483 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 484 | AddLoop(&sensor_reader_event_loop); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 485 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 486 | // Thread 5. |
| 487 | ::aos::ShmEventLoop imu_event_loop; |
Brian Silverman | b443985 | 2017-02-24 19:49:09 -0800 | [diff] [blame] | 488 | auto imu_trigger = make_unique<DigitalInput>(3); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 489 | ::frc971::wpilib::ADIS16448 imu(&imu_event_loop, SPI::Port::kOnboardCS1, |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 490 | imu_trigger.get()); |
Brian Silverman | a70994f | 2017-03-16 22:32:55 -0700 | [diff] [blame] | 491 | imu.SetDummySPI(SPI::Port::kOnboardCS2); |
| 492 | auto imu_reset = make_unique<DigitalOutput>(6); |
| 493 | imu.set_reset(imu_reset.get()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 494 | AddLoop(&imu_event_loop); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 495 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 496 | ::aos::ShmEventLoop output_event_loop; |
| 497 | ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop); |
Sabina Davis | 7af11ad | 2019-02-03 01:16:45 -0800 | [diff] [blame] | 498 | drivetrain_writer.set_left_controller0( |
| 499 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(7)), true); |
| 500 | drivetrain_writer.set_right_controller0( |
| 501 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(3)), false); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 502 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 503 | SuperstructureWriter superstructure_writer(&output_event_loop); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 504 | superstructure_writer.set_intake_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 505 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(1))); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 506 | superstructure_writer.set_intake_rollers_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 507 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(4))); |
Austin Schuh | 0fc1e6d | 2017-02-21 02:04:10 -0800 | [diff] [blame] | 508 | superstructure_writer.set_indexer_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 509 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(6))); |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 510 | superstructure_writer.set_indexer_roller_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 511 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(5))); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 512 | superstructure_writer.set_turret_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 513 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(9))); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 514 | superstructure_writer.set_hood_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 515 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(2))); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 516 | superstructure_writer.set_shooter_victor( |
Austin Schuh | 8347cb6 | 2017-04-08 14:37:34 -0700 | [diff] [blame] | 517 | ::std::unique_ptr<::frc::VictorSP>(new ::frc::VictorSP(8))); |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 518 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 519 | superstructure_writer.set_gear_servo( |
| 520 | ::std::unique_ptr<Servo>(new Servo(0))); |
| 521 | |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 522 | superstructure_writer.set_red_light( |
| 523 | ::std::unique_ptr<DigitalOutput>(new DigitalOutput(5))); |
| 524 | superstructure_writer.set_green_light( |
| 525 | ::std::unique_ptr<DigitalOutput>(new DigitalOutput(24))); |
| 526 | superstructure_writer.set_blue_light( |
| 527 | ::std::unique_ptr<DigitalOutput>(new DigitalOutput(25))); |
| 528 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 529 | AddLoop(&output_event_loop); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 530 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 531 | // Thread 6. |
| 532 | ::aos::ShmEventLoop solenoid_writer_event_loop; |
| 533 | SolenoidWriter solenoid_writer(&solenoid_writer_event_loop); |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 534 | solenoid_writer.set_lights(solenoid_writer.pcm()->MakeSolenoid(0)); |
Austin Schuh | c587c88 | 2017-03-29 21:33:10 -0700 | [diff] [blame] | 535 | solenoid_writer.set_rgb_light(solenoid_writer.pcm()->MakeSolenoid(1)); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 536 | AddLoop(&solenoid_writer_event_loop); |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 537 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 538 | RunLoops(); |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 539 | } |
| 540 | }; |
| 541 | |
Brian Silverman | 052e69d | 2017-02-12 16:19:55 -0800 | [diff] [blame] | 542 | } // namespace |
Campbell Crowley | ae6e842 | 2017-02-05 12:38:50 -0800 | [diff] [blame] | 543 | } // namespace wpilib |
| 544 | } // namespace y2017 |
| 545 | |
| 546 | AOS_ROBOT_CLASS(::y2017::wpilib::WPILibRobot); |