Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <unistd.h> |
| 4 | #include <inttypes.h> |
| 5 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 6 | #include <chrono> |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 7 | #include <thread> |
| 8 | #include <mutex> |
| 9 | #include <functional> |
| 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/DigitalGlitchFilter.h" |
| 14 | #include "frc971/wpilib/ahal/DriverStation.h" |
| 15 | #include "frc971/wpilib/ahal/Encoder.h" |
| 16 | #include "frc971/wpilib/ahal/PowerDistributionPanel.h" |
| 17 | #include "frc971/wpilib/ahal/Relay.h" |
| 18 | #include "frc971/wpilib/ahal/Talon.h" |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 19 | #include "frc971/wpilib/wpilib_robot_base.h" |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 20 | #undef ERROR |
| 21 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 22 | #include "aos/controls/control_loops_generated.h" |
| 23 | #include "aos/events/shm_event_loop.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 24 | #include "aos/init.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 25 | #include "aos/logging/logging.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 26 | #include "aos/make_unique.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 27 | #include "aos/robot_state/robot_state_generated.h" |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 28 | #include "aos/stl_mutex/stl_mutex.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 29 | #include "aos/time/time.h" |
| 30 | #include "aos/util/log_interval.h" |
| 31 | #include "aos/util/phased_loop.h" |
| 32 | #include "aos/util/wrapping_counter.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 33 | #include "frc971/control_loops/drivetrain/drivetrain_output_generated.h" |
| 34 | #include "frc971/control_loops/drivetrain/drivetrain_position_generated.h" |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 35 | #include "frc971/wpilib/buffered_pcm.h" |
Austin Schuh | 2a671df | 2016-11-26 15:00:06 -0800 | [diff] [blame] | 36 | #include "frc971/wpilib/buffered_solenoid.h" |
Brian Silverman | b5b46ca | 2016-03-13 01:14:17 -0500 | [diff] [blame] | 37 | #include "frc971/wpilib/dma.h" |
Austin Schuh | 2a671df | 2016-11-26 15:00:06 -0800 | [diff] [blame] | 38 | #include "frc971/wpilib/dma_edge_counting.h" |
Sabina Davis | e33f59a | 2019-02-03 01:17:45 -0800 | [diff] [blame] | 39 | #include "frc971/wpilib/drivetrain_writer.h" |
Austin Schuh | 2a671df | 2016-11-26 15:00:06 -0800 | [diff] [blame] | 40 | #include "frc971/wpilib/encoder_and_potentiometer.h" |
Austin Schuh | 2a671df | 2016-11-26 15:00:06 -0800 | [diff] [blame] | 41 | #include "frc971/wpilib/interrupt_edge_counting.h" |
| 42 | #include "frc971/wpilib/joystick_sender.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 43 | #include "frc971/wpilib/logging_generated.h" |
Austin Schuh | 2a671df | 2016-11-26 15:00:06 -0800 | [diff] [blame] | 44 | #include "frc971/wpilib/loop_output_handler.h" |
Austin Schuh | 45a549f | 2019-02-02 15:43:56 -0800 | [diff] [blame] | 45 | #include "frc971/wpilib/sensor_reader.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 46 | #include "y2012/control_loops/accessories/accessories_generated.h" |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 47 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 48 | namespace accessories = ::y2012::control_loops::accessories; |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 49 | using namespace frc; |
Brian Silverman | f819b44 | 2019-01-20 16:51:04 -0800 | [diff] [blame] | 50 | using aos::make_unique; |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 51 | |
| 52 | namespace y2012 { |
| 53 | namespace wpilib { |
| 54 | |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 55 | double drivetrain_translate(int32_t in) { |
| 56 | return -static_cast<double>(in) / |
| 57 | (256.0 /*cpr*/ * 4.0 /*4x*/) * |
| 58 | 1 * |
| 59 | (3.5 /*wheel diameter*/ * 2.54 / 100.0 * M_PI) * 2.0 / 2.0; |
| 60 | } |
| 61 | |
| 62 | double drivetrain_velocity_translate(double in) { |
| 63 | return (1.0 / in) / 256.0 /*cpr*/ * |
| 64 | 1 * |
| 65 | (3.5 /*wheel diameter*/ * 2.54 / 100.0 * M_PI) * 2.0 / 2.0; |
| 66 | } |
| 67 | |
Austin Schuh | 45a549f | 2019-02-02 15:43:56 -0800 | [diff] [blame] | 68 | class SensorReader : public ::frc971::wpilib::SensorReader { |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 69 | public: |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 70 | SensorReader(::aos::ShmEventLoop *event_loop) |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 71 | : ::frc971::wpilib::SensorReader(event_loop), |
| 72 | accessories_position_sender_( |
| 73 | event_loop->MakeSender<::aos::control_loops::Position>( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 74 | "/accessories")), |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 75 | drivetrain_position_sender_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 76 | event_loop |
| 77 | ->MakeSender<::frc971::control_loops::drivetrain::Position>( |
| 78 | "/drivetrain")) {} |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 79 | |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 80 | void RunIteration() { |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 81 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 82 | auto builder = drivetrain_position_sender_.MakeBuilder(); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 83 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 84 | frc971::control_loops::drivetrain::Position::Builder position_builder = |
| 85 | builder.MakeBuilder<frc971::control_loops::drivetrain::Position>(); |
| 86 | position_builder.add_right_encoder( |
| 87 | drivetrain_translate(drivetrain_right_encoder_->GetRaw())); |
| 88 | position_builder.add_left_encoder( |
| 89 | -drivetrain_translate(drivetrain_left_encoder_->GetRaw())); |
| 90 | position_builder.add_left_speed( |
| 91 | drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod())); |
| 92 | position_builder.add_right_speed(drivetrain_velocity_translate( |
| 93 | drivetrain_right_encoder_->GetPeriod())); |
| 94 | |
| 95 | builder.Send(position_builder.Finish()); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 98 | { |
| 99 | auto builder = accessories_position_sender_.MakeBuilder(); |
| 100 | builder.Send( |
| 101 | builder.MakeBuilder<::aos::control_loops::Position>().Finish()); |
| 102 | } |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 103 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 104 | |
| 105 | private: |
| 106 | ::aos::Sender<::aos::control_loops::Position> accessories_position_sender_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 107 | ::aos::Sender<::frc971::control_loops::drivetrain::Position> |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 108 | drivetrain_position_sender_; |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | class SolenoidWriter { |
| 112 | public: |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 113 | SolenoidWriter(::aos::ShmEventLoop *event_loop, |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 114 | const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm) |
| 115 | : event_loop_(event_loop), |
| 116 | pcm_(pcm), |
| 117 | drivetrain_fetcher_( |
| 118 | event_loop_ |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 119 | ->MakeFetcher<::frc971::control_loops::drivetrain::Output>( |
| 120 | "/drivetrain")), |
| 121 | accessories_fetcher_( |
| 122 | event_loop_ |
| 123 | ->MakeFetcher<::y2012::control_loops::accessories::Message>( |
| 124 | "/accessories")), |
| 125 | pneumatics_to_log_sender_( |
| 126 | event_loop->MakeSender<::frc971::wpilib::PneumaticsToLog>("/aos")) { |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 127 | event_loop->set_name("Solenoids"); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 128 | event_loop_->SetRuntimeRealtimePriority(27); |
| 129 | |
| 130 | event_loop_->AddPhasedLoop([this](int iterations) { Loop(iterations); }, |
| 131 | ::std::chrono::milliseconds(20), |
| 132 | ::std::chrono::milliseconds(1)); |
| 133 | } |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 134 | |
| 135 | void set_drivetrain_high( |
| 136 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 137 | drivetrain_high_ = ::std::move(s); |
| 138 | } |
| 139 | |
| 140 | void set_drivetrain_low( |
| 141 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 142 | drivetrain_low_ = ::std::move(s); |
| 143 | } |
| 144 | |
| 145 | void set_s1(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 146 | s1_ = ::std::move(s); |
| 147 | } |
| 148 | |
| 149 | void set_s2(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 150 | s2_ = ::std::move(s); |
| 151 | } |
| 152 | |
| 153 | void set_s3(::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) { |
| 154 | s3_ = ::std::move(s); |
| 155 | } |
| 156 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 157 | void Loop(const int iterations) { |
| 158 | if (iterations != 1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 159 | AOS_LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 160 | } |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 161 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 162 | { |
| 163 | accessories_fetcher_.Fetch(); |
| 164 | if (accessories_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 165 | s1_->Set(accessories_fetcher_->solenoids()->Get(0)); |
| 166 | s2_->Set(accessories_fetcher_->solenoids()->Get(1)); |
| 167 | s3_->Set(accessories_fetcher_->solenoids()->Get(2)); |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 168 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 169 | } |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 170 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 171 | { |
| 172 | drivetrain_fetcher_.Fetch(); |
| 173 | if (drivetrain_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 174 | const bool high = drivetrain_fetcher_->left_high() || |
| 175 | drivetrain_fetcher_->right_high(); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 176 | drivetrain_high_->Set(high); |
| 177 | drivetrain_low_->Set(!high); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 178 | } |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 179 | } |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 180 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 181 | { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 182 | auto builder = pneumatics_to_log_sender_.MakeBuilder(); |
| 183 | |
| 184 | ::frc971::wpilib::PneumaticsToLog::Builder to_log_builder = |
| 185 | builder.MakeBuilder<frc971::wpilib::PneumaticsToLog>(); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 186 | pcm_->Flush(); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 187 | to_log_builder.add_read_solenoids(pcm_->GetAll()); |
| 188 | builder.Send(to_log_builder.Finish()); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 192 | private: |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 193 | ::aos::EventLoop *event_loop_; |
| 194 | |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 195 | const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_; |
| 196 | |
| 197 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_high_; |
| 198 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> drivetrain_low_; |
| 199 | ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s1_, s2_, s3_; |
| 200 | |
| 201 | ::std::unique_ptr<Compressor> compressor_; |
| 202 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 203 | ::aos::Fetcher<::frc971::control_loops::drivetrain::Output> |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 204 | drivetrain_fetcher_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 205 | ::aos::Fetcher<::y2012::control_loops::accessories::Message> |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 206 | accessories_fetcher_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 207 | |
| 208 | aos::Sender<::frc971::wpilib::PneumaticsToLog> pneumatics_to_log_sender_; |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 209 | }; |
| 210 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 211 | class AccessoriesWriter : public ::frc971::wpilib::LoopOutputHandler< |
| 212 | control_loops::accessories::Message> { |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 213 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 214 | AccessoriesWriter(::aos::EventLoop *event_loop) |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 215 | : ::frc971::wpilib::LoopOutputHandler< |
| 216 | control_loops::accessories::Message>(event_loop, "/accessories") {} |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 217 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 218 | void set_talon1(::std::unique_ptr<Talon> t) { talon1_ = ::std::move(t); } |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 219 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 220 | void set_talon2(::std::unique_ptr<Talon> t) { talon2_ = ::std::move(t); } |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 221 | |
| 222 | private: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 223 | virtual void Write( |
| 224 | const control_loops::accessories::Message &output) override { |
| 225 | talon1_->SetSpeed(output.sticks()->Get(0)); |
| 226 | talon2_->SetSpeed(output.sticks()->Get(1)); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | virtual void Stop() override { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 230 | AOS_LOG(WARNING, "shooter output too old\n"); |
Brian Silverman | 6eaa2d8 | 2017-02-04 20:48:30 -0800 | [diff] [blame] | 231 | talon1_->SetDisabled(); |
| 232 | talon2_->SetDisabled(); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | ::std::unique_ptr<Talon> talon1_, talon2_; |
| 236 | }; |
| 237 | |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 238 | class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase { |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 239 | public: |
| 240 | ::std::unique_ptr<Encoder> make_encoder(int index) { |
| 241 | return make_unique<Encoder>(10 + index * 2, 11 + index * 2, false, |
| 242 | Encoder::k4X); |
| 243 | } |
| 244 | |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 245 | void Run() override { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 246 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 247 | aos::configuration::ReadConfig("config.json"); |
| 248 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 249 | // Thread 1. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 250 | ::aos::ShmEventLoop joystick_sender_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 251 | ::frc971::wpilib::JoystickSender joystick_sender( |
| 252 | &joystick_sender_event_loop); |
| 253 | AddLoop(&joystick_sender_event_loop); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 254 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 255 | // Thread 2. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 256 | ::aos::ShmEventLoop sensor_reader_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 257 | SensorReader sensor_reader(&sensor_reader_event_loop); |
| 258 | sensor_reader.set_drivetrain_left_encoder(make_encoder(0)); |
| 259 | sensor_reader.set_drivetrain_right_encoder(make_encoder(1)); |
| 260 | AddLoop(&sensor_reader_event_loop); |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 261 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 262 | // Thread 3. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 263 | ::aos::ShmEventLoop output_event_loop(&config.message()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 264 | ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop); |
Sabina Davis | e33f59a | 2019-02-03 01:17:45 -0800 | [diff] [blame] | 265 | drivetrain_writer.set_left_controller0( |
| 266 | ::std::unique_ptr<Talon>(new Talon(3)), true); |
| 267 | drivetrain_writer.set_right_controller0( |
| 268 | ::std::unique_ptr<Talon>(new Talon(4)), false); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 269 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 270 | ::y2012::wpilib::AccessoriesWriter accessories_writer(&output_event_loop); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 271 | accessories_writer.set_talon1(::std::unique_ptr<Talon>(new Talon(5))); |
| 272 | accessories_writer.set_talon2(::std::unique_ptr<Talon>(new Talon(6))); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 273 | AddLoop(&output_event_loop); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 274 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 275 | // Thread 4. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 276 | ::aos::ShmEventLoop solenoid_writer_event_loop(&config.message()); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 277 | ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm( |
| 278 | new ::frc971::wpilib::BufferedPcm()); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 279 | SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 280 | solenoid_writer.set_drivetrain_high(pcm->MakeSolenoid(0)); |
| 281 | solenoid_writer.set_drivetrain_low(pcm->MakeSolenoid(2)); |
| 282 | solenoid_writer.set_s1(pcm->MakeSolenoid(1)); |
| 283 | solenoid_writer.set_s2(pcm->MakeSolenoid(3)); |
| 284 | solenoid_writer.set_s3(pcm->MakeSolenoid(4)); |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 285 | AddLoop(&solenoid_writer_event_loop); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 286 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 287 | RunLoops(); |
Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 288 | } |
| 289 | }; |
| 290 | |
| 291 | } // namespace wpilib |
| 292 | } // namespace y2012 |
| 293 | |
| 294 | |
Brian Silverman | 5090c43 | 2016-01-02 14:44:26 -0800 | [diff] [blame] | 295 | AOS_ROBOT_CLASS(::y2012::wpilib::WPILibRobot); |