blob: de8f1f67b75472bd439bee5b488905911d68c267 [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>
Austin Schuha8de4a62018-09-03 18:04:28 -07006#include <google/protobuf/stubs/stringprintf.h>
Neil Balchacfca5b2018-01-28 14:04:08 -08007
John Park33858a32018-09-28 23:05:48 -07008#include "aos/actions/actions.h"
9#include "aos/input/driver_station_data.h"
10#include "aos/logging/logging.h"
11#include "aos/network/team_number.h"
12#include "aos/stl_mutex/stl_mutex.h"
13#include "aos/time/time.h"
14#include "aos/util/log_interval.h"
Neil Balchacfca5b2018-01-28 14:04:08 -080015#include "aos/input/drivetrain_input.h"
16#include "aos/input/joystick_input.h"
17#include "aos/linux_code/init.h"
Austin Schuh8d5fff42018-05-30 20:44:12 -070018#include "aos/vision/events/udp.h"
Austin Schuha3c148e2018-03-09 21:04:05 -080019#include "frc971/autonomous/auto.q.h"
20#include "frc971/autonomous/base_autonomous_actor.h"
Neil Balchacfca5b2018-01-28 14:04:08 -080021#include "frc971/control_loops/drivetrain/drivetrain.q.h"
22#include "y2018/control_loops/drivetrain/drivetrain_base.h"
Austin Schuhab15c4d2018-03-09 21:21:03 -080023#include "y2018/control_loops/superstructure/arm/generated_graph.h"
Neil Balch07fee582018-01-27 15:46:49 -080024#include "y2018/control_loops/superstructure/superstructure.q.h"
Austin Schuh8d5fff42018-05-30 20:44:12 -070025#include "y2018/vision.pb.h"
Neil Balchacfca5b2018-01-28 14:04:08 -080026
Austin Schuh8d5fff42018-05-30 20:44:12 -070027using ::aos::monotonic_clock;
Neil Balchacfca5b2018-01-28 14:04:08 -080028using ::frc971::control_loops::drivetrain_queue;
Neil Balch07fee582018-01-27 15:46:49 -080029using ::y2018::control_loops::superstructure_queue;
Austin Schuh8d5fff42018-05-30 20:44:12 -070030using ::aos::events::ProtoTXUdpSocket;
31using ::aos::events::RXUdpSocket;
Neil Balchacfca5b2018-01-28 14:04:08 -080032using ::aos::input::driver_station::ButtonLocation;
33using ::aos::input::driver_station::ControlBit;
34using ::aos::input::driver_station::JoystickAxis;
35using ::aos::input::driver_station::POVLocation;
36using ::aos::input::DrivetrainInputReader;
37
Austin Schuh60cdb3e2018-04-06 21:52:32 -070038using ::y2018::control_loops::superstructure::arm::FrontPoints;
39using ::y2018::control_loops::superstructure::arm::BackPoints;
40
Neil Balchacfca5b2018-01-28 14:04:08 -080041namespace y2018 {
42namespace input {
43namespace joysticks {
44
Austin Schuhab15c4d2018-03-09 21:21:03 -080045namespace arm = ::y2018::control_loops::superstructure::arm;
Austin Schuha8de4a62018-09-03 18:04:28 -070046using google::protobuf::StringPrintf;
Neil Balch07fee582018-01-27 15:46:49 -080047
Sabina Davis833ccf62018-04-06 20:52:31 -070048const ButtonLocation kIntakeClosed(3, 2);
49const ButtonLocation kDuck(3, 9);
50const ButtonLocation kSmallBox(3, 1);
Austin Schuh47d74942018-03-04 01:15:59 -080051
Sabina Davis833ccf62018-04-06 20:52:31 -070052const ButtonLocation kIntakeIn(3, 4);
53const ButtonLocation kIntakeOut(3, 3);
Neil Balch07fee582018-01-27 15:46:49 -080054
Austin Schuha8de4a62018-09-03 18:04:28 -070055const ButtonLocation kArmBackHighBox(4, 11);
56const ButtonLocation kArmBackExtraHighBox(4, 1);
57const ButtonLocation kArmBackMiddle2Box(4, 9);
58const ButtonLocation kArmBackMiddle1Box(4, 7);
59const ButtonLocation kArmBackLowBox(4, 5);
60const ButtonLocation kArmBackSwitch(3, 7);
Austin Schuhab15c4d2018-03-09 21:21:03 -080061
Austin Schuha8de4a62018-09-03 18:04:28 -070062const ButtonLocation kArmFrontHighBox(4, 12);
63const ButtonLocation kArmFrontExtraHighBox(3, 14);
64const ButtonLocation kArmFrontMiddle2Box(4, 10);
65const ButtonLocation kArmFrontMiddle1Box(4, 8);
66const ButtonLocation kArmFrontLowBox(4, 6);
67const ButtonLocation kArmFrontSwitch(3, 10);
Austin Schuhab15c4d2018-03-09 21:21:03 -080068
Sabina Davis833ccf62018-04-06 20:52:31 -070069const ButtonLocation kArmAboveHang(3, 15);
70const ButtonLocation kArmBelowHang(3, 16);
Austin Schuh17e484e2018-03-11 01:11:36 -080071
Austin Schuhd76546a2018-07-08 16:05:14 -070072const ButtonLocation kEmergencyUp(3, 5);
73const ButtonLocation kEmergencyDown(3, 6);
74
Sabina Davis833ccf62018-04-06 20:52:31 -070075const ButtonLocation kWinch(4, 2);
Austin Schuh17e484e2018-03-11 01:11:36 -080076
Sabina Davis833ccf62018-04-06 20:52:31 -070077const ButtonLocation kArmNeutral(3, 8);
78const ButtonLocation kArmUp(3, 11);
Austin Schuhab15c4d2018-03-09 21:21:03 -080079
Sabina Davis833ccf62018-04-06 20:52:31 -070080const ButtonLocation kArmStepUp(3, 13);
81const ButtonLocation kArmStepDown(3, 12);
Austin Schuhab15c4d2018-03-09 21:21:03 -080082
Sabina Davis833ccf62018-04-06 20:52:31 -070083const ButtonLocation kArmPickupBoxFromIntake(4, 3);
84
85const ButtonLocation kClawOpen(4, 4);
Neil Balchba9cbba2018-04-06 22:26:38 -070086const ButtonLocation kDriverClawOpen(2, 4);
Neil Balch07fee582018-01-27 15:46:49 -080087
Neil Balchacfca5b2018-01-28 14:04:08 -080088std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_;
89
90class Reader : public ::aos::input::JoystickInput {
91 public:
Austin Schuha8de4a62018-09-03 18:04:28 -070092 Reader() {
93 const uint16_t team = ::aos::network::GetTeamNumber();
94
Neil Balchacfca5b2018-01-28 14:04:08 -080095 drivetrain_input_reader_ = DrivetrainInputReader::Make(
Austin Schuha8de4a62018-09-03 18:04:28 -070096 team == 971 ? DrivetrainInputReader::InputType::kPistol
97 : DrivetrainInputReader::InputType::kSteeringWheel,
Neil Balchacfca5b2018-01-28 14:04:08 -080098 ::y2018::control_loops::drivetrain::GetDrivetrainConfig());
Austin Schuha8de4a62018-09-03 18:04:28 -070099 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
100 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Neil Balchacfca5b2018-01-28 14:04:08 -0800101 }
102
103 void RunIteration(const ::aos::input::driver_station::Data &data) override {
104 bool last_auto_running = auto_running_;
105 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
106 data.GetControlBit(ControlBit::kEnabled);
107 if (auto_running_ != last_auto_running) {
108 if (auto_running_) {
109 StartAuto();
110 } else {
111 StopAuto();
112 }
113 }
114
115 if (!auto_running_) {
116 HandleDrivetrain(data);
117 HandleTeleop(data);
118 }
119
120 // Process any pending actions.
121 action_queue_.Tick();
122 was_running_ = action_queue_.Running();
123 }
124
125 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
126 drivetrain_input_reader_->HandleDrivetrain(data);
Neil Balchacfca5b2018-01-28 14:04:08 -0800127 }
128
129 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
130 if (!data.GetControlBit(ControlBit::kEnabled)) {
131 action_queue_.CancelAllActions();
132 LOG(DEBUG, "Canceling\n");
133 }
Neil Balch07fee582018-01-27 15:46:49 -0800134
Austin Schuhab15c4d2018-03-09 21:21:03 -0800135 superstructure_queue.position.FetchLatest();
Neil Balch07fee582018-01-27 15:46:49 -0800136 superstructure_queue.status.FetchLatest();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800137 if (!superstructure_queue.status.get() ||
138 !superstructure_queue.position.get()) {
Neil Balch07fee582018-01-27 15:46:49 -0800139 LOG(ERROR, "Got no superstructure status packet.\n");
140 return;
141 }
142
Neil Balch07fee582018-01-27 15:46:49 -0800143 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
144
Sabina Davisfdd7a112018-02-04 16:16:23 -0800145 new_superstructure_goal->intake.left_intake_angle = intake_goal_;
146 new_superstructure_goal->intake.right_intake_angle = intake_goal_;
Neil Balch07fee582018-01-27 15:46:49 -0800147
Austin Schuh8d5fff42018-05-30 20:44:12 -0700148 if (data.PosEdge(kIntakeIn) || data.PosEdge(kSmallBox) ||
149 data.PosEdge(kIntakeClosed)) {
150 vision_control_.set_high_video(false);
151 }
152
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700153 if (data.IsPressed(kIntakeIn)) {
Neil Balch07fee582018-01-27 15:46:49 -0800154 // Turn on the rollers.
Neil Balchba9cbba2018-04-06 22:26:38 -0700155 new_superstructure_goal->intake.roller_voltage = 8.0;
Neil Balch07fee582018-01-27 15:46:49 -0800156 } else if (data.IsPressed(kIntakeOut)) {
157 // Turn off the rollers.
Austin Schuh17dd0892018-03-02 20:06:31 -0800158 new_superstructure_goal->intake.roller_voltage = -12.0;
Neil Balch07fee582018-01-27 15:46:49 -0800159 } else {
160 // We don't want the rollers on.
161 new_superstructure_goal->intake.roller_voltage = 0.0;
162 }
163
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700164 if (data.IsPressed(kSmallBox)) {
165 // Deploy the intake.
166 if (superstructure_queue.position->box_back_beambreak_triggered) {
167 intake_goal_ = 0.30;
168 } else {
169 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
170 superstructure_queue.position->box_distance < 0.15) {
171 intake_goal_ = 0.18;
172 } else {
173 intake_goal_ = -0.60;
174 }
175 }
176 } else if (data.IsPressed(kIntakeClosed)) {
177 // Deploy the intake.
178 if (superstructure_queue.position->box_back_beambreak_triggered) {
179 intake_goal_ = 0.30;
180 } else {
181 if (new_superstructure_goal->intake.roller_voltage > 0.1) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700182 if (superstructure_queue.position->box_distance < 0.10) {
183 new_superstructure_goal->intake.roller_voltage -= 3.0;
184 intake_goal_ = 0.22;
185 } else if (superstructure_queue.position->box_distance < 0.17) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700186 intake_goal_ = 0.13;
187 } else if (superstructure_queue.position->box_distance < 0.25) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700188 intake_goal_ = 0.05;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700189 } else {
Neil Balchba9cbba2018-04-06 22:26:38 -0700190 intake_goal_ = -0.10;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700191 }
Austin Schuhcf96d322018-04-07 15:52:31 -0700192 if (drivetrain_input_reader_->robot_velocity() < -0.1 &&
193 superstructure_queue.position->box_distance > 0.15) {
194 intake_goal_ += 0.10;
195 }
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700196 } else {
197 intake_goal_ = -0.60;
198 }
199 }
200 } else {
201 // Bring in the intake.
Austin Schuhcf96d322018-04-07 15:52:31 -0700202 intake_goal_ = -3.20;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700203 }
204
Neil Balchba9cbba2018-04-06 22:26:38 -0700205 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
206 intake_goal_ > 0.0) {
207 if (superstructure_queue.position->box_distance < 0.10) {
208 new_superstructure_goal->intake.roller_voltage -= 3.0;
209 }
210 new_superstructure_goal->intake.roller_voltage += 3.0;
211 }
212
Austin Schuhb874fd32018-03-05 00:27:10 -0800213 // If we are disabled, stay at the node closest to where we start. This
214 // should remove long motions when enabled.
Neil Balchba9cbba2018-04-06 22:26:38 -0700215 if (!data.GetControlBit(ControlBit::kEnabled) || never_disabled_) {
Austin Schuhb874fd32018-03-05 00:27:10 -0800216 arm_goal_position_ = superstructure_queue.status->arm.current_node;
Neil Balchba9cbba2018-04-06 22:26:38 -0700217 never_disabled_ = false;
Austin Schuhb874fd32018-03-05 00:27:10 -0800218 }
219
Austin Schuhab15c4d2018-03-09 21:21:03 -0800220 bool grab_box = false;
221 if (data.IsPressed(kArmPickupBoxFromIntake)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800222 grab_box = true;
Neil Balchba9cbba2018-04-06 22:26:38 -0700223 }
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700224 const bool near_goal =
225 superstructure_queue.status->arm.current_node == arm_goal_position_ &&
226 superstructure_queue.status->arm.path_distance_to_go < 1e-3;
Austin Schuh822a1e52018-04-06 22:50:21 -0700227 if (data.IsPressed(kArmStepDown) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700228 uint32_t *front_point = ::std::find(
229 front_points_.begin(), front_points_.end(), arm_goal_position_);
230 uint32_t *back_point = ::std::find(
231 back_points_.begin(), back_points_.end(), arm_goal_position_);
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700232 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700233 ++front_point;
234 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700235 arm_goal_position_ = *front_point;
236 }
237 } else if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700238 ++back_point;
239 if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700240 arm_goal_position_ = *back_point;
241 }
242 }
Austin Schuh822a1e52018-04-06 22:50:21 -0700243 } else if (data.IsPressed(kArmStepUp) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700244 const uint32_t *front_point = ::std::find(
245 front_points_.begin(), front_points_.end(), arm_goal_position_);
246 const uint32_t *back_point = ::std::find(
247 back_points_.begin(), back_points_.end(), arm_goal_position_);
248 if (front_point != front_points_.end()) {
249 if (front_point != front_points_.begin()) {
250 --front_point;
251 arm_goal_position_ = *front_point;
252 }
253 } else if (back_point != back_points_.end()) {
254 if (back_point != back_points_.begin()) {
255 --back_point;
256 arm_goal_position_ = *back_point;
257 }
258 }
259 } else if (data.PosEdge(kArmPickupBoxFromIntake)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700260 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700261 arm_goal_position_ = arm::NeutralIndex();
262 } else if (data.IsPressed(kDuck)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700263 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700264 arm_goal_position_ = arm::DuckIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800265 } else if (data.IsPressed(kArmNeutral)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700266 vision_control_.set_high_video(false);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800267 arm_goal_position_ = arm::NeutralIndex();
268 } else if (data.IsPressed(kArmUp)) {
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::UpIndex();
271 } else if (data.IsPressed(kArmFrontSwitch)) {
272 arm_goal_position_ = arm::FrontSwitchIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700273 } else if (data.IsPressed(kArmFrontExtraHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700274 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800275 arm_goal_position_ = arm::FrontHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700276 } else if (data.IsPressed(kArmFrontHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700277 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800278 arm_goal_position_ = arm::FrontMiddle2BoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700279 } else if (data.IsPressed(kArmFrontMiddle2Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700280 vision_control_.set_high_video(true);
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700281 arm_goal_position_ = arm::FrontMiddle3BoxIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800282 } else if (data.IsPressed(kArmFrontMiddle1Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700283 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800284 arm_goal_position_ = arm::FrontMiddle1BoxIndex();
285 } else if (data.IsPressed(kArmFrontLowBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700286 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800287 arm_goal_position_ = arm::FrontLowBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700288 } else if (data.IsPressed(kArmBackExtraHighBox)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800289 arm_goal_position_ = arm::BackHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700290 } else if (data.IsPressed(kArmBackHighBox) ||
291 data.IsPressed(kArmBackMiddle2Box)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800292 arm_goal_position_ = arm::BackMiddle2BoxIndex();
293 } else if (data.IsPressed(kArmBackMiddle1Box)) {
294 arm_goal_position_ = arm::BackMiddle1BoxIndex();
295 } else if (data.IsPressed(kArmBackLowBox)) {
296 arm_goal_position_ = arm::BackLowBoxIndex();
297 } else if (data.IsPressed(kArmBackSwitch)) {
298 arm_goal_position_ = arm::BackSwitchIndex();
Austin Schuh17e484e2018-03-11 01:11:36 -0800299 } else if (data.IsPressed(kArmAboveHang)) {
300 if (data.IsPressed(kIntakeIn)) {
301 arm_goal_position_ = arm::SelfHangIndex();
302 } else if (data.IsPressed(kIntakeOut)) {
303 arm_goal_position_ = arm::PartnerHangIndex();
304 } else {
305 arm_goal_position_ = arm::AboveHangIndex();
306 }
307 } else if (data.IsPressed(kArmBelowHang)) {
308 arm_goal_position_ = arm::BelowHangIndex();
Neil Balch07fee582018-01-27 15:46:49 -0800309 }
310
Austin Schuhd76546a2018-07-08 16:05:14 -0700311 if (data.IsPressed(kEmergencyDown)) {
312 arm_goal_position_ = arm::NeutralIndex();
313 new_superstructure_goal->trajectory_override = true;
314 } else if (data.IsPressed(kEmergencyUp)) {
315 arm_goal_position_ = arm::UpIndex();
316 new_superstructure_goal->trajectory_override = true;
317 } else {
318 new_superstructure_goal->trajectory_override = false;
319 }
320
Austin Schuh17e484e2018-03-11 01:11:36 -0800321 new_superstructure_goal->deploy_fork =
322 data.IsPressed(kArmAboveHang) && data.IsPressed(kClawOpen);
323
324 if (new_superstructure_goal->deploy_fork) {
325 intake_goal_ = -2.0;
326 }
327
328 if (data.IsPressed(kWinch)) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700329 LOG(INFO, "Winching\n");
Austin Schuh17e484e2018-03-11 01:11:36 -0800330 new_superstructure_goal->voltage_winch = 12.0;
331 } else {
332 new_superstructure_goal->voltage_winch = 0.0;
333 }
334
335 new_superstructure_goal->hook_release = data.IsPressed(kArmBelowHang);
336
Austin Schuhcb091712018-02-21 20:01:55 -0800337 new_superstructure_goal->arm_goal_position = arm_goal_position_;
Austin Schuhd76546a2018-07-08 16:05:14 -0700338 if (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)) {
339 new_superstructure_goal->open_threshold = 0.35;
340 } else {
341 new_superstructure_goal->open_threshold = 0.0;
342 }
Austin Schuhcb091712018-02-21 20:01:55 -0800343
Neil Balchba9cbba2018-04-06 22:26:38 -0700344 if ((data.IsPressed(kClawOpen) && data.IsPressed(kDriverClawOpen)) ||
Austin Schuhd76546a2018-07-08 16:05:14 -0700345 data.PosEdge(kArmPickupBoxFromIntake) ||
346 (data.IsPressed(kClawOpen) &&
347 (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)))) {
Neil Balch07fee582018-01-27 15:46:49 -0800348 new_superstructure_goal->open_claw = true;
Austin Schuhab15c4d2018-03-09 21:21:03 -0800349 } else {
Neil Balch07fee582018-01-27 15:46:49 -0800350 new_superstructure_goal->open_claw = false;
351 }
352
Austin Schuhab15c4d2018-03-09 21:21:03 -0800353 new_superstructure_goal->grab_box = grab_box;
Neil Balch07fee582018-01-27 15:46:49 -0800354
355 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
356 if (!new_superstructure_goal.Send()) {
357 LOG(ERROR, "Sending superstructure goal failed.\n");
358 }
Austin Schuh8d5fff42018-05-30 20:44:12 -0700359
Austin Schuha8de4a62018-09-03 18:04:28 -0700360 video_tx_->Send(vision_control_);
Neil Balchacfca5b2018-01-28 14:04:08 -0800361 }
362
363 private:
Austin Schuha3c148e2018-03-09 21:04:05 -0800364 void StartAuto() {
365 LOG(INFO, "Starting auto mode\n");
366
367 ::frc971::autonomous::AutonomousActionParams params;
368 ::frc971::autonomous::auto_mode.FetchLatest();
369 if (::frc971::autonomous::auto_mode.get() != nullptr) {
Austin Schuhc231df42018-03-21 20:43:24 -0700370 params.mode = ::frc971::autonomous::auto_mode->mode << 2;
Austin Schuha3c148e2018-03-09 21:04:05 -0800371 } else {
372 LOG(WARNING, "no auto mode values\n");
373 params.mode = 0;
374 }
Austin Schuhc231df42018-03-21 20:43:24 -0700375 // TODO(austin): use the mode later if we care. We don't care right now.
376 params.mode = static_cast<int>(::aos::joystick_state->switch_left) |
377 (static_cast<int>(::aos::joystick_state->scale_left) << 1);
Austin Schuha3c148e2018-03-09 21:04:05 -0800378 action_queue_.EnqueueAction(
379 ::frc971::autonomous::MakeAutonomousAction(params));
380 }
Neil Balchacfca5b2018-01-28 14:04:08 -0800381
382 void StopAuto() {
383 LOG(INFO, "Stopping auto mode\n");
384 action_queue_.CancelAllActions();
385 }
386
Neil Balch07fee582018-01-27 15:46:49 -0800387 // Current goals to send to the robot.
Austin Schuh17e484e2018-03-11 01:11:36 -0800388 double intake_goal_ = 0.0;
Neil Balch07fee582018-01-27 15:46:49 -0800389
Neil Balchacfca5b2018-01-28 14:04:08 -0800390 bool was_running_ = false;
391 bool auto_running_ = false;
Neil Balchba9cbba2018-04-06 22:26:38 -0700392 bool never_disabled_ = true;
Neil Balchacfca5b2018-01-28 14:04:08 -0800393
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700394 uint32_t arm_goal_position_ = 0;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700395 VisionControl vision_control_;
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700396
397 decltype(FrontPoints()) front_points_ = FrontPoints();
398 decltype(BackPoints()) back_points_ = BackPoints();
Austin Schuhcb091712018-02-21 20:01:55 -0800399
Neil Balchacfca5b2018-01-28 14:04:08 -0800400 ::aos::common::actions::ActionQueue action_queue_;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700401
Austin Schuha8de4a62018-09-03 18:04:28 -0700402 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Neil Balchacfca5b2018-01-28 14:04:08 -0800403};
404
405} // namespace joysticks
406} // namespace input
407} // namespace y2018
408
409int main() {
410 ::aos::Init(-1);
411 ::y2018::input::joysticks::Reader reader;
412 reader.Run();
413 ::aos::Cleanup();
414}