Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 1 | #include <inttypes.h> |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 5 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 6 | #include <chrono> |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 7 | #include <functional> |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 8 | #include <mutex> |
| 9 | #include <thread> |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 10 | |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 11 | #include "frc971/wpilib/ahal/AnalogInput.h" |
| 12 | #include "frc971/wpilib/ahal/Compressor.h" |
| 13 | #include "frc971/wpilib/ahal/DigitalInput.h" |
| 14 | #include "frc971/wpilib/ahal/DriverStation.h" |
| 15 | #include "frc971/wpilib/ahal/Encoder.h" |
| 16 | #include "frc971/wpilib/ahal/Relay.h" |
| 17 | #include "frc971/wpilib/ahal/Talon.h" |
Campbell Crowley | c0cfb13 | 2015-12-30 20:58:02 -0800 | [diff] [blame] | 18 | #include "frc971/wpilib/wpilib_robot_base.h" |
Austin Schuh | bc9a2ab | 2015-11-26 16:20:17 -0800 | [diff] [blame] | 19 | #undef ERROR |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 20 | |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 21 | #include "aos/init.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 22 | #include "aos/logging/logging.h" |
| 23 | #include "aos/logging/queue_logging.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 24 | #include "aos/make_unique.h" |
| 25 | #include "aos/robot_state/robot_state.q.h" |
| 26 | #include "aos/stl_mutex/stl_mutex.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 27 | #include "aos/time/time.h" |
| 28 | #include "aos/util/log_interval.h" |
| 29 | #include "aos/util/phased_loop.h" |
| 30 | #include "aos/util/wrapping_counter.h" |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 31 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 32 | #include "frc971/wpilib/buffered_pcm.h" |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 33 | #include "frc971/wpilib/buffered_solenoid.h" |
Brian Silverman | b5b46ca | 2016-03-13 01:14:17 -0500 | [diff] [blame] | 34 | #include "frc971/wpilib/dma.h" |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 35 | #include "frc971/wpilib/gyro_sender.h" |
| 36 | #include "frc971/wpilib/joystick_sender.h" |
| 37 | #include "frc971/wpilib/logging.q.h" |
| 38 | #include "frc971/wpilib/loop_output_handler.h" |
| 39 | #include "frc971/wpilib/pdp_fetcher.h" |
| 40 | #include "frc971/wpilib/sensor_reader.h" |
| 41 | #include "y2014_bot3/control_loops/drivetrain/drivetrain_base.h" |
| 42 | #include "y2014_bot3/control_loops/rollers/rollers.h" |
| 43 | #include "y2014_bot3/control_loops/rollers/rollers.q.h" |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 44 | |
| 45 | #ifndef M_PI |
| 46 | #define M_PI 3.14159265358979323846 |
| 47 | #endif |
| 48 | |
| 49 | using ::aos::util::SimpleLogInterval; |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 50 | using ::frc971::control_loops::drivetrain_queue; |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 51 | using ::y2014_bot3::control_loops::rollers_queue; |
| 52 | using ::frc971::wpilib::BufferedPcm; |
| 53 | using ::frc971::wpilib::BufferedSolenoid; |
| 54 | using ::frc971::wpilib::LoopOutputHandler; |
| 55 | using ::frc971::wpilib::JoystickSender; |
| 56 | using ::frc971::wpilib::GyroSender; |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 57 | using namespace frc; |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 58 | using aos::make_unique; |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 59 | |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 60 | namespace y2014_bot3 { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 61 | namespace wpilib { |
| 62 | |
| 63 | double drivetrain_translate(int32_t in) { |
| 64 | return static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) * |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 65 | ::y2014_bot3::control_loops::drivetrain::kDrivetrainEncoderRatio * |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 66 | (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI); |
| 67 | } |
| 68 | |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 69 | double drivetrain_velocity_translate(double in) { |
| 70 | return (1.0 / in) / 256.0 /*cpr*/ * |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 71 | ::y2014_bot3::control_loops::drivetrain::kDrivetrainEncoderRatio * |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 72 | (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI); |
| 73 | } |
| 74 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 75 | // Reads in our inputs. (sensors, voltages, etc.) |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 76 | class SensorReader : public ::frc971::wpilib::SensorReader { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 77 | public: |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 78 | void RunIteration() { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 79 | // Drivetrain |
| 80 | { |
| 81 | auto drivetrain_message = drivetrain_queue.position.MakeMessage(); |
| 82 | drivetrain_message->right_encoder = |
Austin Schuh | ba32a9e | 2018-11-03 15:28:13 -0700 | [diff] [blame] | 83 | -drivetrain_translate(drivetrain_right_encoder_->GetRaw()); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 84 | drivetrain_message->left_encoder = |
Austin Schuh | ba32a9e | 2018-11-03 15:28:13 -0700 | [diff] [blame] | 85 | drivetrain_translate(drivetrain_left_encoder_->GetRaw()); |
Brian Silverman | 51091a0 | 2015-12-26 15:56:58 -0800 | [diff] [blame] | 86 | drivetrain_message->left_speed = |
| 87 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod()); |
| 88 | drivetrain_message->right_speed = |
| 89 | drivetrain_velocity_translate(drivetrain_right_encoder_->GetPeriod()); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 90 | |
| 91 | drivetrain_message.Send(); |
| 92 | } |
| 93 | |
| 94 | // Rollers |
| 95 | { |
| 96 | auto rollers_message = rollers_queue.position.MakeMessage(); |
| 97 | rollers_message.Send(); |
| 98 | } |
| 99 | } |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | // Writes out our pneumatic outputs. |
| 103 | class SolenoidWriter { |
| 104 | public: |
| 105 | SolenoidWriter(const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm) |
| 106 | : pcm_(pcm), |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 107 | drivetrain_(".frc971.control_loops.drivetrain_queue.output"), |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 108 | rollers_(".y2014_bot3.control_loops.rollers_queue.output") {} |
| 109 | |
| 110 | void set_pressure_switch(::std::unique_ptr<DigitalInput> pressure_switch) { |
| 111 | pressure_switch_ = ::std::move(pressure_switch); |
| 112 | } |
| 113 | |
| 114 | void set_compressor_relay(::std::unique_ptr<Relay> compressor_relay) { |
| 115 | compressor_relay_ = ::std::move(compressor_relay); |
| 116 | } |
| 117 | |
| 118 | void set_drivetrain_left(::std::unique_ptr<BufferedSolenoid> s) { |
| 119 | drivetrain_left_ = ::std::move(s); |
| 120 | } |
| 121 | |
| 122 | void set_drivetrain_right(::std::unique_ptr<BufferedSolenoid> s) { |
| 123 | drivetrain_right_ = ::std::move(s); |
| 124 | } |
| 125 | |
| 126 | void set_rollers_front(::std::unique_ptr<BufferedSolenoid> s) { |
| 127 | rollers_front_ = ::std::move(s); |
| 128 | } |
| 129 | |
| 130 | void set_rollers_back(::std::unique_ptr<BufferedSolenoid> s) { |
| 131 | rollers_back_ = ::std::move(s); |
| 132 | } |
| 133 | |
| 134 | void operator()() { |
| 135 | ::aos::SetCurrentThreadName("Solenoids"); |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 136 | ::aos::SetCurrentThreadRealtimePriority(27); |
| 137 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 138 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(20), |
| 139 | ::std::chrono::milliseconds(1)); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 140 | |
| 141 | while (run_) { |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 142 | { |
| 143 | const int iterations = phased_loop.SleepUntilNext(); |
| 144 | if (iterations != 1) { |
| 145 | LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
| 146 | } |
| 147 | } |
| 148 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 149 | // Drivetrain |
| 150 | { |
| 151 | drivetrain_.FetchLatest(); |
| 152 | if (drivetrain_.get()) { |
| 153 | LOG_STRUCT(DEBUG, "solenoids", *drivetrain_); |
| 154 | drivetrain_left_->Set(drivetrain_->left_high); |
| 155 | drivetrain_right_->Set(drivetrain_->right_high); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // Intake |
| 160 | { |
| 161 | rollers_.FetchLatest(); |
| 162 | if (rollers_.get()) { |
| 163 | LOG_STRUCT(DEBUG, "solenoids", *rollers_); |
| 164 | rollers_front_->Set(rollers_->front_extended); |
| 165 | rollers_back_->Set(rollers_->back_extended); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Compressor |
| 170 | ::aos::joystick_state.FetchLatest(); |
| 171 | { |
| 172 | ::frc971::wpilib::PneumaticsToLog to_log; |
| 173 | { |
| 174 | // Refill if pneumatic pressure goes too low. |
| 175 | const bool compressor_on = !pressure_switch_->Get(); |
| 176 | to_log.compressor_on = compressor_on; |
| 177 | if (compressor_on) { |
| 178 | compressor_relay_->Set(Relay::kForward); |
| 179 | } else { |
| 180 | compressor_relay_->Set(Relay::kOff); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | pcm_->Flush(); |
| 185 | to_log.read_solenoids = pcm_->GetAll(); |
| 186 | LOG_STRUCT(DEBUG, "pneumatics info", to_log); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | void Quit() { run_ = false; } |
| 192 | |
| 193 | private: |
| 194 | const ::std::unique_ptr<BufferedPcm> &pcm_; |
| 195 | |
| 196 | ::std::unique_ptr<BufferedSolenoid> drivetrain_left_, drivetrain_right_; |
| 197 | ::std::unique_ptr<BufferedSolenoid> rollers_front_, rollers_back_; |
| 198 | |
| 199 | ::std::unique_ptr<DigitalInput> pressure_switch_; |
| 200 | ::std::unique_ptr<Relay> compressor_relay_; |
| 201 | |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 202 | ::aos::Queue<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_; |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 203 | ::aos::Queue<::y2014_bot3::control_loops::RollersQueue::Output> rollers_; |
| 204 | |
| 205 | ::std::atomic<bool> run_{true}; |
| 206 | }; |
| 207 | |
| 208 | // Writes out drivetrain voltages. |
| 209 | class DrivetrainWriter : public LoopOutputHandler { |
| 210 | public: |
| 211 | void set_left_drivetrain_talon(::std::unique_ptr<Talon> t) { |
| 212 | left_drivetrain_talon_ = ::std::move(t); |
| 213 | } |
| 214 | |
| 215 | void set_right_drivetrain_talon(::std::unique_ptr<Talon> t) { |
| 216 | right_drivetrain_talon_ = ::std::move(t); |
| 217 | } |
| 218 | |
| 219 | private: |
| 220 | virtual void Read() override { |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 221 | ::frc971::control_loops::drivetrain_queue.output.FetchAnother(); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | virtual void Write() override { |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 225 | auto &queue = ::frc971::control_loops::drivetrain_queue.output; |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 226 | LOG_STRUCT(DEBUG, "will output", *queue); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 227 | left_drivetrain_talon_->SetSpeed(-queue->left_voltage / 12.0); |
| 228 | right_drivetrain_talon_->SetSpeed(queue->right_voltage / 12.0); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | virtual void Stop() override { |
| 232 | LOG(WARNING, "drivetrain output too old\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 233 | left_drivetrain_talon_->SetDisabled(); |
| 234 | right_drivetrain_talon_->SetDisabled(); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | ::std::unique_ptr<Talon> left_drivetrain_talon_; |
| 238 | ::std::unique_ptr<Talon> right_drivetrain_talon_; |
| 239 | }; |
| 240 | |
| 241 | // Writes out rollers voltages. |
| 242 | class RollersWriter : public LoopOutputHandler { |
| 243 | public: |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 244 | void set_rollers_front_intake_talon(::std::unique_ptr<Talon> t_left, |
| 245 | ::std::unique_ptr<Talon> t_right) { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 246 | rollers_front_left_intake_talon_ = ::std::move(t_left); |
| 247 | rollers_front_right_intake_talon_ = ::std::move(t_right); |
| 248 | } |
| 249 | |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 250 | void set_rollers_back_intake_talon(::std::unique_ptr<Talon> t_left, |
| 251 | ::std::unique_ptr<Talon> t_right) { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 252 | rollers_back_left_intake_talon_ = ::std::move(t_left); |
| 253 | rollers_back_right_intake_talon_ = ::std::move(t_right); |
| 254 | } |
| 255 | |
| 256 | void set_rollers_low_goal_talon(::std::unique_ptr<Talon> t) { |
| 257 | rollers_low_goal_talon_ = ::std::move(t); |
| 258 | } |
| 259 | |
| 260 | private: |
| 261 | virtual void Read() override { |
| 262 | ::y2014_bot3::control_loops::rollers_queue.output.FetchAnother(); |
| 263 | } |
| 264 | |
| 265 | virtual void Write() override { |
| 266 | auto &queue = ::y2014_bot3::control_loops::rollers_queue.output; |
| 267 | LOG_STRUCT(DEBUG, "will output", *queue); |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 268 | rollers_front_left_intake_talon_->SetSpeed(queue->front_intake_voltage / |
| 269 | 12.0); |
| 270 | rollers_front_right_intake_talon_->SetSpeed( |
| 271 | -(queue->front_intake_voltage / 12.0)); |
| 272 | rollers_back_left_intake_talon_->SetSpeed(queue->back_intake_voltage / |
| 273 | 12.0); |
| 274 | rollers_back_right_intake_talon_->SetSpeed( |
| 275 | -(queue->back_intake_voltage / 12.0)); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 276 | rollers_low_goal_talon_->SetSpeed(queue->low_goal_voltage / 12.0); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | virtual void Stop() override { |
| 280 | LOG(WARNING, "Intake output too old\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 281 | rollers_front_left_intake_talon_->SetDisabled(); |
| 282 | rollers_front_right_intake_talon_->SetDisabled(); |
| 283 | rollers_back_left_intake_talon_->SetDisabled(); |
| 284 | rollers_back_right_intake_talon_->SetDisabled(); |
| 285 | rollers_low_goal_talon_->SetDisabled(); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | ::std::unique_ptr<Talon> rollers_front_left_intake_talon_, |
| 289 | rollers_back_left_intake_talon_, rollers_front_right_intake_talon_, |
| 290 | rollers_back_right_intake_talon_, rollers_low_goal_talon_; |
| 291 | }; |
| 292 | |
Campbell Crowley | c0cfb13 | 2015-12-30 20:58:02 -0800 | [diff] [blame] | 293 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 294 | public: |
| 295 | ::std::unique_ptr<Encoder> make_encoder(int index) { |
| 296 | return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false, |
| 297 | Encoder::k4X); |
| 298 | } |
Campbell Crowley | c0cfb13 | 2015-12-30 20:58:02 -0800 | [diff] [blame] | 299 | void Run() override { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 300 | ::aos::InitNRT(); |
| 301 | ::aos::SetCurrentThreadName("StartCompetition"); |
| 302 | |
| 303 | JoystickSender joystick_sender; |
| 304 | ::std::thread joystick_thread(::std::ref(joystick_sender)); |
| 305 | |
Brian Silverman | 425492b | 2015-12-30 15:23:55 -0800 | [diff] [blame] | 306 | ::frc971::wpilib::PDPFetcher pdp_fetcher; |
| 307 | ::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher)); |
| 308 | |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 309 | // TODO(comran): IO ports are placeholders at the moment, so match them to |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 310 | // the robot before turning on. |
| 311 | |
| 312 | // Sensors |
Brian Silverman | 39b339e | 2016-01-03 13:24:22 -0800 | [diff] [blame] | 313 | SensorReader reader; |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 314 | reader.set_drivetrain_left_encoder(make_encoder(4)); |
| 315 | reader.set_drivetrain_right_encoder(make_encoder(5)); |
| 316 | |
| 317 | ::std::thread reader_thread(::std::ref(reader)); |
| 318 | GyroSender gyro_sender; |
| 319 | ::std::thread gyro_thread(::std::ref(gyro_sender)); |
| 320 | |
| 321 | // Outputs |
| 322 | DrivetrainWriter drivetrain_writer; |
| 323 | drivetrain_writer.set_left_drivetrain_talon( |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 324 | ::std::unique_ptr<Talon>(new Talon(5))); |
Adam Snaider | 83eae56 | 2016-09-10 16:47:33 -0700 | [diff] [blame] | 325 | drivetrain_writer.set_right_drivetrain_talon( |
| 326 | ::std::unique_ptr<Talon>(new Talon(2))); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 327 | ::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer)); |
| 328 | |
| 329 | RollersWriter rollers_writer; |
| 330 | rollers_writer.set_rollers_front_intake_talon( |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 331 | ::std::unique_ptr<Talon>(new Talon(3)), |
| 332 | ::std::unique_ptr<Talon>(new Talon(7))); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 333 | rollers_writer.set_rollers_back_intake_talon( |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 334 | ::std::unique_ptr<Talon>(new Talon(1)), |
| 335 | ::std::unique_ptr<Talon>(new Talon(6))); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 336 | |
| 337 | rollers_writer.set_rollers_low_goal_talon( |
| 338 | ::std::unique_ptr<Talon>(new Talon(4))); |
| 339 | ::std::thread rollers_writer_thread(::std::ref(rollers_writer)); |
| 340 | |
| 341 | ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm( |
| 342 | new ::frc971::wpilib::BufferedPcm()); |
| 343 | SolenoidWriter solenoid_writer(pcm); |
| 344 | solenoid_writer.set_drivetrain_left(pcm->MakeSolenoid(6)); |
| 345 | solenoid_writer.set_drivetrain_right(pcm->MakeSolenoid(5)); |
| 346 | solenoid_writer.set_rollers_front(pcm->MakeSolenoid(2)); |
| 347 | solenoid_writer.set_rollers_back(pcm->MakeSolenoid(4)); |
| 348 | |
| 349 | // Don't change the following IDs. |
| 350 | solenoid_writer.set_pressure_switch(make_unique<DigitalInput>(9)); |
| 351 | solenoid_writer.set_compressor_relay(make_unique<Relay>(0)); |
| 352 | ::std::thread solenoid_thread(::std::ref(solenoid_writer)); |
| 353 | |
| 354 | // Wait forever. Not much else to do... |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 355 | while (true) { |
| 356 | const int r = select(0, nullptr, nullptr, nullptr, nullptr); |
| 357 | if (r != 0) { |
| 358 | PLOG(WARNING, "infinite select failed"); |
| 359 | } else { |
| 360 | PLOG(WARNING, "infinite select succeeded??\n"); |
| 361 | } |
| 362 | } |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 363 | |
| 364 | LOG(ERROR, "Exiting WPILibRobot\n"); |
| 365 | |
| 366 | joystick_sender.Quit(); |
| 367 | joystick_thread.join(); |
Brian Silverman | 425492b | 2015-12-30 15:23:55 -0800 | [diff] [blame] | 368 | pdp_fetcher.Quit(); |
| 369 | pdp_fetcher_thread.join(); |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 370 | reader.Quit(); |
| 371 | reader_thread.join(); |
| 372 | gyro_sender.Quit(); |
| 373 | gyro_thread.join(); |
| 374 | |
| 375 | drivetrain_writer.Quit(); |
| 376 | drivetrain_writer_thread.join(); |
| 377 | |
| 378 | rollers_writer.Quit(); |
| 379 | rollers_writer_thread.join(); |
| 380 | |
| 381 | solenoid_writer.Quit(); |
| 382 | solenoid_thread.join(); |
| 383 | |
| 384 | ::aos::Cleanup(); |
| 385 | } |
| 386 | }; |
| 387 | |
| 388 | } // namespace wpilib |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 389 | } // namespace y2014_bot3 |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 390 | |
Austin Schuh | 4d11f9a | 2019-02-02 16:30:06 -0800 | [diff] [blame^] | 391 | AOS_ROBOT_CLASS(::y2014_bot3::wpilib::WPILibRobot); |