Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <unistd.h> |
| 4 | #include <inttypes.h> |
| 5 | |
| 6 | #include <thread> |
| 7 | #include <mutex> |
| 8 | #include <functional> |
| 9 | |
| 10 | #include "Encoder.h" |
| 11 | #include "Talon.h" |
| 12 | #include "DriverStation.h" |
| 13 | #include "AnalogInput.h" |
| 14 | #include "Compressor.h" |
| 15 | #include "Relay.h" |
| 16 | #include "frc971/wpilib/wpilib_robot_base.h" |
| 17 | #include "dma.h" |
| 18 | #ifndef WPILIB2015 |
| 19 | #include "DigitalGlitchFilter.h" |
| 20 | #endif |
| 21 | #undef ERROR |
| 22 | |
| 23 | #include "aos/common/logging/logging.h" |
| 24 | #include "aos/common/logging/queue_logging.h" |
| 25 | #include "aos/common/time.h" |
| 26 | #include "aos/common/util/log_interval.h" |
| 27 | #include "aos/common/util/phased_loop.h" |
| 28 | #include "aos/common/util/wrapping_counter.h" |
| 29 | #include "aos/common/stl_mutex.h" |
| 30 | #include "aos/linux_code/init.h" |
| 31 | #include "aos/common/messages/robot_state.q.h" |
| 32 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 33 | #include "frc971/control_loops/control_loops.q.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 34 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 35 | #include "y2016/control_loops/shooter/shooter.q.h" |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 36 | #include "y2016/constants.h" |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 37 | #include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 38 | #include "y2016/control_loops/shooter/shooter.q.h" |
| 39 | #include "y2016/control_loops/superstructure/superstructure.q.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 40 | |
| 41 | #include "frc971/wpilib/joystick_sender.h" |
| 42 | #include "frc971/wpilib/loop_output_handler.h" |
| 43 | #include "frc971/wpilib/buffered_solenoid.h" |
| 44 | #include "frc971/wpilib/buffered_pcm.h" |
| 45 | #include "frc971/wpilib/gyro_sender.h" |
| 46 | #include "frc971/wpilib/dma_edge_counting.h" |
| 47 | #include "frc971/wpilib/interrupt_edge_counting.h" |
| 48 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
| 49 | #include "frc971/wpilib/logging.q.h" |
| 50 | #include "frc971/wpilib/wpilib_interface.h" |
| 51 | #include "frc971/wpilib/pdp_fetcher.h" |
| 52 | |
| 53 | #ifndef M_PI |
| 54 | #define M_PI 3.14159265358979323846 |
| 55 | #endif |
| 56 | |
| 57 | using ::frc971::control_loops::drivetrain_queue; |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 58 | using ::y2016::control_loops::shooter::shooter_queue; |
| 59 | using ::y2016::control_loops::superstructure_queue; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 60 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 61 | namespace y2016 { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 62 | namespace wpilib { |
| 63 | |
| 64 | // TODO(Brian): Fix the interpretation of the result of GetRaw here and in the |
| 65 | // DMA stuff and then removing the * 2.0 in *_translate. |
| 66 | // The low bit is direction. |
| 67 | |
| 68 | // TODO(brian): Replace this with ::std::make_unique once all our toolchains |
| 69 | // have support. |
| 70 | template <class T, class... U> |
| 71 | std::unique_ptr<T> make_unique(U &&... u) { |
| 72 | return std::unique_ptr<T>(new T(std::forward<U>(u)...)); |
| 73 | } |
| 74 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 75 | // Translates for the sensor values to convert raw index pulses into something |
| 76 | // with proper units. |
| 77 | |
| 78 | // TODO(comran): Template these methods since there is a lot of repetition here. |
| 79 | double hall_translate(double in) { |
| 80 | // Turn voltage from our 3-state halls into a ratio that the loop can use. |
| 81 | return in / 5.0; |
| 82 | } |
| 83 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 84 | double drivetrain_translate(int32_t in) { |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 85 | return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 86 | constants::Values::kDrivetrainEncoderRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 87 | control_loops::drivetrain::kWheelRadius * 2.0 / 2.0; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | double drivetrain_velocity_translate(double in) { |
| 91 | return (1.0 / in) / 256.0 /*cpr*/ * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 92 | constants::Values::kDrivetrainEncoderRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 93 | control_loops::drivetrain::kWheelRadius * 2.0 / 2.0; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 96 | double shooter_translate(int32_t in) { |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 97 | return -static_cast<double>(in) / (128.0 /*cpr*/ * 4.0 /*4x*/) * |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 98 | constants::Values::kShooterEncoderRatio * (2 * M_PI /*radians*/); |
| 99 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 100 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 101 | double intake_translate(int32_t in) { |
| 102 | return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) * |
| 103 | constants::Values::kIntakeEncoderRatio * (2 * M_PI /*radians*/); |
| 104 | } |
| 105 | |
| 106 | double shoulder_translate(int32_t in) { |
| 107 | return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) * |
| 108 | constants::Values::kShoulderEncoderRatio * (2 * M_PI /*radians*/); |
| 109 | } |
| 110 | |
| 111 | double wrist_translate(int32_t in) { |
| 112 | return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) * |
| 113 | constants::Values::kWristEncoderRatio * (2 * M_PI /*radians*/); |
| 114 | } |
| 115 | |
| 116 | double intake_pot_translate(double voltage) { |
| 117 | return voltage * constants::Values::kIntakePotRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 118 | (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | double shoulder_pot_translate(double voltage) { |
| 122 | return voltage * constants::Values::kShoulderPotRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 123 | (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | double wrist_pot_translate(double voltage) { |
| 127 | return voltage * constants::Values::kWristPotRatio * |
Comran Morshed | 5bb1211 | 2016-02-16 13:48:57 +0000 | [diff] [blame^] | 128 | (3.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 131 | constexpr double kMaxDrivetrainEncoderPulsesPerSecond = |
| 132 | 5600.0 /* CIM free speed RPM */ * 14.0 / 48.0 /* 1st reduction */ * 28.0 / |
| 133 | 50.0 /* 2nd reduction (high gear) */ * 30.0 / 44.0 /* encoder gears */ / |
| 134 | 60.0 /* seconds per minute */ * 256.0 /* CPR */ * 4 /* edges per cycle */; |
| 135 | |
| 136 | constexpr double kMaxShooterEncoderPulsesPerSecond = |
| 137 | 18700.0 /* 775pro free speed RPM */ * 12.0 / |
| 138 | 18.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ * |
| 139 | 128.0 /* CPR */ * 4 /* edges per cycle */; |
| 140 | |
| 141 | double kMaxDrivetrainShooterEncoderPulsesPerSecond = ::std::max( |
| 142 | kMaxDrivetrainEncoderPulsesPerSecond, kMaxShooterEncoderPulsesPerSecond); |
| 143 | |
| 144 | constexpr double kMaxSuperstructureEncoderPulsesPerSecond = |
| 145 | 18700.0 /* 775pro free speed RPM */ * 12.0 / |
| 146 | 56.0 /* motor to encoder reduction */ / 60.0 /* seconds per minute */ * |
| 147 | 512.0 /* CPR */ * 4 /* index pulse every quarter cycle */; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 148 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 149 | // Class to send position messages with sensor readings to our loops. |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 150 | class SensorReader { |
| 151 | public: |
| 152 | SensorReader() { |
| 153 | // Set it to filter out anything shorter than 1/4 of the minimum pulse width |
| 154 | // we should ever see. |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 155 | drivetrain_shooter_encoder_filter_.SetPeriodNanoSeconds( |
| 156 | static_cast<int>(1 / 4.0 /* built-in tolerance */ / |
| 157 | kMaxDrivetrainShooterEncoderPulsesPerSecond * 1e9 + |
| 158 | 0.5)); |
| 159 | superstructure_encoder_filter_.SetPeriodNanoSeconds( |
| 160 | static_cast<int>(1 / 4.0 /* built-in tolerance */ / |
| 161 | kMaxSuperstructureEncoderPulsesPerSecond * 1e9 + |
| 162 | 0.5)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 163 | hall_filter_.SetPeriodNanoSeconds(100000); |
| 164 | } |
| 165 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 166 | // Drivetrain setters. |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 167 | void set_drivetrain_left_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 168 | drivetrain_shooter_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 169 | drivetrain_left_encoder_ = ::std::move(encoder); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void set_drivetrain_right_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 173 | drivetrain_shooter_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 174 | drivetrain_right_encoder_ = ::std::move(encoder); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 177 | void set_drivetrain_left_hall(::std::unique_ptr<AnalogInput> analog) { |
| 178 | drivetrain_left_hall_ = ::std::move(analog); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 181 | void set_drivetrain_right_hall(::std::unique_ptr<AnalogInput> analog) { |
| 182 | drivetrain_right_hall_ = ::std::move(analog); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 185 | // Shooter setters. |
| 186 | void set_shooter_left_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 187 | drivetrain_shooter_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 188 | shooter_left_encoder_ = ::std::move(encoder); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 191 | void set_shooter_right_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 192 | drivetrain_shooter_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 193 | shooter_right_encoder_ = ::std::move(encoder); |
| 194 | } |
| 195 | |
| 196 | // Intake setters. |
| 197 | void set_intake_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 198 | superstructure_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 199 | intake_encoder_.set_encoder(::std::move(encoder)); |
| 200 | } |
| 201 | |
| 202 | void set_intake_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) { |
| 203 | intake_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 204 | } |
| 205 | |
| 206 | void set_intake_index(::std::unique_ptr<DigitalInput> index) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 207 | superstructure_encoder_filter_.Add(index.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 208 | intake_encoder_.set_index(::std::move(index)); |
| 209 | } |
| 210 | |
| 211 | // Shoulder setters. |
| 212 | void set_shoulder_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 213 | superstructure_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 214 | shoulder_encoder_.set_encoder(::std::move(encoder)); |
| 215 | } |
| 216 | |
| 217 | void set_shoulder_potentiometer( |
| 218 | ::std::unique_ptr<AnalogInput> potentiometer) { |
| 219 | shoulder_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 220 | } |
| 221 | |
| 222 | void set_shoulder_index(::std::unique_ptr<DigitalInput> index) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 223 | superstructure_encoder_filter_.Add(index.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 224 | shoulder_encoder_.set_index(::std::move(index)); |
| 225 | } |
| 226 | |
| 227 | // Wrist setters. |
| 228 | void set_wrist_encoder(::std::unique_ptr<Encoder> encoder) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 229 | superstructure_encoder_filter_.Add(encoder.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 230 | wrist_encoder_.set_encoder(::std::move(encoder)); |
| 231 | } |
| 232 | |
| 233 | void set_wrist_potentiometer(::std::unique_ptr<AnalogInput> potentiometer) { |
| 234 | wrist_encoder_.set_potentiometer(::std::move(potentiometer)); |
| 235 | } |
| 236 | |
| 237 | void set_wrist_index(::std::unique_ptr<DigitalInput> index) { |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 238 | superstructure_encoder_filter_.Add(index.get()); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 239 | wrist_encoder_.set_index(::std::move(index)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 242 | // All of the DMA-related set_* calls must be made before this, and it doesn't |
| 243 | // hurt to do all of them. |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 244 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 245 | // TODO(comran): Add 2016 things down below for dma synchronization. |
| 246 | void set_dma(::std::unique_ptr<DMA> dma) { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 247 | dma_synchronizer_.reset( |
| 248 | new ::frc971::wpilib::DMASynchronizer(::std::move(dma))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 249 | dma_synchronizer_->Add(&intake_encoder_); |
| 250 | dma_synchronizer_->Add(&shoulder_encoder_); |
| 251 | dma_synchronizer_->Add(&wrist_encoder_); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void operator()() { |
| 255 | ::aos::SetCurrentThreadName("SensorReader"); |
| 256 | |
| 257 | my_pid_ = getpid(); |
| 258 | ds_ = |
| 259 | #ifdef WPILIB2015 |
| 260 | DriverStation::GetInstance(); |
| 261 | #else |
| 262 | &DriverStation::GetInstance(); |
| 263 | #endif |
| 264 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 265 | dma_synchronizer_->Start(); |
| 266 | |
| 267 | ::aos::time::PhasedLoop phased_loop(::aos::time::Time::InMS(5), |
| 268 | ::aos::time::Time::InMS(4)); |
| 269 | |
| 270 | ::aos::SetCurrentThreadRealtimePriority(40); |
| 271 | while (run_) { |
| 272 | { |
| 273 | const int iterations = phased_loop.SleepUntilNext(); |
| 274 | if (iterations != 1) { |
| 275 | LOG(WARNING, "SensorReader skipped %d iterations\n", iterations - 1); |
| 276 | } |
| 277 | } |
| 278 | RunIteration(); |
| 279 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void RunIteration() { |
| 283 | ::frc971::wpilib::SendRobotState(my_pid_, ds_); |
| 284 | |
| 285 | const auto &values = constants::GetValues(); |
| 286 | |
| 287 | { |
| 288 | auto drivetrain_message = drivetrain_queue.position.MakeMessage(); |
| 289 | drivetrain_message->right_encoder = |
| 290 | drivetrain_translate(drivetrain_right_encoder_->GetRaw()); |
| 291 | drivetrain_message->left_encoder = |
| 292 | -drivetrain_translate(drivetrain_left_encoder_->GetRaw()); |
| 293 | drivetrain_message->left_speed = |
| 294 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod()); |
| 295 | drivetrain_message->right_speed = |
| 296 | drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod()); |
| 297 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 298 | drivetrain_message->left_shifter_position = |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 299 | hall_translate(drivetrain_left_hall_->GetVoltage()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 300 | drivetrain_message->right_shifter_position = |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 301 | hall_translate(drivetrain_right_hall_->GetVoltage()); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 302 | |
| 303 | drivetrain_message.Send(); |
| 304 | } |
| 305 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 306 | dma_synchronizer_->RunIteration(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 307 | |
| 308 | { |
| 309 | auto shooter_message = shooter_queue.position.MakeMessage(); |
| 310 | shooter_message->theta_left = |
| 311 | shooter_translate(shooter_left_encoder_->GetRaw()); |
| 312 | shooter_message->theta_right = |
| 313 | shooter_translate(shooter_right_encoder_->GetRaw()); |
| 314 | shooter_message.Send(); |
| 315 | } |
| 316 | |
| 317 | { |
| 318 | auto superstructure_message = superstructure_queue.position.MakeMessage(); |
| 319 | CopyPotAndIndexPosition(intake_encoder_, &superstructure_message->intake, |
| 320 | intake_translate, intake_pot_translate, false, |
| 321 | values.intake.pot_offset); |
| 322 | CopyPotAndIndexPosition(shoulder_encoder_, |
| 323 | &superstructure_message->shoulder, |
| 324 | shoulder_translate, shoulder_pot_translate, false, |
| 325 | values.shoulder.pot_offset); |
| 326 | CopyPotAndIndexPosition(wrist_encoder_, &superstructure_message->wrist, |
| 327 | wrist_translate, wrist_pot_translate, false, |
| 328 | values.wrist.pot_offset); |
| 329 | |
| 330 | superstructure_message.Send(); |
| 331 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void Quit() { run_ = false; } |
| 335 | |
| 336 | private: |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 337 | void CopyPotAndIndexPosition( |
| 338 | const ::frc971::wpilib::DMAEncoderAndPotentiometer &encoder, |
| 339 | ::frc971::PotAndIndexPosition *position, |
| 340 | ::std::function<double(int32_t)> encoder_translate, |
| 341 | ::std::function<double(double)> potentiometer_translate, bool reverse, |
| 342 | double pot_offset) { |
| 343 | const double multiplier = reverse ? -1.0 : 1.0; |
| 344 | position->encoder = |
| 345 | multiplier * encoder_translate(encoder.polled_encoder_value()); |
| 346 | position->pot = multiplier * potentiometer_translate( |
| 347 | encoder.polled_potentiometer_voltage()) + |
| 348 | pot_offset; |
| 349 | position->latched_encoder = |
| 350 | multiplier * encoder_translate(encoder.last_encoder_value()); |
| 351 | position->latched_pot = |
| 352 | multiplier * |
| 353 | potentiometer_translate(encoder.last_potentiometer_voltage()) + |
| 354 | pot_offset; |
| 355 | position->index_pulses = encoder.index_posedge_count(); |
| 356 | } |
| 357 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 358 | int32_t my_pid_; |
| 359 | DriverStation *ds_; |
| 360 | |
| 361 | ::std::unique_ptr<::frc971::wpilib::DMASynchronizer> dma_synchronizer_; |
| 362 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 363 | ::std::unique_ptr<Encoder> drivetrain_left_encoder_, |
| 364 | drivetrain_right_encoder_; |
| 365 | ::std::unique_ptr<AnalogInput> drivetrain_left_hall_, drivetrain_right_hall_; |
| 366 | |
| 367 | ::std::unique_ptr<Encoder> shooter_left_encoder_, shooter_right_encoder_; |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 368 | ::frc971::wpilib::DMAEncoderAndPotentiometer intake_encoder_, |
| 369 | shoulder_encoder_, wrist_encoder_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 370 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 371 | ::std::atomic<bool> run_{true}; |
Comran Morshed | 1b76432 | 2016-02-14 20:18:12 +0000 | [diff] [blame] | 372 | DigitalGlitchFilter drivetrain_shooter_encoder_filter_, hall_filter_, |
| 373 | superstructure_encoder_filter_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 374 | }; |
| 375 | |
| 376 | class SolenoidWriter { |
| 377 | public: |
| 378 | SolenoidWriter(const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm) |
| 379 | : pcm_(pcm), |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 380 | drivetrain_(".frc971.control_loops.drivetrain_queue.output"), |
| 381 | shooter_(".y2016.control_loops.shooter_queue.output") {} |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 382 | |
| 383 | void set_pressure_switch(::std::unique_ptr<DigitalInput> pressure_switch) { |
| 384 | pressure_switch_ = ::std::move(pressure_switch); |
| 385 | } |
| 386 | |
| 387 | void set_compressor_relay(::std::unique_ptr<Relay> compressor_relay) { |
| 388 | compressor_relay_ = ::std::move(compressor_relay); |
| 389 | } |
| 390 | |
| 391 | void set_drivetrain_left( |
| 392 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 393 | drivetrain_left_ = ::std::move(s); |
| 394 | } |
| 395 | |
| 396 | void set_drivetrain_right( |
| 397 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 398 | drivetrain_right_ = ::std::move(s); |
| 399 | } |
| 400 | |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 401 | void set_shooter_clamp( |
| 402 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 403 | shooter_clamp_ = ::std::move(s); |
| 404 | } |
| 405 | |
| 406 | void set_shooter_pusher( |
| 407 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 408 | shooter_pusher_ = ::std::move(s); |
| 409 | } |
| 410 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 411 | void operator()() { |
| 412 | ::aos::SetCurrentThreadName("Solenoids"); |
| 413 | ::aos::SetCurrentThreadRealtimePriority(27); |
| 414 | |
| 415 | ::aos::time::PhasedLoop phased_loop(::aos::time::Time::InMS(20), |
| 416 | ::aos::time::Time::InMS(1)); |
| 417 | |
| 418 | while (run_) { |
| 419 | { |
| 420 | const int iterations = phased_loop.SleepUntilNext(); |
| 421 | if (iterations != 1) { |
| 422 | LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 427 | drivetrain_.FetchLatest(); |
| 428 | if (drivetrain_.get()) { |
| 429 | LOG_STRUCT(DEBUG, "solenoids", *drivetrain_); |
| 430 | drivetrain_left_->Set(!drivetrain_->left_high); |
| 431 | drivetrain_right_->Set(!drivetrain_->right_high); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | { |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 436 | shooter_.FetchLatest(); |
| 437 | if (shooter_.get()) { |
| 438 | LOG_STRUCT(DEBUG, "solenoids", *shooter_); |
| 439 | shooter_clamp_->Set(shooter_->clamp_open); |
| 440 | shooter_pusher_->Set(shooter_->push_to_shooter); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 445 | ::frc971::wpilib::PneumaticsToLog to_log; |
| 446 | { |
| 447 | const bool compressor_on = !pressure_switch_->Get(); |
| 448 | to_log.compressor_on = compressor_on; |
| 449 | if (compressor_on) { |
| 450 | compressor_relay_->Set(Relay::kForward); |
| 451 | } else { |
| 452 | compressor_relay_->Set(Relay::kOff); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | pcm_->Flush(); |
| 457 | to_log.read_solenoids = pcm_->GetAll(); |
| 458 | LOG_STRUCT(DEBUG, "pneumatics info", to_log); |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void Quit() { run_ = false; } |
| 464 | |
| 465 | private: |
| 466 | const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_; |
| 467 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 468 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_left_, |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 469 | drivetrain_right_, shooter_clamp_, shooter_pusher_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 470 | ::std::unique_ptr<DigitalInput> pressure_switch_; |
| 471 | ::std::unique_ptr<Relay> compressor_relay_; |
| 472 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 473 | ::aos::Queue<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_; |
Comran Morshed | 3263e8f | 2016-02-14 17:55:45 +0000 | [diff] [blame] | 474 | ::aos::Queue<::y2016::control_loops::shooter::ShooterQueue::Output> shooter_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 475 | |
| 476 | ::std::atomic<bool> run_{true}; |
| 477 | }; |
| 478 | |
| 479 | class DrivetrainWriter : public ::frc971::wpilib::LoopOutputHandler { |
| 480 | public: |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 481 | void set_drivetrain_left_talon(::std::unique_ptr<Talon> t) { |
| 482 | drivetrain_left_talon_ = ::std::move(t); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 485 | void set_drivetrain_right_talon(::std::unique_ptr<Talon> t) { |
| 486 | drivetrain_right_talon_ = ::std::move(t); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | private: |
| 490 | virtual void Read() override { |
| 491 | ::frc971::control_loops::drivetrain_queue.output.FetchAnother(); |
| 492 | } |
| 493 | |
| 494 | virtual void Write() override { |
| 495 | auto &queue = ::frc971::control_loops::drivetrain_queue.output; |
| 496 | LOG_STRUCT(DEBUG, "will output", *queue); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 497 | drivetrain_left_talon_->Set(-queue->left_voltage / 12.0); |
| 498 | drivetrain_right_talon_->Set(queue->right_voltage / 12.0); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | virtual void Stop() override { |
| 502 | LOG(WARNING, "drivetrain output too old\n"); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 503 | drivetrain_left_talon_->Disable(); |
| 504 | drivetrain_right_talon_->Disable(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 507 | ::std::unique_ptr<Talon> drivetrain_left_talon_, drivetrain_right_talon_; |
| 508 | }; |
| 509 | |
| 510 | class ShooterWriter : public ::frc971::wpilib::LoopOutputHandler { |
| 511 | public: |
| 512 | void set_shooter_left_talon(::std::unique_ptr<Talon> t) { |
| 513 | shooter_left_talon_ = ::std::move(t); |
| 514 | } |
| 515 | |
| 516 | void set_shooter_right_talon(::std::unique_ptr<Talon> t) { |
| 517 | shooter_right_talon_ = ::std::move(t); |
| 518 | } |
| 519 | |
| 520 | private: |
| 521 | virtual void Read() override { |
| 522 | ::y2016::control_loops::shooter::shooter_queue.output.FetchAnother(); |
| 523 | } |
| 524 | |
| 525 | virtual void Write() override { |
| 526 | auto &queue = ::y2016::control_loops::shooter::shooter_queue.output; |
| 527 | LOG_STRUCT(DEBUG, "will output", *queue); |
| 528 | shooter_left_talon_->Set(queue->voltage_left / 12.0); |
| 529 | shooter_right_talon_->Set(queue->voltage_right / 12.0); |
| 530 | } |
| 531 | |
| 532 | virtual void Stop() override { |
| 533 | LOG(WARNING, "Shooter output too old.\n"); |
| 534 | shooter_left_talon_->Disable(); |
| 535 | shooter_right_talon_->Disable(); |
| 536 | } |
| 537 | |
| 538 | ::std::unique_ptr<Talon> shooter_left_talon_, shooter_right_talon_; |
| 539 | }; |
| 540 | |
| 541 | class SuperstructureWriter : public ::frc971::wpilib::LoopOutputHandler { |
| 542 | public: |
| 543 | void set_intake_talon(::std::unique_ptr<Talon> t) { |
| 544 | intake_talon_ = ::std::move(t); |
| 545 | } |
| 546 | |
| 547 | void set_shoulder_talon(::std::unique_ptr<Talon> t) { |
| 548 | shoulder_talon_ = ::std::move(t); |
| 549 | } |
| 550 | |
| 551 | void set_wrist_talon(::std::unique_ptr<Talon> t) { |
| 552 | wrist_talon_ = ::std::move(t); |
| 553 | } |
| 554 | |
Comran Morshed | f4cd764 | 2016-02-15 20:40:49 +0000 | [diff] [blame] | 555 | void set_rollers_talon(::std::unique_ptr<Talon> t) { |
| 556 | rollers_talon_ = ::std::move(t); |
| 557 | } |
| 558 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 559 | private: |
| 560 | virtual void Read() override { |
| 561 | ::y2016::control_loops::superstructure_queue.output.FetchAnother(); |
| 562 | } |
| 563 | |
| 564 | virtual void Write() override { |
| 565 | auto &queue = ::y2016::control_loops::superstructure_queue.output; |
| 566 | LOG_STRUCT(DEBUG, "will output", *queue); |
| 567 | intake_talon_->Set(queue->voltage_intake / 12.0); |
| 568 | shoulder_talon_->Set(-queue->voltage_shoulder / 12.0); |
| 569 | wrist_talon_->Set(queue->voltage_wrist / 12.0); |
Comran Morshed | f4cd764 | 2016-02-15 20:40:49 +0000 | [diff] [blame] | 570 | rollers_talon_->Set(queue->voltage_rollers / 12.0); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | virtual void Stop() override { |
| 574 | LOG(WARNING, "Superstructure output too old.\n"); |
| 575 | intake_talon_->Disable(); |
| 576 | shoulder_talon_->Disable(); |
| 577 | wrist_talon_->Disable(); |
| 578 | } |
| 579 | |
Comran Morshed | f4cd764 | 2016-02-15 20:40:49 +0000 | [diff] [blame] | 580 | ::std::unique_ptr<Talon> intake_talon_, shoulder_talon_, wrist_talon_, |
| 581 | rollers_talon_; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 582 | }; |
| 583 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 584 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
| 585 | public: |
| 586 | ::std::unique_ptr<Encoder> make_encoder(int index) { |
| 587 | return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false, |
| 588 | Encoder::k4X); |
| 589 | } |
| 590 | |
| 591 | void Run() override { |
| 592 | ::aos::InitNRT(); |
| 593 | ::aos::SetCurrentThreadName("StartCompetition"); |
| 594 | |
| 595 | ::frc971::wpilib::JoystickSender joystick_sender; |
| 596 | ::std::thread joystick_thread(::std::ref(joystick_sender)); |
| 597 | |
| 598 | ::frc971::wpilib::PDPFetcher pdp_fetcher; |
| 599 | ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher)); |
| 600 | SensorReader reader; |
| 601 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 602 | // TODO(constants): Update these input numbers. |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 603 | reader.set_drivetrain_left_encoder(make_encoder(0)); |
| 604 | reader.set_drivetrain_right_encoder(make_encoder(1)); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 605 | reader.set_drivetrain_left_hall(make_unique<AnalogInput>(1)); |
| 606 | reader.set_drivetrain_right_hall(make_unique<AnalogInput>(2)); |
| 607 | |
| 608 | reader.set_shooter_left_encoder(make_encoder(0)); |
| 609 | reader.set_shooter_right_encoder(make_encoder(0)); |
| 610 | |
| 611 | reader.set_intake_encoder(make_encoder(0)); |
| 612 | reader.set_intake_index(make_unique<DigitalInput>(0)); |
| 613 | reader.set_intake_potentiometer(make_unique<AnalogInput>(0)); |
| 614 | |
| 615 | reader.set_shoulder_encoder(make_encoder(0)); |
| 616 | reader.set_shoulder_index(make_unique<DigitalInput>(0)); |
| 617 | reader.set_shoulder_potentiometer(make_unique<AnalogInput>(0)); |
| 618 | |
| 619 | reader.set_wrist_encoder(make_encoder(0)); |
| 620 | reader.set_wrist_index(make_unique<DigitalInput>(0)); |
| 621 | reader.set_wrist_potentiometer(make_unique<AnalogInput>(0)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 622 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 623 | reader.set_dma(make_unique<DMA>()); |
| 624 | ::std::thread reader_thread(::std::ref(reader)); |
| 625 | |
| 626 | ::frc971::wpilib::GyroSender gyro_sender; |
| 627 | ::std::thread gyro_thread(::std::ref(gyro_sender)); |
| 628 | |
| 629 | DrivetrainWriter drivetrain_writer; |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 630 | drivetrain_writer.set_drivetrain_left_talon( |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 631 | ::std::unique_ptr<Talon>(new Talon(5))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 632 | drivetrain_writer.set_drivetrain_right_talon( |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 633 | ::std::unique_ptr<Talon>(new Talon(2))); |
| 634 | ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer)); |
| 635 | |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 636 | ShooterWriter shooter_writer; |
| 637 | shooter_writer.set_shooter_left_talon( |
| 638 | ::std::unique_ptr<Talon>(new Talon(0))); |
| 639 | shooter_writer.set_shooter_right_talon( |
| 640 | ::std::unique_ptr<Talon>(new Talon(0))); |
| 641 | ::std::thread shooter_writer_thread(::std::ref(shooter_writer)); |
| 642 | |
| 643 | SuperstructureWriter superstructure_writer; |
| 644 | superstructure_writer.set_intake_talon( |
| 645 | ::std::unique_ptr<Talon>(new Talon(0))); |
| 646 | superstructure_writer.set_shoulder_talon( |
| 647 | ::std::unique_ptr<Talon>(new Talon(0))); |
| 648 | superstructure_writer.set_wrist_talon( |
| 649 | ::std::unique_ptr<Talon>(new Talon(0))); |
Comran Morshed | f4cd764 | 2016-02-15 20:40:49 +0000 | [diff] [blame] | 650 | superstructure_writer.set_rollers_talon( |
| 651 | ::std::unique_ptr<Talon>(new Talon(0))); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 652 | ::std::thread superstructure_writer_thread( |
| 653 | ::std::ref(superstructure_writer)); |
| 654 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 655 | ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm( |
| 656 | new ::frc971::wpilib::BufferedPcm()); |
| 657 | SolenoidWriter solenoid_writer(pcm); |
| 658 | solenoid_writer.set_drivetrain_left(pcm->MakeSolenoid(6)); |
| 659 | solenoid_writer.set_drivetrain_right(pcm->MakeSolenoid(7)); |
Comran Morshed | b79c424 | 2016-02-06 18:27:26 +0000 | [diff] [blame] | 660 | solenoid_writer.set_shooter_clamp(pcm->MakeSolenoid(6)); |
| 661 | solenoid_writer.set_shooter_pusher(pcm->MakeSolenoid(7)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 662 | |
| 663 | solenoid_writer.set_pressure_switch(make_unique<DigitalInput>(25)); |
| 664 | solenoid_writer.set_compressor_relay(make_unique<Relay>(0)); |
| 665 | ::std::thread solenoid_thread(::std::ref(solenoid_writer)); |
| 666 | |
| 667 | // Wait forever. Not much else to do... |
| 668 | while (true) { |
| 669 | const int r = select(0, nullptr, nullptr, nullptr, nullptr); |
| 670 | if (r != 0) { |
| 671 | PLOG(WARNING, "infinite select failed"); |
| 672 | } else { |
| 673 | PLOG(WARNING, "infinite select succeeded??\n"); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | LOG(ERROR, "Exiting WPILibRobot\n"); |
| 678 | |
| 679 | joystick_sender.Quit(); |
| 680 | joystick_thread.join(); |
| 681 | pdp_fetcher.Quit(); |
| 682 | pdp_fetcher_thread.join(); |
| 683 | reader.Quit(); |
| 684 | reader_thread.join(); |
| 685 | gyro_sender.Quit(); |
| 686 | gyro_thread.join(); |
| 687 | |
| 688 | drivetrain_writer.Quit(); |
| 689 | drivetrain_writer_thread.join(); |
Comran Morshed | 225f0b9 | 2016-02-10 20:34:27 +0000 | [diff] [blame] | 690 | shooter_writer.Quit(); |
| 691 | shooter_writer_thread.join(); |
| 692 | superstructure_writer.Quit(); |
| 693 | superstructure_writer_thread.join(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 694 | solenoid_writer.Quit(); |
| 695 | solenoid_thread.join(); |
| 696 | |
| 697 | ::aos::Cleanup(); |
| 698 | } |
| 699 | }; |
| 700 | |
| 701 | } // namespace wpilib |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 702 | } // namespace y2016 |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 703 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 704 | AOS_ROBOT_CLASS(::y2016::wpilib::WPILibRobot); |