blob: 41efc009ff94772df99bfb9619e3ecdf82cbea78 [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"
John Park398c74a2018-10-20 21:17:39 -070017#include "aos/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 -080088class Reader : public ::aos::input::JoystickInput {
89 public:
Austin Schuha8de4a62018-09-03 18:04:28 -070090 Reader() {
91 const uint16_t team = ::aos::network::GetTeamNumber();
92
Neil Balchacfca5b2018-01-28 14:04:08 -080093 drivetrain_input_reader_ = DrivetrainInputReader::Make(
Austin Schuha8de4a62018-09-03 18:04:28 -070094 team == 971 ? DrivetrainInputReader::InputType::kPistol
95 : DrivetrainInputReader::InputType::kSteeringWheel,
Neil Balchacfca5b2018-01-28 14:04:08 -080096 ::y2018::control_loops::drivetrain::GetDrivetrainConfig());
Austin Schuha8de4a62018-09-03 18:04:28 -070097 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
98 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Neil Balchacfca5b2018-01-28 14:04:08 -080099 }
100
101 void RunIteration(const ::aos::input::driver_station::Data &data) override {
102 bool last_auto_running = auto_running_;
103 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
104 data.GetControlBit(ControlBit::kEnabled);
105 if (auto_running_ != last_auto_running) {
106 if (auto_running_) {
107 StartAuto();
108 } else {
109 StopAuto();
110 }
111 }
112
113 if (!auto_running_) {
114 HandleDrivetrain(data);
115 HandleTeleop(data);
116 }
117
118 // Process any pending actions.
119 action_queue_.Tick();
120 was_running_ = action_queue_.Running();
121 }
122
123 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
124 drivetrain_input_reader_->HandleDrivetrain(data);
Neil Balchacfca5b2018-01-28 14:04:08 -0800125 }
126
127 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
128 if (!data.GetControlBit(ControlBit::kEnabled)) {
129 action_queue_.CancelAllActions();
130 LOG(DEBUG, "Canceling\n");
131 }
Neil Balch07fee582018-01-27 15:46:49 -0800132
Austin Schuhab15c4d2018-03-09 21:21:03 -0800133 superstructure_queue.position.FetchLatest();
Neil Balch07fee582018-01-27 15:46:49 -0800134 superstructure_queue.status.FetchLatest();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800135 if (!superstructure_queue.status.get() ||
136 !superstructure_queue.position.get()) {
Neil Balch07fee582018-01-27 15:46:49 -0800137 LOG(ERROR, "Got no superstructure status packet.\n");
138 return;
139 }
140
Neil Balch07fee582018-01-27 15:46:49 -0800141 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
142
Sabina Davisfdd7a112018-02-04 16:16:23 -0800143 new_superstructure_goal->intake.left_intake_angle = intake_goal_;
144 new_superstructure_goal->intake.right_intake_angle = intake_goal_;
Neil Balch07fee582018-01-27 15:46:49 -0800145
Austin Schuh8d5fff42018-05-30 20:44:12 -0700146 if (data.PosEdge(kIntakeIn) || data.PosEdge(kSmallBox) ||
147 data.PosEdge(kIntakeClosed)) {
148 vision_control_.set_high_video(false);
149 }
150
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700151 if (data.IsPressed(kIntakeIn)) {
Neil Balch07fee582018-01-27 15:46:49 -0800152 // Turn on the rollers.
Neil Balchba9cbba2018-04-06 22:26:38 -0700153 new_superstructure_goal->intake.roller_voltage = 8.0;
Neil Balch07fee582018-01-27 15:46:49 -0800154 } else if (data.IsPressed(kIntakeOut)) {
155 // Turn off the rollers.
Austin Schuh17dd0892018-03-02 20:06:31 -0800156 new_superstructure_goal->intake.roller_voltage = -12.0;
Neil Balch07fee582018-01-27 15:46:49 -0800157 } else {
158 // We don't want the rollers on.
159 new_superstructure_goal->intake.roller_voltage = 0.0;
160 }
161
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700162 if (data.IsPressed(kSmallBox)) {
163 // Deploy the intake.
164 if (superstructure_queue.position->box_back_beambreak_triggered) {
165 intake_goal_ = 0.30;
166 } else {
167 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
168 superstructure_queue.position->box_distance < 0.15) {
169 intake_goal_ = 0.18;
170 } else {
171 intake_goal_ = -0.60;
172 }
173 }
174 } else if (data.IsPressed(kIntakeClosed)) {
175 // Deploy the intake.
176 if (superstructure_queue.position->box_back_beambreak_triggered) {
177 intake_goal_ = 0.30;
178 } else {
179 if (new_superstructure_goal->intake.roller_voltage > 0.1) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700180 if (superstructure_queue.position->box_distance < 0.10) {
181 new_superstructure_goal->intake.roller_voltage -= 3.0;
182 intake_goal_ = 0.22;
183 } else if (superstructure_queue.position->box_distance < 0.17) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700184 intake_goal_ = 0.13;
185 } else if (superstructure_queue.position->box_distance < 0.25) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700186 intake_goal_ = 0.05;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700187 } else {
Neil Balchba9cbba2018-04-06 22:26:38 -0700188 intake_goal_ = -0.10;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700189 }
Austin Schuhcf96d322018-04-07 15:52:31 -0700190 if (drivetrain_input_reader_->robot_velocity() < -0.1 &&
191 superstructure_queue.position->box_distance > 0.15) {
192 intake_goal_ += 0.10;
193 }
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700194 } else {
195 intake_goal_ = -0.60;
196 }
197 }
198 } else {
199 // Bring in the intake.
Austin Schuhcf96d322018-04-07 15:52:31 -0700200 intake_goal_ = -3.20;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700201 }
202
Neil Balchba9cbba2018-04-06 22:26:38 -0700203 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
204 intake_goal_ > 0.0) {
205 if (superstructure_queue.position->box_distance < 0.10) {
206 new_superstructure_goal->intake.roller_voltage -= 3.0;
207 }
208 new_superstructure_goal->intake.roller_voltage += 3.0;
209 }
210
Austin Schuhb874fd32018-03-05 00:27:10 -0800211 // If we are disabled, stay at the node closest to where we start. This
212 // should remove long motions when enabled.
Neil Balchba9cbba2018-04-06 22:26:38 -0700213 if (!data.GetControlBit(ControlBit::kEnabled) || never_disabled_) {
Austin Schuhb874fd32018-03-05 00:27:10 -0800214 arm_goal_position_ = superstructure_queue.status->arm.current_node;
Neil Balchba9cbba2018-04-06 22:26:38 -0700215 never_disabled_ = false;
Austin Schuhb874fd32018-03-05 00:27:10 -0800216 }
217
Austin Schuhab15c4d2018-03-09 21:21:03 -0800218 bool grab_box = false;
219 if (data.IsPressed(kArmPickupBoxFromIntake)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800220 grab_box = true;
Neil Balchba9cbba2018-04-06 22:26:38 -0700221 }
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700222 const bool near_goal =
223 superstructure_queue.status->arm.current_node == arm_goal_position_ &&
224 superstructure_queue.status->arm.path_distance_to_go < 1e-3;
Austin Schuh822a1e52018-04-06 22:50:21 -0700225 if (data.IsPressed(kArmStepDown) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700226 uint32_t *front_point = ::std::find(
227 front_points_.begin(), front_points_.end(), arm_goal_position_);
228 uint32_t *back_point = ::std::find(
229 back_points_.begin(), back_points_.end(), arm_goal_position_);
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700230 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700231 ++front_point;
232 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700233 arm_goal_position_ = *front_point;
234 }
235 } else if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700236 ++back_point;
237 if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700238 arm_goal_position_ = *back_point;
239 }
240 }
Austin Schuh822a1e52018-04-06 22:50:21 -0700241 } else if (data.IsPressed(kArmStepUp) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700242 const uint32_t *front_point = ::std::find(
243 front_points_.begin(), front_points_.end(), arm_goal_position_);
244 const uint32_t *back_point = ::std::find(
245 back_points_.begin(), back_points_.end(), arm_goal_position_);
246 if (front_point != front_points_.end()) {
247 if (front_point != front_points_.begin()) {
248 --front_point;
249 arm_goal_position_ = *front_point;
250 }
251 } else if (back_point != back_points_.end()) {
252 if (back_point != back_points_.begin()) {
253 --back_point;
254 arm_goal_position_ = *back_point;
255 }
256 }
257 } else if (data.PosEdge(kArmPickupBoxFromIntake)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700258 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700259 arm_goal_position_ = arm::NeutralIndex();
260 } else if (data.IsPressed(kDuck)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700261 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700262 arm_goal_position_ = arm::DuckIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800263 } else if (data.IsPressed(kArmNeutral)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700264 vision_control_.set_high_video(false);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800265 arm_goal_position_ = arm::NeutralIndex();
266 } else if (data.IsPressed(kArmUp)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700267 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800268 arm_goal_position_ = arm::UpIndex();
269 } else if (data.IsPressed(kArmFrontSwitch)) {
270 arm_goal_position_ = arm::FrontSwitchIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700271 } else if (data.IsPressed(kArmFrontExtraHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700272 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800273 arm_goal_position_ = arm::FrontHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700274 } else if (data.IsPressed(kArmFrontHighBox)) {
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::FrontMiddle2BoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700277 } else if (data.IsPressed(kArmFrontMiddle2Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700278 vision_control_.set_high_video(true);
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700279 arm_goal_position_ = arm::FrontMiddle3BoxIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800280 } else if (data.IsPressed(kArmFrontMiddle1Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700281 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800282 arm_goal_position_ = arm::FrontMiddle1BoxIndex();
283 } else if (data.IsPressed(kArmFrontLowBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700284 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800285 arm_goal_position_ = arm::FrontLowBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700286 } else if (data.IsPressed(kArmBackExtraHighBox)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800287 arm_goal_position_ = arm::BackHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700288 } else if (data.IsPressed(kArmBackHighBox) ||
289 data.IsPressed(kArmBackMiddle2Box)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800290 arm_goal_position_ = arm::BackMiddle2BoxIndex();
291 } else if (data.IsPressed(kArmBackMiddle1Box)) {
292 arm_goal_position_ = arm::BackMiddle1BoxIndex();
293 } else if (data.IsPressed(kArmBackLowBox)) {
294 arm_goal_position_ = arm::BackLowBoxIndex();
295 } else if (data.IsPressed(kArmBackSwitch)) {
296 arm_goal_position_ = arm::BackSwitchIndex();
Austin Schuh17e484e2018-03-11 01:11:36 -0800297 } else if (data.IsPressed(kArmAboveHang)) {
298 if (data.IsPressed(kIntakeIn)) {
299 arm_goal_position_ = arm::SelfHangIndex();
300 } else if (data.IsPressed(kIntakeOut)) {
301 arm_goal_position_ = arm::PartnerHangIndex();
302 } else {
303 arm_goal_position_ = arm::AboveHangIndex();
304 }
305 } else if (data.IsPressed(kArmBelowHang)) {
306 arm_goal_position_ = arm::BelowHangIndex();
Neil Balch07fee582018-01-27 15:46:49 -0800307 }
308
Austin Schuhd76546a2018-07-08 16:05:14 -0700309 if (data.IsPressed(kEmergencyDown)) {
310 arm_goal_position_ = arm::NeutralIndex();
311 new_superstructure_goal->trajectory_override = true;
312 } else if (data.IsPressed(kEmergencyUp)) {
313 arm_goal_position_ = arm::UpIndex();
314 new_superstructure_goal->trajectory_override = true;
315 } else {
316 new_superstructure_goal->trajectory_override = false;
317 }
318
Austin Schuh17e484e2018-03-11 01:11:36 -0800319 new_superstructure_goal->deploy_fork =
320 data.IsPressed(kArmAboveHang) && data.IsPressed(kClawOpen);
321
322 if (new_superstructure_goal->deploy_fork) {
323 intake_goal_ = -2.0;
324 }
325
326 if (data.IsPressed(kWinch)) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700327 LOG(INFO, "Winching\n");
Austin Schuh17e484e2018-03-11 01:11:36 -0800328 new_superstructure_goal->voltage_winch = 12.0;
329 } else {
330 new_superstructure_goal->voltage_winch = 0.0;
331 }
332
333 new_superstructure_goal->hook_release = data.IsPressed(kArmBelowHang);
334
Austin Schuhcb091712018-02-21 20:01:55 -0800335 new_superstructure_goal->arm_goal_position = arm_goal_position_;
Austin Schuhd76546a2018-07-08 16:05:14 -0700336 if (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)) {
337 new_superstructure_goal->open_threshold = 0.35;
338 } else {
339 new_superstructure_goal->open_threshold = 0.0;
340 }
Austin Schuhcb091712018-02-21 20:01:55 -0800341
Neil Balchba9cbba2018-04-06 22:26:38 -0700342 if ((data.IsPressed(kClawOpen) && data.IsPressed(kDriverClawOpen)) ||
Austin Schuhd76546a2018-07-08 16:05:14 -0700343 data.PosEdge(kArmPickupBoxFromIntake) ||
344 (data.IsPressed(kClawOpen) &&
345 (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)))) {
Neil Balch07fee582018-01-27 15:46:49 -0800346 new_superstructure_goal->open_claw = true;
Austin Schuhab15c4d2018-03-09 21:21:03 -0800347 } else {
Neil Balch07fee582018-01-27 15:46:49 -0800348 new_superstructure_goal->open_claw = false;
349 }
350
Austin Schuhab15c4d2018-03-09 21:21:03 -0800351 new_superstructure_goal->grab_box = grab_box;
Neil Balch07fee582018-01-27 15:46:49 -0800352
353 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
354 if (!new_superstructure_goal.Send()) {
355 LOG(ERROR, "Sending superstructure goal failed.\n");
356 }
Austin Schuh8d5fff42018-05-30 20:44:12 -0700357
Austin Schuha8de4a62018-09-03 18:04:28 -0700358 video_tx_->Send(vision_control_);
Neil Balchacfca5b2018-01-28 14:04:08 -0800359 }
360
361 private:
Austin Schuha3c148e2018-03-09 21:04:05 -0800362 void StartAuto() {
363 LOG(INFO, "Starting auto mode\n");
364
365 ::frc971::autonomous::AutonomousActionParams params;
366 ::frc971::autonomous::auto_mode.FetchLatest();
367 if (::frc971::autonomous::auto_mode.get() != nullptr) {
Austin Schuhc231df42018-03-21 20:43:24 -0700368 params.mode = ::frc971::autonomous::auto_mode->mode << 2;
Austin Schuha3c148e2018-03-09 21:04:05 -0800369 } else {
370 LOG(WARNING, "no auto mode values\n");
371 params.mode = 0;
372 }
Austin Schuhc231df42018-03-21 20:43:24 -0700373 // TODO(austin): use the mode later if we care. We don't care right now.
374 params.mode = static_cast<int>(::aos::joystick_state->switch_left) |
375 (static_cast<int>(::aos::joystick_state->scale_left) << 1);
Austin Schuha3c148e2018-03-09 21:04:05 -0800376 action_queue_.EnqueueAction(
377 ::frc971::autonomous::MakeAutonomousAction(params));
378 }
Neil Balchacfca5b2018-01-28 14:04:08 -0800379
380 void StopAuto() {
381 LOG(INFO, "Stopping auto mode\n");
382 action_queue_.CancelAllActions();
383 }
384
Neil Balch07fee582018-01-27 15:46:49 -0800385 // Current goals to send to the robot.
Austin Schuh17e484e2018-03-11 01:11:36 -0800386 double intake_goal_ = 0.0;
Neil Balch07fee582018-01-27 15:46:49 -0800387
Neil Balchacfca5b2018-01-28 14:04:08 -0800388 bool was_running_ = false;
389 bool auto_running_ = false;
Neil Balchba9cbba2018-04-06 22:26:38 -0700390 bool never_disabled_ = true;
Neil Balchacfca5b2018-01-28 14:04:08 -0800391
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700392 uint32_t arm_goal_position_ = 0;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700393 VisionControl vision_control_;
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700394
395 decltype(FrontPoints()) front_points_ = FrontPoints();
396 decltype(BackPoints()) back_points_ = BackPoints();
Austin Schuhcb091712018-02-21 20:01:55 -0800397
Neil Balchacfca5b2018-01-28 14:04:08 -0800398 ::aos::common::actions::ActionQueue action_queue_;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700399
Austin Schuha8de4a62018-09-03 18:04:28 -0700400 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Austin Schuh4a66adf2018-12-23 08:48:45 +1100401
402 ::std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_;
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}