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