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