blob: ee5fc168ef8c137a9d5f06a0f6ba57eb9920ec80 [file] [log] [blame]
Austin Schuh4d11f9a2019-02-02 16:30:06 -08001#include <inttypes.h>
Comran Morshed41ed7c22015-11-04 21:03:37 +00002#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
Comran Morshed41ed7c22015-11-04 21:03:37 +00005
Austin Schuh8aec1ed2016-05-01 13:29:20 -07006#include <chrono>
Comran Morshed41ed7c22015-11-04 21:03:37 +00007#include <functional>
Austin Schuh4d11f9a2019-02-02 16:30:06 -08008#include <mutex>
9#include <thread>
Comran Morshed41ed7c22015-11-04 21:03:37 +000010
Parker Schuhd3b7a8872018-02-19 16:42:27 -080011#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 Crowleyc0cfb132015-12-30 20:58:02 -080018#include "frc971/wpilib/wpilib_robot_base.h"
Austin Schuhbc9a2ab2015-11-26 16:20:17 -080019#undef ERROR
Comran Morshed41ed7c22015-11-04 21:03:37 +000020
Alex Perrycb7da4b2019-08-28 19:35:56 -070021#include "aos/events/shm_event_loop.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080022#include "aos/init.h"
John Park33858a32018-09-28 23:05:48 -070023#include "aos/logging/logging.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080024#include "aos/make_unique.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070025#include "aos/robot_state/robot_state_generated.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080026#include "aos/stl_mutex/stl_mutex.h"
John Park33858a32018-09-28 23:05:48 -070027#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 Perrycb7da4b2019-08-28 19:35:56 -070031#include "frc971/control_loops/drivetrain/drivetrain_output_generated.h"
32#include "frc971/control_loops/drivetrain/drivetrain_position_generated.h"
Comran Morshed41ed7c22015-11-04 21:03:37 +000033#include "frc971/wpilib/buffered_pcm.h"
Austin Schuh4d11f9a2019-02-02 16:30:06 -080034#include "frc971/wpilib/buffered_solenoid.h"
Brian Silvermanb5b46ca2016-03-13 01:14:17 -050035#include "frc971/wpilib/dma.h"
Sabina Davis5ba275b2019-02-03 01:18:04 -080036#include "frc971/wpilib/drivetrain_writer.h"
Austin Schuh4d11f9a2019-02-02 16:30:06 -080037#include "frc971/wpilib/gyro_sender.h"
38#include "frc971/wpilib/joystick_sender.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070039#include "frc971/wpilib/logging_generated.h"
Austin Schuh4d11f9a2019-02-02 16:30:06 -080040#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"
Alex Perrycb7da4b2019-08-28 19:35:56 -070045#include "y2014_bot3/control_loops/rollers/rollers_output_generated.h"
46#include "y2014_bot3/control_loops/rollers/rollers_position_generated.h"
Comran Morshed41ed7c22015-11-04 21:03:37 +000047
48#ifndef M_PI
49#define M_PI 3.14159265358979323846
50#endif
51
52using ::aos::util::SimpleLogInterval;
Comran Morshed41ed7c22015-11-04 21:03:37 +000053using ::frc971::wpilib::BufferedPcm;
54using ::frc971::wpilib::BufferedSolenoid;
55using ::frc971::wpilib::LoopOutputHandler;
56using ::frc971::wpilib::JoystickSender;
57using ::frc971::wpilib::GyroSender;
Brian Silvermanf819b442019-01-20 16:51:04 -080058using aos::make_unique;
Comran Morshed41ed7c22015-11-04 21:03:37 +000059
Austin Schuh4d11f9a2019-02-02 16:30:06 -080060namespace y2014_bot3 {
Comran Morshed41ed7c22015-11-04 21:03:37 +000061namespace wpilib {
62
63double drivetrain_translate(int32_t in) {
64 return static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) *
Adam Snaider83eae562016-09-10 16:47:33 -070065 ::y2014_bot3::control_loops::drivetrain::kDrivetrainEncoderRatio *
Comran Morshed41ed7c22015-11-04 21:03:37 +000066 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
67}
68
Brian Silverman51091a02015-12-26 15:56:58 -080069double drivetrain_velocity_translate(double in) {
70 return (1.0 / in) / 256.0 /*cpr*/ *
Adam Snaider83eae562016-09-10 16:47:33 -070071 ::y2014_bot3::control_loops::drivetrain::kDrivetrainEncoderRatio *
Brian Silverman51091a02015-12-26 15:56:58 -080072 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
73}
74
Comran Morshed41ed7c22015-11-04 21:03:37 +000075// Reads in our inputs. (sensors, voltages, etc.)
Austin Schuh4d11f9a2019-02-02 16:30:06 -080076class SensorReader : public ::frc971::wpilib::SensorReader {
Comran Morshed41ed7c22015-11-04 21:03:37 +000077 public:
Austin Schuh217a9782019-12-21 23:02:50 -080078 SensorReader(::aos::ShmEventLoop *event_loop)
Austin Schuh30020d92019-05-27 13:07:02 -070079 : ::frc971::wpilib::SensorReader(event_loop),
80 rollers_position_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -070081 event_loop
82 ->MakeSender<::y2014_bot3::control_loops::rollers::Position>(
83 "/rollers")),
Austin Schuhbd0a40f2019-06-30 14:56:31 -070084 drivetrain_position_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -070085 event_loop
86 ->MakeSender<::frc971::control_loops::drivetrain::Position>(
87 "/drivetrain")) {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -080088
Comran Morshed41ed7c22015-11-04 21:03:37 +000089 void RunIteration() {
Comran Morshed41ed7c22015-11-04 21:03:37 +000090 // Drivetrain
91 {
Alex Perrycb7da4b2019-08-28 19:35:56 -070092 auto builder = drivetrain_position_sender_.MakeBuilder();
Comran Morshed41ed7c22015-11-04 21:03:37 +000093
Alex Perrycb7da4b2019-08-28 19:35:56 -070094 frc971::control_loops::drivetrain::Position::Builder position_builder =
95 builder.MakeBuilder<frc971::control_loops::drivetrain::Position>();
96 position_builder.add_right_encoder(
97 -drivetrain_translate(drivetrain_right_encoder_->GetRaw()));
98 position_builder.add_left_encoder(
99 drivetrain_translate(drivetrain_left_encoder_->GetRaw()));
100 position_builder.add_left_speed(
101 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod()));
102 position_builder.add_right_speed(drivetrain_velocity_translate(
103 drivetrain_right_encoder_->GetPeriod()));
104
105 builder.Send(position_builder.Finish());
Comran Morshed41ed7c22015-11-04 21:03:37 +0000106 }
107
108 // Rollers
109 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700110 auto builder = rollers_position_sender_.MakeBuilder();
111 builder.Send(
112 builder.MakeBuilder<control_loops::rollers::Position>().Finish());
Comran Morshed41ed7c22015-11-04 21:03:37 +0000113 }
114 }
Austin Schuh30020d92019-05-27 13:07:02 -0700115
116 private:
Alex Perrycb7da4b2019-08-28 19:35:56 -0700117 ::aos::Sender<::y2014_bot3::control_loops::rollers::Position>
Austin Schuh30020d92019-05-27 13:07:02 -0700118 rollers_position_sender_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700119 ::aos::Sender<::frc971::control_loops::drivetrain::Position>
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700120 drivetrain_position_sender_;
Comran Morshed41ed7c22015-11-04 21:03:37 +0000121};
122
123// Writes out our pneumatic outputs.
124class SolenoidWriter {
125 public:
Austin Schuh217a9782019-12-21 23:02:50 -0800126 SolenoidWriter(::aos::ShmEventLoop *event_loop,
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700127 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
Comran Morshed41ed7c22015-11-04 21:03:37 +0000128 : pcm_(pcm),
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700129 drivetrain_(
130 event_loop
Alex Perrycb7da4b2019-08-28 19:35:56 -0700131 ->MakeFetcher<::frc971::control_loops::drivetrain::Output>(
132 "/drivetrain")),
133 rollers_(
134 event_loop
135 ->MakeFetcher<::y2014_bot3::control_loops::rollers::Output>(
136 "/rollers")),
137 pneumatics_to_log_sender_(
138 event_loop->MakeSender<::frc971::wpilib::PneumaticsToLog>("/aos")) {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700139 event_loop->set_name("Solenoids");
140 event_loop->SetRuntimeRealtimePriority(27);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000141
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700142 event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); },
143 ::std::chrono::milliseconds(20),
144 ::std::chrono::milliseconds(1));
145 }
146
147 void set_pressure_switch(
148 ::std::unique_ptr<::frc::DigitalInput> pressure_switch) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000149 pressure_switch_ = ::std::move(pressure_switch);
150 }
151
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700152 void set_compressor_relay(::std::unique_ptr<::frc::Relay> compressor_relay) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000153 compressor_relay_ = ::std::move(compressor_relay);
154 }
155
156 void set_drivetrain_left(::std::unique_ptr<BufferedSolenoid> s) {
157 drivetrain_left_ = ::std::move(s);
158 }
159
160 void set_drivetrain_right(::std::unique_ptr<BufferedSolenoid> s) {
161 drivetrain_right_ = ::std::move(s);
162 }
163
164 void set_rollers_front(::std::unique_ptr<BufferedSolenoid> s) {
165 rollers_front_ = ::std::move(s);
166 }
167
168 void set_rollers_back(::std::unique_ptr<BufferedSolenoid> s) {
169 rollers_back_ = ::std::move(s);
170 }
171
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700172 void Loop(const int iterations) {
173 if (iterations != 1) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700174 AOS_LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700175 }
Brian Silverman5090c432016-01-02 14:44:26 -0800176
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700177 // Drivetrain
178 {
179 drivetrain_.Fetch();
180 if (drivetrain_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700181 drivetrain_left_->Set(drivetrain_->left_high());
182 drivetrain_right_->Set(drivetrain_->right_high());
Comran Morshed41ed7c22015-11-04 21:03:37 +0000183 }
184 }
Comran Morshed41ed7c22015-11-04 21:03:37 +0000185
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700186 // Intake
187 {
188 rollers_.Fetch();
189 if (rollers_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700190 rollers_front_->Set(rollers_->front_extended());
191 rollers_back_->Set(rollers_->back_extended());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700192 }
193 }
194
195 // Compressor
196 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700197 auto builder = pneumatics_to_log_sender_.MakeBuilder();
198
199 ::frc971::wpilib::PneumaticsToLog::Builder to_log_builder =
200 builder.MakeBuilder<frc971::wpilib::PneumaticsToLog>();
201
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700202 {
203 // Refill if pneumatic pressure goes too low.
204 const bool compressor_on = !pressure_switch_->Get();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700205 to_log_builder.add_compressor_on(compressor_on);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700206 if (compressor_on) {
207 compressor_relay_->Set(::frc::Relay::kForward);
208 } else {
209 compressor_relay_->Set(::frc::Relay::kOff);
210 }
211 }
212
213 pcm_->Flush();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700214 to_log_builder.add_read_solenoids(pcm_->GetAll());
215 builder.Send(to_log_builder.Finish());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700216 }
217 }
Comran Morshed41ed7c22015-11-04 21:03:37 +0000218
219 private:
220 const ::std::unique_ptr<BufferedPcm> &pcm_;
221
222 ::std::unique_ptr<BufferedSolenoid> drivetrain_left_, drivetrain_right_;
223 ::std::unique_ptr<BufferedSolenoid> rollers_front_, rollers_back_;
224
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700225 ::std::unique_ptr<::frc::DigitalInput> pressure_switch_;
226 ::std::unique_ptr<::frc::Relay> compressor_relay_;
Comran Morshed41ed7c22015-11-04 21:03:37 +0000227
Alex Perrycb7da4b2019-08-28 19:35:56 -0700228 ::aos::Fetcher<::frc971::control_loops::drivetrain::Output> drivetrain_;
229 ::aos::Fetcher<::y2014_bot3::control_loops::rollers::Output> rollers_;
230 aos::Sender<::frc971::wpilib::PneumaticsToLog> pneumatics_to_log_sender_;
Comran Morshed41ed7c22015-11-04 21:03:37 +0000231};
232
Comran Morshed41ed7c22015-11-04 21:03:37 +0000233// Writes out rollers voltages.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700234class RollersWriter : public LoopOutputHandler<
Alex Perrycb7da4b2019-08-28 19:35:56 -0700235 ::y2014_bot3::control_loops::rollers::Output> {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000236 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800237 RollersWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700238 : ::frc971::wpilib::LoopOutputHandler<
Alex Perrycb7da4b2019-08-28 19:35:56 -0700239 ::y2014_bot3::control_loops::rollers::Output>(event_loop,
240 "/rollers") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800241
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700242 void set_rollers_front_intake_talon(::std::unique_ptr<::frc::Talon> t_left,
243 ::std::unique_ptr<::frc::Talon> t_right) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000244 rollers_front_left_intake_talon_ = ::std::move(t_left);
245 rollers_front_right_intake_talon_ = ::std::move(t_right);
246 }
247
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700248 void set_rollers_back_intake_talon(::std::unique_ptr<::frc::Talon> t_left,
249 ::std::unique_ptr<::frc::Talon> t_right) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000250 rollers_back_left_intake_talon_ = ::std::move(t_left);
251 rollers_back_right_intake_talon_ = ::std::move(t_right);
252 }
253
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700254 void set_rollers_low_goal_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000255 rollers_low_goal_talon_ = ::std::move(t);
256 }
257
258 private:
Alex Perrycb7da4b2019-08-28 19:35:56 -0700259 virtual void Write(const ::y2014_bot3::control_loops::rollers::Output
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700260 &output) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700261 rollers_front_left_intake_talon_->SetSpeed(output.front_intake_voltage() /
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800262 12.0);
263 rollers_front_right_intake_talon_->SetSpeed(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700264 -(output.front_intake_voltage() / 12.0));
265 rollers_back_left_intake_talon_->SetSpeed(output.back_intake_voltage() /
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800266 12.0);
267 rollers_back_right_intake_talon_->SetSpeed(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700268 -(output.back_intake_voltage() / 12.0));
269 rollers_low_goal_talon_->SetSpeed(output.low_goal_voltage() / 12.0);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000270 }
271
272 virtual void Stop() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700273 AOS_LOG(WARNING, "Intake output too old\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800274 rollers_front_left_intake_talon_->SetDisabled();
275 rollers_front_right_intake_talon_->SetDisabled();
276 rollers_back_left_intake_talon_->SetDisabled();
277 rollers_back_right_intake_talon_->SetDisabled();
278 rollers_low_goal_talon_->SetDisabled();
Comran Morshed41ed7c22015-11-04 21:03:37 +0000279 }
280
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700281 ::std::unique_ptr<::frc::Talon> rollers_front_left_intake_talon_,
Comran Morshed41ed7c22015-11-04 21:03:37 +0000282 rollers_back_left_intake_talon_, rollers_front_right_intake_talon_,
283 rollers_back_right_intake_talon_, rollers_low_goal_talon_;
284};
285
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800286class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000287 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700288 ::std::unique_ptr<::frc::Encoder> make_encoder(int index) {
289 return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false,
290 ::frc::Encoder::k4X);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000291 }
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800292 void Run() override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700293 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
294 aos::configuration::ReadConfig("config.json");
295
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700296 // Thread 1.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700297 ::aos::ShmEventLoop joystick_sender_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700298 ::frc971::wpilib::JoystickSender joystick_sender(
299 &joystick_sender_event_loop);
300 AddLoop(&joystick_sender_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000301
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700302 // Thread 2.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700303 ::aos::ShmEventLoop pdp_fetcher_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700304 ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop);
305 AddLoop(&pdp_fetcher_event_loop);
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800306
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700307 // Thread 3.
Comran Morshed41ed7c22015-11-04 21:03:37 +0000308 // Sensors
Alex Perrycb7da4b2019-08-28 19:35:56 -0700309 ::aos::ShmEventLoop sensor_reader_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700310 SensorReader sensor_reader(&sensor_reader_event_loop);
311 sensor_reader.set_drivetrain_left_encoder(make_encoder(4));
312 sensor_reader.set_drivetrain_right_encoder(make_encoder(5));
313 AddLoop(&sensor_reader_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000314
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700315 // Thread 4.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700316 ::aos::ShmEventLoop gyro_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700317 GyroSender gyro_sender(&gyro_event_loop);
318 AddLoop(&gyro_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000319
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700320 // Thread 5.
Comran Morshed41ed7c22015-11-04 21:03:37 +0000321 // Outputs
Alex Perrycb7da4b2019-08-28 19:35:56 -0700322 ::aos::ShmEventLoop output_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700323 ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop);
Sabina Davis5ba275b2019-02-03 01:18:04 -0800324 drivetrain_writer.set_left_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700325 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), true);
Sabina Davis5ba275b2019-02-03 01:18:04 -0800326 drivetrain_writer.set_right_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700327 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2)), false);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000328
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700329 RollersWriter rollers_writer(&output_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000330 rollers_writer.set_rollers_front_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700331 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3)),
332 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7)));
Comran Morshed41ed7c22015-11-04 21:03:37 +0000333 rollers_writer.set_rollers_back_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700334 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1)),
335 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6)));
Comran Morshed41ed7c22015-11-04 21:03:37 +0000336
337 rollers_writer.set_rollers_low_goal_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700338 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)));
339 AddLoop(&output_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000340
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700341 // Thread 6.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700342 ::aos::ShmEventLoop solenoid_writer_event_loop(&config.message());
Comran Morshed41ed7c22015-11-04 21:03:37 +0000343 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
344 new ::frc971::wpilib::BufferedPcm());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700345 SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000346 solenoid_writer.set_drivetrain_left(pcm->MakeSolenoid(6));
347 solenoid_writer.set_drivetrain_right(pcm->MakeSolenoid(5));
348 solenoid_writer.set_rollers_front(pcm->MakeSolenoid(2));
349 solenoid_writer.set_rollers_back(pcm->MakeSolenoid(4));
350
351 // Don't change the following IDs.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700352 solenoid_writer.set_pressure_switch(make_unique<::frc::DigitalInput>(9));
353 solenoid_writer.set_compressor_relay(make_unique<::frc::Relay>(0));
354 AddLoop(&solenoid_writer_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000355
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700356 RunLoops();
Comran Morshed41ed7c22015-11-04 21:03:37 +0000357 }
358};
359
360} // namespace wpilib
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800361} // namespace y2014_bot3
Comran Morshed41ed7c22015-11-04 21:03:37 +0000362
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800363AOS_ROBOT_CLASS(::y2014_bot3::wpilib::WPILibRobot);