blob: 5640e504088805034b66de6d7b8cd6cbc58994eb [file] [log] [blame]
Comran Morshed41ed7c22015-11-04 21:03:37 +00001#include <unistd.h>
Comran Morshed41ed7c22015-11-04 21:03:37 +00002
Austin Schuh8aec1ed2016-05-01 13:29:20 -07003#include <chrono>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cinttypes>
5#include <cstdio>
6#include <cstring>
Comran Morshed41ed7c22015-11-04 21:03:37 +00007#include <functional>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07008#include <memory>
Austin Schuh4d11f9a2019-02-02 16:30:06 -08009#include <mutex>
10#include <thread>
Comran Morshed41ed7c22015-11-04 21:03:37 +000011
Parker Schuhd3b7a8872018-02-19 16:42:27 -080012#include "frc971/wpilib/ahal/AnalogInput.h"
13#include "frc971/wpilib/ahal/Compressor.h"
14#include "frc971/wpilib/ahal/DigitalInput.h"
15#include "frc971/wpilib/ahal/DriverStation.h"
16#include "frc971/wpilib/ahal/Encoder.h"
17#include "frc971/wpilib/ahal/Relay.h"
18#include "frc971/wpilib/ahal/Talon.h"
Campbell Crowleyc0cfb132015-12-30 20:58:02 -080019#include "frc971/wpilib/wpilib_robot_base.h"
Austin Schuhbc9a2ab2015-11-26 16:20:17 -080020#undef ERROR
Comran Morshed41ed7c22015-11-04 21:03:37 +000021
Alex Perrycb7da4b2019-08-28 19:35:56 -070022#include "aos/events/shm_event_loop.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080023#include "aos/init.h"
John Park33858a32018-09-28 23:05:48 -070024#include "aos/logging/logging.h"
Brian Silvermanf819b442019-01-20 16:51:04 -080025#include "aos/stl_mutex/stl_mutex.h"
John Park33858a32018-09-28 23:05:48 -070026#include "aos/time/time.h"
27#include "aos/util/log_interval.h"
28#include "aos/util/phased_loop.h"
29#include "aos/util/wrapping_counter.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070030#include "frc971/control_loops/drivetrain/drivetrain_output_generated.h"
31#include "frc971/control_loops/drivetrain/drivetrain_position_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -070032#include "frc971/input/robot_state_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;
Comran Morshed41ed7c22015-11-04 21:03:37 +000055using ::frc971::wpilib::GyroSender;
James Kuszmaul7077d342021-06-09 20:23:58 -070056using ::frc971::wpilib::JoystickSender;
57using ::frc971::wpilib::LoopOutputHandler;
Tyler Chatowbf0609c2021-07-31 16:13:27 -070058using std::make_unique;
Comran Morshed41ed7c22015-11-04 21:03:37 +000059
Stephan Pleinesf63bde82024-01-13 15:59:33 -080060namespace y2014_bot3::wpilib {
Comran Morshed41ed7c22015-11-04 21:03:37 +000061
62double drivetrain_translate(int32_t in) {
63 return static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) *
Adam Snaider83eae562016-09-10 16:47:33 -070064 ::y2014_bot3::control_loops::drivetrain::kDrivetrainEncoderRatio *
Comran Morshed41ed7c22015-11-04 21:03:37 +000065 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
66}
67
Brian Silverman51091a02015-12-26 15:56:58 -080068double drivetrain_velocity_translate(double in) {
69 return (1.0 / in) / 256.0 /*cpr*/ *
Adam Snaider83eae562016-09-10 16:47:33 -070070 ::y2014_bot3::control_loops::drivetrain::kDrivetrainEncoderRatio *
Brian Silverman51091a02015-12-26 15:56:58 -080071 (4 /*wheel diameter*/ * 2.54 / 100.0 * M_PI);
72}
73
Comran Morshed41ed7c22015-11-04 21:03:37 +000074// Reads in our inputs. (sensors, voltages, etc.)
Austin Schuh4d11f9a2019-02-02 16:30:06 -080075class SensorReader : public ::frc971::wpilib::SensorReader {
Comran Morshed41ed7c22015-11-04 21:03:37 +000076 public:
Austin Schuh217a9782019-12-21 23:02:50 -080077 SensorReader(::aos::ShmEventLoop *event_loop)
Austin Schuh30020d92019-05-27 13:07:02 -070078 : ::frc971::wpilib::SensorReader(event_loop),
79 rollers_position_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -070080 event_loop
81 ->MakeSender<::y2014_bot3::control_loops::rollers::Position>(
82 "/rollers")),
Austin Schuhbd0a40f2019-06-30 14:56:31 -070083 drivetrain_position_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -070084 event_loop
85 ->MakeSender<::frc971::control_loops::drivetrain::Position>(
86 "/drivetrain")) {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -080087
Comran Morshed41ed7c22015-11-04 21:03:37 +000088 void RunIteration() {
Comran Morshed41ed7c22015-11-04 21:03:37 +000089 // Drivetrain
90 {
Alex Perrycb7da4b2019-08-28 19:35:56 -070091 auto builder = drivetrain_position_sender_.MakeBuilder();
Comran Morshed41ed7c22015-11-04 21:03:37 +000092
Alex Perrycb7da4b2019-08-28 19:35:56 -070093 frc971::control_loops::drivetrain::Position::Builder position_builder =
94 builder.MakeBuilder<frc971::control_loops::drivetrain::Position>();
95 position_builder.add_right_encoder(
96 -drivetrain_translate(drivetrain_right_encoder_->GetRaw()));
97 position_builder.add_left_encoder(
98 drivetrain_translate(drivetrain_left_encoder_->GetRaw()));
99 position_builder.add_left_speed(
100 drivetrain_velocity_translate(drivetrain_left_encoder_->GetPeriod()));
101 position_builder.add_right_speed(drivetrain_velocity_translate(
102 drivetrain_right_encoder_->GetPeriod()));
103
milind1f1dca32021-07-03 13:50:07 -0700104 builder.CheckOk(builder.Send(position_builder.Finish()));
Comran Morshed41ed7c22015-11-04 21:03:37 +0000105 }
106
107 // Rollers
108 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700109 auto builder = rollers_position_sender_.MakeBuilder();
milind1f1dca32021-07-03 13:50:07 -0700110 builder.CheckOk(builder.Send(
111 builder.MakeBuilder<control_loops::rollers::Position>().Finish()));
Comran Morshed41ed7c22015-11-04 21:03:37 +0000112 }
113 }
Austin Schuh30020d92019-05-27 13:07:02 -0700114
115 private:
Alex Perrycb7da4b2019-08-28 19:35:56 -0700116 ::aos::Sender<::y2014_bot3::control_loops::rollers::Position>
Austin Schuh30020d92019-05-27 13:07:02 -0700117 rollers_position_sender_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700118 ::aos::Sender<::frc971::control_loops::drivetrain::Position>
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700119 drivetrain_position_sender_;
Comran Morshed41ed7c22015-11-04 21:03:37 +0000120};
121
122// Writes out our pneumatic outputs.
123class SolenoidWriter {
124 public:
Austin Schuh217a9782019-12-21 23:02:50 -0800125 SolenoidWriter(::aos::ShmEventLoop *event_loop,
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700126 const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm)
Comran Morshed41ed7c22015-11-04 21:03:37 +0000127 : pcm_(pcm),
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700128 drivetrain_(
129 event_loop
Alex Perrycb7da4b2019-08-28 19:35:56 -0700130 ->MakeFetcher<::frc971::control_loops::drivetrain::Output>(
131 "/drivetrain")),
132 rollers_(
133 event_loop
134 ->MakeFetcher<::y2014_bot3::control_loops::rollers::Output>(
135 "/rollers")),
136 pneumatics_to_log_sender_(
137 event_loop->MakeSender<::frc971::wpilib::PneumaticsToLog>("/aos")) {
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700138 event_loop->set_name("Solenoids");
139 event_loop->SetRuntimeRealtimePriority(27);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000140
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700141 event_loop->AddPhasedLoop([this](int iterations) { Loop(iterations); },
142 ::std::chrono::milliseconds(20),
143 ::std::chrono::milliseconds(1));
144 }
145
146 void set_pressure_switch(
147 ::std::unique_ptr<::frc::DigitalInput> pressure_switch) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000148 pressure_switch_ = ::std::move(pressure_switch);
149 }
150
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700151 void set_compressor_relay(::std::unique_ptr<::frc::Relay> compressor_relay) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000152 compressor_relay_ = ::std::move(compressor_relay);
153 }
154
155 void set_drivetrain_left(::std::unique_ptr<BufferedSolenoid> s) {
156 drivetrain_left_ = ::std::move(s);
157 }
158
159 void set_drivetrain_right(::std::unique_ptr<BufferedSolenoid> s) {
160 drivetrain_right_ = ::std::move(s);
161 }
162
163 void set_rollers_front(::std::unique_ptr<BufferedSolenoid> s) {
164 rollers_front_ = ::std::move(s);
165 }
166
167 void set_rollers_back(::std::unique_ptr<BufferedSolenoid> s) {
168 rollers_back_ = ::std::move(s);
169 }
170
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700171 void Loop(const int iterations) {
172 if (iterations != 1) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700173 AOS_LOG(DEBUG, "Solenoids skipped %d iterations\n", iterations - 1);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700174 }
Brian Silverman5090c432016-01-02 14:44:26 -0800175
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700176 // Drivetrain
177 {
178 drivetrain_.Fetch();
179 if (drivetrain_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700180 drivetrain_left_->Set(drivetrain_->left_high());
181 drivetrain_right_->Set(drivetrain_->right_high());
Comran Morshed41ed7c22015-11-04 21:03:37 +0000182 }
183 }
Comran Morshed41ed7c22015-11-04 21:03:37 +0000184
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700185 // Intake
186 {
187 rollers_.Fetch();
188 if (rollers_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700189 rollers_front_->Set(rollers_->front_extended());
190 rollers_back_->Set(rollers_->back_extended());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700191 }
192 }
193
194 // Compressor
195 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700196 auto builder = pneumatics_to_log_sender_.MakeBuilder();
197
198 ::frc971::wpilib::PneumaticsToLog::Builder to_log_builder =
199 builder.MakeBuilder<frc971::wpilib::PneumaticsToLog>();
200
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700201 {
202 // Refill if pneumatic pressure goes too low.
203 const bool compressor_on = !pressure_switch_->Get();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700204 to_log_builder.add_compressor_on(compressor_on);
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700205 if (compressor_on) {
206 compressor_relay_->Set(::frc::Relay::kForward);
207 } else {
208 compressor_relay_->Set(::frc::Relay::kOff);
209 }
210 }
211
212 pcm_->Flush();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700213 to_log_builder.add_read_solenoids(pcm_->GetAll());
milind1f1dca32021-07-03 13:50:07 -0700214 builder.CheckOk(builder.Send(to_log_builder.Finish()));
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700215 }
216 }
Comran Morshed41ed7c22015-11-04 21:03:37 +0000217
218 private:
219 const ::std::unique_ptr<BufferedPcm> &pcm_;
220
221 ::std::unique_ptr<BufferedSolenoid> drivetrain_left_, drivetrain_right_;
222 ::std::unique_ptr<BufferedSolenoid> rollers_front_, rollers_back_;
223
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700224 ::std::unique_ptr<::frc::DigitalInput> pressure_switch_;
225 ::std::unique_ptr<::frc::Relay> compressor_relay_;
Comran Morshed41ed7c22015-11-04 21:03:37 +0000226
Alex Perrycb7da4b2019-08-28 19:35:56 -0700227 ::aos::Fetcher<::frc971::control_loops::drivetrain::Output> drivetrain_;
228 ::aos::Fetcher<::y2014_bot3::control_loops::rollers::Output> rollers_;
229 aos::Sender<::frc971::wpilib::PneumaticsToLog> pneumatics_to_log_sender_;
Comran Morshed41ed7c22015-11-04 21:03:37 +0000230};
231
Comran Morshed41ed7c22015-11-04 21:03:37 +0000232// Writes out rollers voltages.
James Kuszmaul7077d342021-06-09 20:23:58 -0700233class RollersWriter
234 : public LoopOutputHandler<::y2014_bot3::control_loops::rollers::Output> {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000235 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800236 RollersWriter(::aos::EventLoop *event_loop)
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700237 : ::frc971::wpilib::LoopOutputHandler<
Alex Perrycb7da4b2019-08-28 19:35:56 -0700238 ::y2014_bot3::control_loops::rollers::Output>(event_loop,
239 "/rollers") {}
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800240
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700241 void set_rollers_front_intake_talon(::std::unique_ptr<::frc::Talon> t_left,
242 ::std::unique_ptr<::frc::Talon> t_right) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000243 rollers_front_left_intake_talon_ = ::std::move(t_left);
244 rollers_front_right_intake_talon_ = ::std::move(t_right);
245 }
246
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700247 void set_rollers_back_intake_talon(::std::unique_ptr<::frc::Talon> t_left,
248 ::std::unique_ptr<::frc::Talon> t_right) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000249 rollers_back_left_intake_talon_ = ::std::move(t_left);
250 rollers_back_right_intake_talon_ = ::std::move(t_right);
251 }
252
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700253 void set_rollers_low_goal_talon(::std::unique_ptr<::frc::Talon> t) {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000254 rollers_low_goal_talon_ = ::std::move(t);
255 }
256
257 private:
James Kuszmaul7077d342021-06-09 20:23:58 -0700258 virtual void Write(
259 const ::y2014_bot3::control_loops::rollers::Output &output) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700260 rollers_front_left_intake_talon_->SetSpeed(output.front_intake_voltage() /
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800261 12.0);
262 rollers_front_right_intake_talon_->SetSpeed(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700263 -(output.front_intake_voltage() / 12.0));
264 rollers_back_left_intake_talon_->SetSpeed(output.back_intake_voltage() /
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800265 12.0);
266 rollers_back_right_intake_talon_->SetSpeed(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700267 -(output.back_intake_voltage() / 12.0));
268 rollers_low_goal_talon_->SetSpeed(output.low_goal_voltage() / 12.0);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000269 }
270
271 virtual void Stop() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700272 AOS_LOG(WARNING, "Intake output too old\n");
Brian Silverman6eaa2d82017-02-04 20:48:30 -0800273 rollers_front_left_intake_talon_->SetDisabled();
274 rollers_front_right_intake_talon_->SetDisabled();
275 rollers_back_left_intake_talon_->SetDisabled();
276 rollers_back_right_intake_talon_->SetDisabled();
277 rollers_low_goal_talon_->SetDisabled();
Comran Morshed41ed7c22015-11-04 21:03:37 +0000278 }
279
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700280 ::std::unique_ptr<::frc::Talon> rollers_front_left_intake_talon_,
Comran Morshed41ed7c22015-11-04 21:03:37 +0000281 rollers_back_left_intake_talon_, rollers_front_right_intake_talon_,
282 rollers_back_right_intake_talon_, rollers_low_goal_talon_;
283};
284
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800285class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
Comran Morshed41ed7c22015-11-04 21:03:37 +0000286 public:
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700287 ::std::unique_ptr<::frc::Encoder> make_encoder(int index) {
288 return make_unique<::frc::Encoder>(10 + index * 2, 11 + index * 2, false,
289 ::frc::Encoder::k4X);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000290 }
Campbell Crowleyc0cfb132015-12-30 20:58:02 -0800291 void Run() override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700292 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800293 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700294
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700295 // Thread 1.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700296 ::aos::ShmEventLoop joystick_sender_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700297 ::frc971::wpilib::JoystickSender joystick_sender(
298 &joystick_sender_event_loop);
299 AddLoop(&joystick_sender_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000300
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700301 // Thread 2.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700302 ::aos::ShmEventLoop pdp_fetcher_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700303 ::frc971::wpilib::PDPFetcher pdp_fetcher(&pdp_fetcher_event_loop);
304 AddLoop(&pdp_fetcher_event_loop);
Austin Schuhdf6cbb12019-02-02 13:46:52 -0800305
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700306 // Thread 3.
Comran Morshed41ed7c22015-11-04 21:03:37 +0000307 // Sensors
Alex Perrycb7da4b2019-08-28 19:35:56 -0700308 ::aos::ShmEventLoop sensor_reader_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700309 SensorReader sensor_reader(&sensor_reader_event_loop);
310 sensor_reader.set_drivetrain_left_encoder(make_encoder(4));
311 sensor_reader.set_drivetrain_right_encoder(make_encoder(5));
312 AddLoop(&sensor_reader_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000313
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700314 // Thread 4.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700315 ::aos::ShmEventLoop gyro_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700316 GyroSender gyro_sender(&gyro_event_loop);
317 AddLoop(&gyro_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000318
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700319 // Thread 5.
Comran Morshed41ed7c22015-11-04 21:03:37 +0000320 // Outputs
Alex Perrycb7da4b2019-08-28 19:35:56 -0700321 ::aos::ShmEventLoop output_event_loop(&config.message());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700322 ::frc971::wpilib::DrivetrainWriter drivetrain_writer(&output_event_loop);
Sabina Davis5ba275b2019-02-03 01:18:04 -0800323 drivetrain_writer.set_left_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700324 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(5)), true);
Sabina Davis5ba275b2019-02-03 01:18:04 -0800325 drivetrain_writer.set_right_controller0(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700326 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(2)), false);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000327
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700328 RollersWriter rollers_writer(&output_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000329 rollers_writer.set_rollers_front_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700330 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(3)),
331 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(7)));
Comran Morshed41ed7c22015-11-04 21:03:37 +0000332 rollers_writer.set_rollers_back_intake_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700333 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(1)),
334 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(6)));
Comran Morshed41ed7c22015-11-04 21:03:37 +0000335
336 rollers_writer.set_rollers_low_goal_talon(
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700337 ::std::unique_ptr<::frc::Talon>(new ::frc::Talon(4)));
338 AddLoop(&output_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000339
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700340 // Thread 6.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700341 ::aos::ShmEventLoop solenoid_writer_event_loop(&config.message());
Comran Morshed41ed7c22015-11-04 21:03:37 +0000342 ::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
343 new ::frc971::wpilib::BufferedPcm());
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700344 SolenoidWriter solenoid_writer(&solenoid_writer_event_loop, pcm);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000345 solenoid_writer.set_drivetrain_left(pcm->MakeSolenoid(6));
346 solenoid_writer.set_drivetrain_right(pcm->MakeSolenoid(5));
347 solenoid_writer.set_rollers_front(pcm->MakeSolenoid(2));
348 solenoid_writer.set_rollers_back(pcm->MakeSolenoid(4));
349
350 // Don't change the following IDs.
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700351 solenoid_writer.set_pressure_switch(make_unique<::frc::DigitalInput>(9));
352 solenoid_writer.set_compressor_relay(make_unique<::frc::Relay>(0));
353 AddLoop(&solenoid_writer_event_loop);
Comran Morshed41ed7c22015-11-04 21:03:37 +0000354
Austin Schuhbd1fe9c2019-06-29 16:35:48 -0700355 RunLoops();
Comran Morshed41ed7c22015-11-04 21:03:37 +0000356 }
357};
358
Stephan Pleinesf63bde82024-01-13 15:59:33 -0800359} // namespace y2014_bot3::wpilib
Comran Morshed41ed7c22015-11-04 21:03:37 +0000360
Austin Schuh4d11f9a2019-02-02 16:30:06 -0800361AOS_ROBOT_CLASS(::y2014_bot3::wpilib::WPILibRobot);