blob: 173e6ef058752f5fc2c0008c68ef70a56919af0b [file] [log] [blame]
Neil Balchacfca5b2018-01-28 14:04:08 -08001#include <math.h>
2#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
Austin Schuh8d5fff42018-05-30 20:44:12 -07005#include <mutex>
Neil Balchacfca5b2018-01-28 14:04:08 -08006
7#include "aos/common/actions/actions.h"
8#include "aos/common/input/driver_station_data.h"
9#include "aos/common/logging/logging.h"
Austin Schuh8d5fff42018-05-30 20:44:12 -070010#include "aos/common/stl_mutex.h"
Neil Balchacfca5b2018-01-28 14:04:08 -080011#include "aos/common/time.h"
12#include "aos/common/util/log_interval.h"
13#include "aos/input/drivetrain_input.h"
14#include "aos/input/joystick_input.h"
15#include "aos/linux_code/init.h"
Austin Schuh8d5fff42018-05-30 20:44:12 -070016#include "aos/vision/events/udp.h"
Austin Schuha3c148e2018-03-09 21:04:05 -080017#include "frc971/autonomous/auto.q.h"
18#include "frc971/autonomous/base_autonomous_actor.h"
Neil Balchacfca5b2018-01-28 14:04:08 -080019#include "frc971/control_loops/drivetrain/drivetrain.q.h"
20#include "y2018/control_loops/drivetrain/drivetrain_base.h"
Austin Schuhab15c4d2018-03-09 21:21:03 -080021#include "y2018/control_loops/superstructure/arm/generated_graph.h"
Neil Balch07fee582018-01-27 15:46:49 -080022#include "y2018/control_loops/superstructure/superstructure.q.h"
Austin Schuh8d5fff42018-05-30 20:44:12 -070023#include "y2018/vision.pb.h"
Neil Balchacfca5b2018-01-28 14:04:08 -080024
Austin Schuh8d5fff42018-05-30 20:44:12 -070025using ::aos::monotonic_clock;
Neil Balchacfca5b2018-01-28 14:04:08 -080026using ::frc971::control_loops::drivetrain_queue;
Neil Balch07fee582018-01-27 15:46:49 -080027using ::y2018::control_loops::superstructure_queue;
Austin Schuh8d5fff42018-05-30 20:44:12 -070028using ::aos::events::ProtoTXUdpSocket;
29using ::aos::events::RXUdpSocket;
Neil Balchacfca5b2018-01-28 14:04:08 -080030using ::aos::input::driver_station::ButtonLocation;
31using ::aos::input::driver_station::ControlBit;
32using ::aos::input::driver_station::JoystickAxis;
33using ::aos::input::driver_station::POVLocation;
34using ::aos::input::DrivetrainInputReader;
35
Austin Schuh60cdb3e2018-04-06 21:52:32 -070036using ::y2018::control_loops::superstructure::arm::FrontPoints;
37using ::y2018::control_loops::superstructure::arm::BackPoints;
38
Neil Balchacfca5b2018-01-28 14:04:08 -080039namespace y2018 {
40namespace input {
41namespace joysticks {
42
Austin Schuhab15c4d2018-03-09 21:21:03 -080043namespace arm = ::y2018::control_loops::superstructure::arm;
Neil Balch07fee582018-01-27 15:46:49 -080044
Sabina Davis833ccf62018-04-06 20:52:31 -070045const ButtonLocation kIntakeClosed(3, 2);
46const ButtonLocation kDuck(3, 9);
47const ButtonLocation kSmallBox(3, 1);
Austin Schuh47d74942018-03-04 01:15:59 -080048
Sabina Davis833ccf62018-04-06 20:52:31 -070049const ButtonLocation kIntakeIn(3, 4);
50const ButtonLocation kIntakeOut(3, 3);
Neil Balch07fee582018-01-27 15:46:49 -080051
Sabina Davis833ccf62018-04-06 20:52:31 -070052const ButtonLocation kArmFrontHighBox(4, 11);
53const ButtonLocation kArmFrontExtraHighBox(4, 1);
54const ButtonLocation kArmFrontMiddle2Box(4, 9);
55const ButtonLocation kArmFrontMiddle1Box(4, 7);
56const ButtonLocation kArmFrontLowBox(4, 5);
57const ButtonLocation kArmFrontSwitch(3, 7);
Austin Schuhab15c4d2018-03-09 21:21:03 -080058
Sabina Davis833ccf62018-04-06 20:52:31 -070059const ButtonLocation kArmBackHighBox(4, 12);
60const ButtonLocation kArmBackExtraHighBox(3, 14);
61const ButtonLocation kArmBackMiddle2Box(4, 10);
62const ButtonLocation kArmBackMiddle1Box(4, 8);
63const ButtonLocation kArmBackLowBox(4, 6);
64const ButtonLocation kArmBackSwitch(3, 10);
Austin Schuhab15c4d2018-03-09 21:21:03 -080065
Sabina Davis833ccf62018-04-06 20:52:31 -070066const ButtonLocation kArmAboveHang(3, 15);
67const ButtonLocation kArmBelowHang(3, 16);
Austin Schuh17e484e2018-03-11 01:11:36 -080068
Austin Schuhd76546a2018-07-08 16:05:14 -070069const ButtonLocation kEmergencyUp(3, 5);
70const ButtonLocation kEmergencyDown(3, 6);
71
Sabina Davis833ccf62018-04-06 20:52:31 -070072const ButtonLocation kWinch(4, 2);
Austin Schuh17e484e2018-03-11 01:11:36 -080073
Sabina Davis833ccf62018-04-06 20:52:31 -070074const ButtonLocation kArmNeutral(3, 8);
75const ButtonLocation kArmUp(3, 11);
Austin Schuhab15c4d2018-03-09 21:21:03 -080076
Sabina Davis833ccf62018-04-06 20:52:31 -070077const ButtonLocation kArmStepUp(3, 13);
78const ButtonLocation kArmStepDown(3, 12);
Austin Schuhab15c4d2018-03-09 21:21:03 -080079
Sabina Davis833ccf62018-04-06 20:52:31 -070080const ButtonLocation kArmPickupBoxFromIntake(4, 3);
81
82const ButtonLocation kClawOpen(4, 4);
Neil Balchba9cbba2018-04-06 22:26:38 -070083const ButtonLocation kDriverClawOpen(2, 4);
Neil Balch07fee582018-01-27 15:46:49 -080084
Neil Balchacfca5b2018-01-28 14:04:08 -080085std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_;
86
87class Reader : public ::aos::input::JoystickInput {
88 public:
Austin Schuh8d5fff42018-05-30 20:44:12 -070089 Reader() : video_tx_("10.9.71.179", 5000) {
Neil Balchacfca5b2018-01-28 14:04:08 -080090 drivetrain_input_reader_ = DrivetrainInputReader::Make(
Austin Schuh2b1fce02018-03-02 20:05:20 -080091 DrivetrainInputReader::InputType::kPistol,
Neil Balchacfca5b2018-01-28 14:04:08 -080092 ::y2018::control_loops::drivetrain::GetDrivetrainConfig());
93 }
94
95 void RunIteration(const ::aos::input::driver_station::Data &data) override {
96 bool last_auto_running = auto_running_;
97 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
98 data.GetControlBit(ControlBit::kEnabled);
99 if (auto_running_ != last_auto_running) {
100 if (auto_running_) {
101 StartAuto();
102 } else {
103 StopAuto();
104 }
105 }
106
107 if (!auto_running_) {
108 HandleDrivetrain(data);
109 HandleTeleop(data);
110 }
111
112 // Process any pending actions.
113 action_queue_.Tick();
114 was_running_ = action_queue_.Running();
115 }
116
117 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
118 drivetrain_input_reader_->HandleDrivetrain(data);
Neil Balchacfca5b2018-01-28 14:04:08 -0800119 }
120
121 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
122 if (!data.GetControlBit(ControlBit::kEnabled)) {
123 action_queue_.CancelAllActions();
124 LOG(DEBUG, "Canceling\n");
125 }
Neil Balch07fee582018-01-27 15:46:49 -0800126
Austin Schuhab15c4d2018-03-09 21:21:03 -0800127 superstructure_queue.position.FetchLatest();
Neil Balch07fee582018-01-27 15:46:49 -0800128 superstructure_queue.status.FetchLatest();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800129 if (!superstructure_queue.status.get() ||
130 !superstructure_queue.position.get()) {
Neil Balch07fee582018-01-27 15:46:49 -0800131 LOG(ERROR, "Got no superstructure status packet.\n");
132 return;
133 }
134
Neil Balch07fee582018-01-27 15:46:49 -0800135 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
136
Sabina Davisfdd7a112018-02-04 16:16:23 -0800137 new_superstructure_goal->intake.left_intake_angle = intake_goal_;
138 new_superstructure_goal->intake.right_intake_angle = intake_goal_;
Neil Balch07fee582018-01-27 15:46:49 -0800139
Austin Schuh8d5fff42018-05-30 20:44:12 -0700140 if (data.PosEdge(kIntakeIn) || data.PosEdge(kSmallBox) ||
141 data.PosEdge(kIntakeClosed)) {
142 vision_control_.set_high_video(false);
143 }
144
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700145 if (data.IsPressed(kIntakeIn)) {
Neil Balch07fee582018-01-27 15:46:49 -0800146 // Turn on the rollers.
Neil Balchba9cbba2018-04-06 22:26:38 -0700147 new_superstructure_goal->intake.roller_voltage = 8.0;
Neil Balch07fee582018-01-27 15:46:49 -0800148 } else if (data.IsPressed(kIntakeOut)) {
149 // Turn off the rollers.
Austin Schuh17dd0892018-03-02 20:06:31 -0800150 new_superstructure_goal->intake.roller_voltage = -12.0;
Neil Balch07fee582018-01-27 15:46:49 -0800151 } else {
152 // We don't want the rollers on.
153 new_superstructure_goal->intake.roller_voltage = 0.0;
154 }
155
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700156 if (data.IsPressed(kSmallBox)) {
157 // Deploy the intake.
158 if (superstructure_queue.position->box_back_beambreak_triggered) {
159 intake_goal_ = 0.30;
160 } else {
161 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
162 superstructure_queue.position->box_distance < 0.15) {
163 intake_goal_ = 0.18;
164 } else {
165 intake_goal_ = -0.60;
166 }
167 }
168 } else if (data.IsPressed(kIntakeClosed)) {
169 // Deploy the intake.
170 if (superstructure_queue.position->box_back_beambreak_triggered) {
171 intake_goal_ = 0.30;
172 } else {
173 if (new_superstructure_goal->intake.roller_voltage > 0.1) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700174 if (superstructure_queue.position->box_distance < 0.10) {
175 new_superstructure_goal->intake.roller_voltage -= 3.0;
176 intake_goal_ = 0.22;
177 } else if (superstructure_queue.position->box_distance < 0.17) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700178 intake_goal_ = 0.13;
179 } else if (superstructure_queue.position->box_distance < 0.25) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700180 intake_goal_ = 0.05;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700181 } else {
Neil Balchba9cbba2018-04-06 22:26:38 -0700182 intake_goal_ = -0.10;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700183 }
Austin Schuhcf96d322018-04-07 15:52:31 -0700184 if (drivetrain_input_reader_->robot_velocity() < -0.1 &&
185 superstructure_queue.position->box_distance > 0.15) {
186 intake_goal_ += 0.10;
187 }
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700188 } else {
189 intake_goal_ = -0.60;
190 }
191 }
192 } else {
193 // Bring in the intake.
Austin Schuhcf96d322018-04-07 15:52:31 -0700194 intake_goal_ = -3.20;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700195 }
196
Neil Balchba9cbba2018-04-06 22:26:38 -0700197 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
198 intake_goal_ > 0.0) {
199 if (superstructure_queue.position->box_distance < 0.10) {
200 new_superstructure_goal->intake.roller_voltage -= 3.0;
201 }
202 new_superstructure_goal->intake.roller_voltage += 3.0;
203 }
204
Austin Schuhb874fd32018-03-05 00:27:10 -0800205 // If we are disabled, stay at the node closest to where we start. This
206 // should remove long motions when enabled.
Neil Balchba9cbba2018-04-06 22:26:38 -0700207 if (!data.GetControlBit(ControlBit::kEnabled) || never_disabled_) {
Austin Schuhb874fd32018-03-05 00:27:10 -0800208 arm_goal_position_ = superstructure_queue.status->arm.current_node;
Neil Balchba9cbba2018-04-06 22:26:38 -0700209 never_disabled_ = false;
Austin Schuhb874fd32018-03-05 00:27:10 -0800210 }
211
Austin Schuhab15c4d2018-03-09 21:21:03 -0800212 bool grab_box = false;
213 if (data.IsPressed(kArmPickupBoxFromIntake)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800214 grab_box = true;
Neil Balchba9cbba2018-04-06 22:26:38 -0700215 }
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700216 const bool near_goal =
217 superstructure_queue.status->arm.current_node == arm_goal_position_ &&
218 superstructure_queue.status->arm.path_distance_to_go < 1e-3;
Austin Schuh822a1e52018-04-06 22:50:21 -0700219 if (data.IsPressed(kArmStepDown) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700220 uint32_t *front_point = ::std::find(
221 front_points_.begin(), front_points_.end(), arm_goal_position_);
222 uint32_t *back_point = ::std::find(
223 back_points_.begin(), back_points_.end(), arm_goal_position_);
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700224 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700225 ++front_point;
226 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700227 arm_goal_position_ = *front_point;
228 }
229 } else if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700230 ++back_point;
231 if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700232 arm_goal_position_ = *back_point;
233 }
234 }
Austin Schuh822a1e52018-04-06 22:50:21 -0700235 } else if (data.IsPressed(kArmStepUp) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700236 const uint32_t *front_point = ::std::find(
237 front_points_.begin(), front_points_.end(), arm_goal_position_);
238 const uint32_t *back_point = ::std::find(
239 back_points_.begin(), back_points_.end(), arm_goal_position_);
240 if (front_point != front_points_.end()) {
241 if (front_point != front_points_.begin()) {
242 --front_point;
243 arm_goal_position_ = *front_point;
244 }
245 } else if (back_point != back_points_.end()) {
246 if (back_point != back_points_.begin()) {
247 --back_point;
248 arm_goal_position_ = *back_point;
249 }
250 }
251 } else if (data.PosEdge(kArmPickupBoxFromIntake)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700252 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700253 arm_goal_position_ = arm::NeutralIndex();
254 } else if (data.IsPressed(kDuck)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700255 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700256 arm_goal_position_ = arm::DuckIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800257 } else if (data.IsPressed(kArmNeutral)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700258 vision_control_.set_high_video(false);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800259 arm_goal_position_ = arm::NeutralIndex();
260 } else if (data.IsPressed(kArmUp)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700261 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800262 arm_goal_position_ = arm::UpIndex();
263 } else if (data.IsPressed(kArmFrontSwitch)) {
264 arm_goal_position_ = arm::FrontSwitchIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700265 } else if (data.IsPressed(kArmFrontExtraHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700266 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800267 arm_goal_position_ = arm::FrontHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700268 } else if (data.IsPressed(kArmFrontHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700269 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800270 arm_goal_position_ = arm::FrontMiddle2BoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700271 } else if (data.IsPressed(kArmFrontMiddle2Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700272 vision_control_.set_high_video(true);
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700273 arm_goal_position_ = arm::FrontMiddle3BoxIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800274 } else if (data.IsPressed(kArmFrontMiddle1Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700275 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800276 arm_goal_position_ = arm::FrontMiddle1BoxIndex();
277 } else if (data.IsPressed(kArmFrontLowBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700278 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800279 arm_goal_position_ = arm::FrontLowBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700280 } else if (data.IsPressed(kArmBackExtraHighBox)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800281 arm_goal_position_ = arm::BackHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700282 } else if (data.IsPressed(kArmBackHighBox) ||
283 data.IsPressed(kArmBackMiddle2Box)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800284 arm_goal_position_ = arm::BackMiddle2BoxIndex();
285 } else if (data.IsPressed(kArmBackMiddle1Box)) {
286 arm_goal_position_ = arm::BackMiddle1BoxIndex();
287 } else if (data.IsPressed(kArmBackLowBox)) {
288 arm_goal_position_ = arm::BackLowBoxIndex();
289 } else if (data.IsPressed(kArmBackSwitch)) {
290 arm_goal_position_ = arm::BackSwitchIndex();
Austin Schuh17e484e2018-03-11 01:11:36 -0800291 } else if (data.IsPressed(kArmAboveHang)) {
292 if (data.IsPressed(kIntakeIn)) {
293 arm_goal_position_ = arm::SelfHangIndex();
294 } else if (data.IsPressed(kIntakeOut)) {
295 arm_goal_position_ = arm::PartnerHangIndex();
296 } else {
297 arm_goal_position_ = arm::AboveHangIndex();
298 }
299 } else if (data.IsPressed(kArmBelowHang)) {
300 arm_goal_position_ = arm::BelowHangIndex();
Neil Balch07fee582018-01-27 15:46:49 -0800301 }
302
Austin Schuhd76546a2018-07-08 16:05:14 -0700303 if (data.IsPressed(kEmergencyDown)) {
304 arm_goal_position_ = arm::NeutralIndex();
305 new_superstructure_goal->trajectory_override = true;
306 } else if (data.IsPressed(kEmergencyUp)) {
307 arm_goal_position_ = arm::UpIndex();
308 new_superstructure_goal->trajectory_override = true;
309 } else {
310 new_superstructure_goal->trajectory_override = false;
311 }
312
Austin Schuh17e484e2018-03-11 01:11:36 -0800313 new_superstructure_goal->deploy_fork =
314 data.IsPressed(kArmAboveHang) && data.IsPressed(kClawOpen);
315
316 if (new_superstructure_goal->deploy_fork) {
317 intake_goal_ = -2.0;
318 }
319
320 if (data.IsPressed(kWinch)) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700321 LOG(INFO, "Winching\n");
Austin Schuh17e484e2018-03-11 01:11:36 -0800322 new_superstructure_goal->voltage_winch = 12.0;
323 } else {
324 new_superstructure_goal->voltage_winch = 0.0;
325 }
326
327 new_superstructure_goal->hook_release = data.IsPressed(kArmBelowHang);
328
Austin Schuhcb091712018-02-21 20:01:55 -0800329 new_superstructure_goal->arm_goal_position = arm_goal_position_;
Austin Schuhd76546a2018-07-08 16:05:14 -0700330 if (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)) {
331 new_superstructure_goal->open_threshold = 0.35;
332 } else {
333 new_superstructure_goal->open_threshold = 0.0;
334 }
Austin Schuhcb091712018-02-21 20:01:55 -0800335
Neil Balchba9cbba2018-04-06 22:26:38 -0700336 if ((data.IsPressed(kClawOpen) && data.IsPressed(kDriverClawOpen)) ||
Austin Schuhd76546a2018-07-08 16:05:14 -0700337 data.PosEdge(kArmPickupBoxFromIntake) ||
338 (data.IsPressed(kClawOpen) &&
339 (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)))) {
Neil Balch07fee582018-01-27 15:46:49 -0800340 new_superstructure_goal->open_claw = true;
Austin Schuhab15c4d2018-03-09 21:21:03 -0800341 } else {
Neil Balch07fee582018-01-27 15:46:49 -0800342 new_superstructure_goal->open_claw = false;
343 }
344
Austin Schuhab15c4d2018-03-09 21:21:03 -0800345 new_superstructure_goal->grab_box = grab_box;
Neil Balch07fee582018-01-27 15:46:49 -0800346
347 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
348 if (!new_superstructure_goal.Send()) {
349 LOG(ERROR, "Sending superstructure goal failed.\n");
350 }
Austin Schuh8d5fff42018-05-30 20:44:12 -0700351
352 video_tx_.Send(vision_control_);
Neil Balchacfca5b2018-01-28 14:04:08 -0800353 }
354
355 private:
Austin Schuha3c148e2018-03-09 21:04:05 -0800356 void StartAuto() {
357 LOG(INFO, "Starting auto mode\n");
358
359 ::frc971::autonomous::AutonomousActionParams params;
360 ::frc971::autonomous::auto_mode.FetchLatest();
361 if (::frc971::autonomous::auto_mode.get() != nullptr) {
Austin Schuhc231df42018-03-21 20:43:24 -0700362 params.mode = ::frc971::autonomous::auto_mode->mode << 2;
Austin Schuha3c148e2018-03-09 21:04:05 -0800363 } else {
364 LOG(WARNING, "no auto mode values\n");
365 params.mode = 0;
366 }
Austin Schuhc231df42018-03-21 20:43:24 -0700367 // TODO(austin): use the mode later if we care. We don't care right now.
368 params.mode = static_cast<int>(::aos::joystick_state->switch_left) |
369 (static_cast<int>(::aos::joystick_state->scale_left) << 1);
Austin Schuha3c148e2018-03-09 21:04:05 -0800370 action_queue_.EnqueueAction(
371 ::frc971::autonomous::MakeAutonomousAction(params));
372 }
Neil Balchacfca5b2018-01-28 14:04:08 -0800373
374 void StopAuto() {
375 LOG(INFO, "Stopping auto mode\n");
376 action_queue_.CancelAllActions();
377 }
378
Neil Balch07fee582018-01-27 15:46:49 -0800379 // Current goals to send to the robot.
Austin Schuh17e484e2018-03-11 01:11:36 -0800380 double intake_goal_ = 0.0;
Neil Balch07fee582018-01-27 15:46:49 -0800381
Neil Balchacfca5b2018-01-28 14:04:08 -0800382 bool was_running_ = false;
383 bool auto_running_ = false;
Neil Balchba9cbba2018-04-06 22:26:38 -0700384 bool never_disabled_ = true;
Neil Balchacfca5b2018-01-28 14:04:08 -0800385
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700386 uint32_t arm_goal_position_ = 0;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700387 VisionControl vision_control_;
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700388
389 decltype(FrontPoints()) front_points_ = FrontPoints();
390 decltype(BackPoints()) back_points_ = BackPoints();
Austin Schuhcb091712018-02-21 20:01:55 -0800391
Neil Balchacfca5b2018-01-28 14:04:08 -0800392 ::aos::common::actions::ActionQueue action_queue_;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700393
394 ProtoTXUdpSocket<VisionControl> video_tx_;
Neil Balchacfca5b2018-01-28 14:04:08 -0800395};
396
397} // namespace joysticks
398} // namespace input
399} // namespace y2018
400
401int main() {
402 ::aos::Init(-1);
403 ::y2018::input::joysticks::Reader reader;
404 reader.Run();
405 ::aos::Cleanup();
406}