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