blob: 41b4d1402a613fcb1a31151552cb45ac01377ebb [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 Schuh3e45c752019-02-02 12:19:11 -080090 Reader(::aos::EventLoop *event_loop)
91 : ::aos::input::JoystickInput(event_loop) {
Austin Schuha8de4a62018-09-03 18:04:28 -070092 const uint16_t team = ::aos::network::GetTeamNumber();
93
Neil Balchacfca5b2018-01-28 14:04:08 -080094 drivetrain_input_reader_ = DrivetrainInputReader::Make(
Austin Schuha8de4a62018-09-03 18:04:28 -070095 team == 971 ? DrivetrainInputReader::InputType::kPistol
96 : DrivetrainInputReader::InputType::kSteeringWheel,
Neil Balchacfca5b2018-01-28 14:04:08 -080097 ::y2018::control_loops::drivetrain::GetDrivetrainConfig());
Austin Schuha8de4a62018-09-03 18:04:28 -070098 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
99 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Neil Balchacfca5b2018-01-28 14:04:08 -0800100 }
101
102 void RunIteration(const ::aos::input::driver_station::Data &data) override {
103 bool last_auto_running = auto_running_;
104 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
105 data.GetControlBit(ControlBit::kEnabled);
106 if (auto_running_ != last_auto_running) {
107 if (auto_running_) {
108 StartAuto();
109 } else {
110 StopAuto();
111 }
112 }
113
114 if (!auto_running_) {
115 HandleDrivetrain(data);
116 HandleTeleop(data);
117 }
118
119 // Process any pending actions.
120 action_queue_.Tick();
121 was_running_ = action_queue_.Running();
122 }
123
124 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
125 drivetrain_input_reader_->HandleDrivetrain(data);
Neil Balchacfca5b2018-01-28 14:04:08 -0800126 }
127
128 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
129 if (!data.GetControlBit(ControlBit::kEnabled)) {
130 action_queue_.CancelAllActions();
131 LOG(DEBUG, "Canceling\n");
132 }
Neil Balch07fee582018-01-27 15:46:49 -0800133
Austin Schuhab15c4d2018-03-09 21:21:03 -0800134 superstructure_queue.position.FetchLatest();
Neil Balch07fee582018-01-27 15:46:49 -0800135 superstructure_queue.status.FetchLatest();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800136 if (!superstructure_queue.status.get() ||
137 !superstructure_queue.position.get()) {
Neil Balch07fee582018-01-27 15:46:49 -0800138 LOG(ERROR, "Got no superstructure status packet.\n");
139 return;
140 }
141
Neil Balch07fee582018-01-27 15:46:49 -0800142 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
143
Sabina Davisfdd7a112018-02-04 16:16:23 -0800144 new_superstructure_goal->intake.left_intake_angle = intake_goal_;
145 new_superstructure_goal->intake.right_intake_angle = intake_goal_;
Neil Balch07fee582018-01-27 15:46:49 -0800146
Austin Schuh8d5fff42018-05-30 20:44:12 -0700147 if (data.PosEdge(kIntakeIn) || data.PosEdge(kSmallBox) ||
148 data.PosEdge(kIntakeClosed)) {
149 vision_control_.set_high_video(false);
150 }
151
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700152 if (data.IsPressed(kIntakeIn)) {
Neil Balch07fee582018-01-27 15:46:49 -0800153 // Turn on the rollers.
Neil Balchba9cbba2018-04-06 22:26:38 -0700154 new_superstructure_goal->intake.roller_voltage = 8.0;
Neil Balch07fee582018-01-27 15:46:49 -0800155 } else if (data.IsPressed(kIntakeOut)) {
156 // Turn off the rollers.
Austin Schuh17dd0892018-03-02 20:06:31 -0800157 new_superstructure_goal->intake.roller_voltage = -12.0;
Neil Balch07fee582018-01-27 15:46:49 -0800158 } else {
159 // We don't want the rollers on.
160 new_superstructure_goal->intake.roller_voltage = 0.0;
161 }
162
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700163 if (data.IsPressed(kSmallBox)) {
164 // Deploy the intake.
165 if (superstructure_queue.position->box_back_beambreak_triggered) {
166 intake_goal_ = 0.30;
167 } else {
168 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
169 superstructure_queue.position->box_distance < 0.15) {
170 intake_goal_ = 0.18;
171 } else {
172 intake_goal_ = -0.60;
173 }
174 }
175 } else if (data.IsPressed(kIntakeClosed)) {
176 // Deploy the intake.
177 if (superstructure_queue.position->box_back_beambreak_triggered) {
178 intake_goal_ = 0.30;
179 } else {
180 if (new_superstructure_goal->intake.roller_voltage > 0.1) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700181 if (superstructure_queue.position->box_distance < 0.10) {
182 new_superstructure_goal->intake.roller_voltage -= 3.0;
183 intake_goal_ = 0.22;
184 } else if (superstructure_queue.position->box_distance < 0.17) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700185 intake_goal_ = 0.13;
186 } else if (superstructure_queue.position->box_distance < 0.25) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700187 intake_goal_ = 0.05;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700188 } else {
Neil Balchba9cbba2018-04-06 22:26:38 -0700189 intake_goal_ = -0.10;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700190 }
Austin Schuhcf96d322018-04-07 15:52:31 -0700191 if (drivetrain_input_reader_->robot_velocity() < -0.1 &&
192 superstructure_queue.position->box_distance > 0.15) {
193 intake_goal_ += 0.10;
194 }
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700195 } else {
196 intake_goal_ = -0.60;
197 }
198 }
199 } else {
200 // Bring in the intake.
Austin Schuhcf96d322018-04-07 15:52:31 -0700201 intake_goal_ = -3.20;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700202 }
203
Neil Balchba9cbba2018-04-06 22:26:38 -0700204 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
205 intake_goal_ > 0.0) {
206 if (superstructure_queue.position->box_distance < 0.10) {
207 new_superstructure_goal->intake.roller_voltage -= 3.0;
208 }
209 new_superstructure_goal->intake.roller_voltage += 3.0;
210 }
211
Austin Schuhb874fd32018-03-05 00:27:10 -0800212 // If we are disabled, stay at the node closest to where we start. This
213 // should remove long motions when enabled.
Neil Balchba9cbba2018-04-06 22:26:38 -0700214 if (!data.GetControlBit(ControlBit::kEnabled) || never_disabled_) {
Austin Schuhb874fd32018-03-05 00:27:10 -0800215 arm_goal_position_ = superstructure_queue.status->arm.current_node;
Neil Balchba9cbba2018-04-06 22:26:38 -0700216 never_disabled_ = false;
Austin Schuhb874fd32018-03-05 00:27:10 -0800217 }
218
Austin Schuhab15c4d2018-03-09 21:21:03 -0800219 bool grab_box = false;
220 if (data.IsPressed(kArmPickupBoxFromIntake)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800221 grab_box = true;
Neil Balchba9cbba2018-04-06 22:26:38 -0700222 }
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700223 const bool near_goal =
224 superstructure_queue.status->arm.current_node == arm_goal_position_ &&
225 superstructure_queue.status->arm.path_distance_to_go < 1e-3;
Austin Schuh822a1e52018-04-06 22:50:21 -0700226 if (data.IsPressed(kArmStepDown) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700227 uint32_t *front_point = ::std::find(
228 front_points_.begin(), front_points_.end(), arm_goal_position_);
229 uint32_t *back_point = ::std::find(
230 back_points_.begin(), back_points_.end(), arm_goal_position_);
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700231 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700232 ++front_point;
233 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700234 arm_goal_position_ = *front_point;
235 }
236 } else if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700237 ++back_point;
238 if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700239 arm_goal_position_ = *back_point;
240 }
241 }
Austin Schuh822a1e52018-04-06 22:50:21 -0700242 } else if (data.IsPressed(kArmStepUp) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700243 const uint32_t *front_point = ::std::find(
244 front_points_.begin(), front_points_.end(), arm_goal_position_);
245 const uint32_t *back_point = ::std::find(
246 back_points_.begin(), back_points_.end(), arm_goal_position_);
247 if (front_point != front_points_.end()) {
248 if (front_point != front_points_.begin()) {
249 --front_point;
250 arm_goal_position_ = *front_point;
251 }
252 } else if (back_point != back_points_.end()) {
253 if (back_point != back_points_.begin()) {
254 --back_point;
255 arm_goal_position_ = *back_point;
256 }
257 }
258 } else if (data.PosEdge(kArmPickupBoxFromIntake)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700259 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700260 arm_goal_position_ = arm::NeutralIndex();
261 } else if (data.IsPressed(kDuck)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700262 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700263 arm_goal_position_ = arm::DuckIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800264 } else if (data.IsPressed(kArmNeutral)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700265 vision_control_.set_high_video(false);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800266 arm_goal_position_ = arm::NeutralIndex();
267 } else if (data.IsPressed(kArmUp)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700268 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800269 arm_goal_position_ = arm::UpIndex();
270 } else if (data.IsPressed(kArmFrontSwitch)) {
271 arm_goal_position_ = arm::FrontSwitchIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700272 } else if (data.IsPressed(kArmFrontExtraHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700273 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800274 arm_goal_position_ = arm::FrontHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700275 } else if (data.IsPressed(kArmFrontHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700276 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800277 arm_goal_position_ = arm::FrontMiddle2BoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700278 } else if (data.IsPressed(kArmFrontMiddle2Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700279 vision_control_.set_high_video(true);
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700280 arm_goal_position_ = arm::FrontMiddle3BoxIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800281 } else if (data.IsPressed(kArmFrontMiddle1Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700282 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800283 arm_goal_position_ = arm::FrontMiddle1BoxIndex();
284 } else if (data.IsPressed(kArmFrontLowBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700285 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800286 arm_goal_position_ = arm::FrontLowBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700287 } else if (data.IsPressed(kArmBackExtraHighBox)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800288 arm_goal_position_ = arm::BackHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700289 } else if (data.IsPressed(kArmBackHighBox) ||
290 data.IsPressed(kArmBackMiddle2Box)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800291 arm_goal_position_ = arm::BackMiddle2BoxIndex();
292 } else if (data.IsPressed(kArmBackMiddle1Box)) {
293 arm_goal_position_ = arm::BackMiddle1BoxIndex();
294 } else if (data.IsPressed(kArmBackLowBox)) {
295 arm_goal_position_ = arm::BackLowBoxIndex();
296 } else if (data.IsPressed(kArmBackSwitch)) {
297 arm_goal_position_ = arm::BackSwitchIndex();
Austin Schuh17e484e2018-03-11 01:11:36 -0800298 } else if (data.IsPressed(kArmAboveHang)) {
299 if (data.IsPressed(kIntakeIn)) {
300 arm_goal_position_ = arm::SelfHangIndex();
301 } else if (data.IsPressed(kIntakeOut)) {
302 arm_goal_position_ = arm::PartnerHangIndex();
303 } else {
304 arm_goal_position_ = arm::AboveHangIndex();
305 }
306 } else if (data.IsPressed(kArmBelowHang)) {
307 arm_goal_position_ = arm::BelowHangIndex();
Neil Balch07fee582018-01-27 15:46:49 -0800308 }
309
Austin Schuhd76546a2018-07-08 16:05:14 -0700310 if (data.IsPressed(kEmergencyDown)) {
311 arm_goal_position_ = arm::NeutralIndex();
312 new_superstructure_goal->trajectory_override = true;
313 } else if (data.IsPressed(kEmergencyUp)) {
314 arm_goal_position_ = arm::UpIndex();
315 new_superstructure_goal->trajectory_override = true;
316 } else {
317 new_superstructure_goal->trajectory_override = false;
318 }
319
Austin Schuh17e484e2018-03-11 01:11:36 -0800320 new_superstructure_goal->deploy_fork =
321 data.IsPressed(kArmAboveHang) && data.IsPressed(kClawOpen);
322
323 if (new_superstructure_goal->deploy_fork) {
324 intake_goal_ = -2.0;
325 }
326
327 if (data.IsPressed(kWinch)) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700328 LOG(INFO, "Winching\n");
Austin Schuh17e484e2018-03-11 01:11:36 -0800329 new_superstructure_goal->voltage_winch = 12.0;
330 } else {
331 new_superstructure_goal->voltage_winch = 0.0;
332 }
333
334 new_superstructure_goal->hook_release = data.IsPressed(kArmBelowHang);
335
Austin Schuhcb091712018-02-21 20:01:55 -0800336 new_superstructure_goal->arm_goal_position = arm_goal_position_;
Austin Schuhd76546a2018-07-08 16:05:14 -0700337 if (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)) {
338 new_superstructure_goal->open_threshold = 0.35;
339 } else {
340 new_superstructure_goal->open_threshold = 0.0;
341 }
Austin Schuhcb091712018-02-21 20:01:55 -0800342
Neil Balchba9cbba2018-04-06 22:26:38 -0700343 if ((data.IsPressed(kClawOpen) && data.IsPressed(kDriverClawOpen)) ||
Austin Schuhd76546a2018-07-08 16:05:14 -0700344 data.PosEdge(kArmPickupBoxFromIntake) ||
345 (data.IsPressed(kClawOpen) &&
346 (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)))) {
Neil Balch07fee582018-01-27 15:46:49 -0800347 new_superstructure_goal->open_claw = true;
Austin Schuhab15c4d2018-03-09 21:21:03 -0800348 } else {
Neil Balch07fee582018-01-27 15:46:49 -0800349 new_superstructure_goal->open_claw = false;
350 }
351
Austin Schuhab15c4d2018-03-09 21:21:03 -0800352 new_superstructure_goal->grab_box = grab_box;
Neil Balch07fee582018-01-27 15:46:49 -0800353
354 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
355 if (!new_superstructure_goal.Send()) {
356 LOG(ERROR, "Sending superstructure goal failed.\n");
357 }
Austin Schuh8d5fff42018-05-30 20:44:12 -0700358
Austin Schuha8de4a62018-09-03 18:04:28 -0700359 video_tx_->Send(vision_control_);
Neil Balchacfca5b2018-01-28 14:04:08 -0800360 }
361
362 private:
Austin Schuha3c148e2018-03-09 21:04:05 -0800363 void StartAuto() {
364 LOG(INFO, "Starting auto mode\n");
365
366 ::frc971::autonomous::AutonomousActionParams params;
367 ::frc971::autonomous::auto_mode.FetchLatest();
368 if (::frc971::autonomous::auto_mode.get() != nullptr) {
Austin Schuhc231df42018-03-21 20:43:24 -0700369 params.mode = ::frc971::autonomous::auto_mode->mode << 2;
Austin Schuha3c148e2018-03-09 21:04:05 -0800370 } else {
371 LOG(WARNING, "no auto mode values\n");
372 params.mode = 0;
373 }
Austin Schuh3e45c752019-02-02 12:19:11 -0800374 // Low bit is switch, high bit is scale. 1 means left, 0 means right.
375 params.mode = mode();
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);
Austin Schuh3e45c752019-02-02 12:19:11 -0800411 ::aos::ShmEventLoop event_loop;
412 ::y2018::input::joysticks::Reader reader(&event_loop);
Neil Balchacfca5b2018-01-28 14:04:08 -0800413 reader.Run();
414 ::aos::Cleanup();
415}