blob: eb231964ab0da904bd2358bfc6b03350fd567edf [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"
Austin Schuha250b2d2019-05-27 16:14:02 -070016#include "aos/input/action_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;
Austin Schuh8d5fff42018-05-30 20:44:12 -070029using ::aos::events::ProtoTXUdpSocket;
30using ::aos::events::RXUdpSocket;
Neil Balchacfca5b2018-01-28 14:04:08 -080031using ::aos::input::driver_station::ButtonLocation;
32using ::aos::input::driver_station::ControlBit;
33using ::aos::input::driver_station::JoystickAxis;
34using ::aos::input::driver_station::POVLocation;
35using ::aos::input::DrivetrainInputReader;
36
Austin Schuh60cdb3e2018-04-06 21:52:32 -070037using ::y2018::control_loops::superstructure::arm::FrontPoints;
38using ::y2018::control_loops::superstructure::arm::BackPoints;
39
Neil Balchacfca5b2018-01-28 14:04:08 -080040namespace y2018 {
41namespace input {
42namespace joysticks {
43
Austin Schuhab15c4d2018-03-09 21:21:03 -080044namespace arm = ::y2018::control_loops::superstructure::arm;
Austin Schuha8de4a62018-09-03 18:04:28 -070045using google::protobuf::StringPrintf;
Neil Balch07fee582018-01-27 15:46:49 -080046
Sabina Davis833ccf62018-04-06 20:52:31 -070047const ButtonLocation kIntakeClosed(3, 2);
48const ButtonLocation kDuck(3, 9);
49const ButtonLocation kSmallBox(3, 1);
Austin Schuh47d74942018-03-04 01:15:59 -080050
Sabina Davis833ccf62018-04-06 20:52:31 -070051const ButtonLocation kIntakeIn(3, 4);
52const ButtonLocation kIntakeOut(3, 3);
Neil Balch07fee582018-01-27 15:46:49 -080053
Austin Schuha8de4a62018-09-03 18:04:28 -070054const ButtonLocation kArmBackHighBox(4, 11);
55const ButtonLocation kArmBackExtraHighBox(4, 1);
56const ButtonLocation kArmBackMiddle2Box(4, 9);
57const ButtonLocation kArmBackMiddle1Box(4, 7);
58const ButtonLocation kArmBackLowBox(4, 5);
59const ButtonLocation kArmBackSwitch(3, 7);
Austin Schuhab15c4d2018-03-09 21:21:03 -080060
Austin Schuha8de4a62018-09-03 18:04:28 -070061const ButtonLocation kArmFrontHighBox(4, 12);
62const ButtonLocation kArmFrontExtraHighBox(3, 14);
63const ButtonLocation kArmFrontMiddle2Box(4, 10);
64const ButtonLocation kArmFrontMiddle1Box(4, 8);
65const ButtonLocation kArmFrontLowBox(4, 6);
66const ButtonLocation kArmFrontSwitch(3, 10);
Austin Schuhab15c4d2018-03-09 21:21:03 -080067
Sabina Davis833ccf62018-04-06 20:52:31 -070068const ButtonLocation kArmAboveHang(3, 15);
69const ButtonLocation kArmBelowHang(3, 16);
Austin Schuh17e484e2018-03-11 01:11:36 -080070
Austin Schuhd76546a2018-07-08 16:05:14 -070071const ButtonLocation kEmergencyUp(3, 5);
72const ButtonLocation kEmergencyDown(3, 6);
73
Sabina Davis833ccf62018-04-06 20:52:31 -070074const ButtonLocation kWinch(4, 2);
Austin Schuh17e484e2018-03-11 01:11:36 -080075
Sabina Davis833ccf62018-04-06 20:52:31 -070076const ButtonLocation kArmNeutral(3, 8);
77const ButtonLocation kArmUp(3, 11);
Austin Schuhab15c4d2018-03-09 21:21:03 -080078
Sabina Davis833ccf62018-04-06 20:52:31 -070079const ButtonLocation kArmStepUp(3, 13);
80const ButtonLocation kArmStepDown(3, 12);
Austin Schuhab15c4d2018-03-09 21:21:03 -080081
Sabina Davis833ccf62018-04-06 20:52:31 -070082const ButtonLocation kArmPickupBoxFromIntake(4, 3);
83
84const ButtonLocation kClawOpen(4, 4);
Neil Balchba9cbba2018-04-06 22:26:38 -070085const ButtonLocation kDriverClawOpen(2, 4);
Neil Balch07fee582018-01-27 15:46:49 -080086
Austin Schuha250b2d2019-05-27 16:14:02 -070087class Reader : public ::aos::input::ActionJoystickInput {
Neil Balchacfca5b2018-01-28 14:04:08 -080088 public:
Austin Schuh3e45c752019-02-02 12:19:11 -080089 Reader(::aos::EventLoop *event_loop)
Austin Schuha250b2d2019-05-27 16:14:02 -070090 : ::aos::input::ActionJoystickInput(
91 event_loop,
92 ::y2018::control_loops::drivetrain::GetDrivetrainConfig(),
93 ::aos::network::GetTeamNumber() == 971
94 ? DrivetrainInputReader::InputType::kPistol
95 : DrivetrainInputReader::InputType::kSteeringWheel,
Austin Schuhd845c972019-06-29 21:20:05 -070096 {}),
97 superstructure_position_fetcher_(
98 event_loop->MakeFetcher<
99 ::y2018::control_loops::SuperstructureQueue::Position>(
100 ".frc971.control_loops.superstructure_queue.position")),
101 superstructure_status_fetcher_(
102 event_loop->MakeFetcher<
103 ::y2018::control_loops::SuperstructureQueue::Status>(
104 ".frc971.control_loops.superstructure_queue.status")),
105 superstructure_goal_sender_(
106 event_loop
107 ->MakeSender<::y2018::control_loops::SuperstructureQueue::Goal>(
108 ".frc971.control_loops.superstructure_queue.goal")) {
Austin Schuha8de4a62018-09-03 18:04:28 -0700109 const uint16_t team = ::aos::network::GetTeamNumber();
110
Austin Schuha8de4a62018-09-03 18:04:28 -0700111 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
112 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Neil Balchacfca5b2018-01-28 14:04:08 -0800113 }
114
Austin Schuha250b2d2019-05-27 16:14:02 -0700115 void HandleTeleop(const ::aos::input::driver_station::Data &data) override {
Austin Schuhd845c972019-06-29 21:20:05 -0700116 superstructure_position_fetcher_.Fetch();
117 superstructure_status_fetcher_.Fetch();
118 if (!superstructure_status_fetcher_.get() ||
119 !superstructure_position_fetcher_.get()) {
Neil Balch07fee582018-01-27 15:46:49 -0800120 LOG(ERROR, "Got no superstructure status packet.\n");
121 return;
122 }
123
Austin Schuhd845c972019-06-29 21:20:05 -0700124 auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage();
Neil Balch07fee582018-01-27 15:46:49 -0800125
Sabina Davisfdd7a112018-02-04 16:16:23 -0800126 new_superstructure_goal->intake.left_intake_angle = intake_goal_;
127 new_superstructure_goal->intake.right_intake_angle = intake_goal_;
Neil Balch07fee582018-01-27 15:46:49 -0800128
Austin Schuh8d5fff42018-05-30 20:44:12 -0700129 if (data.PosEdge(kIntakeIn) || data.PosEdge(kSmallBox) ||
130 data.PosEdge(kIntakeClosed)) {
131 vision_control_.set_high_video(false);
132 }
133
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700134 if (data.IsPressed(kIntakeIn)) {
Neil Balch07fee582018-01-27 15:46:49 -0800135 // Turn on the rollers.
Neil Balchba9cbba2018-04-06 22:26:38 -0700136 new_superstructure_goal->intake.roller_voltage = 8.0;
Neil Balch07fee582018-01-27 15:46:49 -0800137 } else if (data.IsPressed(kIntakeOut)) {
138 // Turn off the rollers.
Austin Schuh17dd0892018-03-02 20:06:31 -0800139 new_superstructure_goal->intake.roller_voltage = -12.0;
Neil Balch07fee582018-01-27 15:46:49 -0800140 } else {
141 // We don't want the rollers on.
142 new_superstructure_goal->intake.roller_voltage = 0.0;
143 }
144
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700145 if (data.IsPressed(kSmallBox)) {
146 // Deploy the intake.
Austin Schuhd845c972019-06-29 21:20:05 -0700147 if (superstructure_position_fetcher_->box_back_beambreak_triggered) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700148 intake_goal_ = 0.30;
149 } else {
150 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
Austin Schuhd845c972019-06-29 21:20:05 -0700151 superstructure_position_fetcher_->box_distance < 0.15) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700152 intake_goal_ = 0.18;
153 } else {
154 intake_goal_ = -0.60;
155 }
156 }
157 } else if (data.IsPressed(kIntakeClosed)) {
158 // Deploy the intake.
Austin Schuhd845c972019-06-29 21:20:05 -0700159 if (superstructure_position_fetcher_->box_back_beambreak_triggered) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700160 intake_goal_ = 0.30;
161 } else {
162 if (new_superstructure_goal->intake.roller_voltage > 0.1) {
Austin Schuhd845c972019-06-29 21:20:05 -0700163 if (superstructure_position_fetcher_->box_distance < 0.10) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700164 new_superstructure_goal->intake.roller_voltage -= 3.0;
165 intake_goal_ = 0.22;
Austin Schuhd845c972019-06-29 21:20:05 -0700166 } else if (superstructure_position_fetcher_->box_distance < 0.17) {
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700167 intake_goal_ = 0.13;
Austin Schuhd845c972019-06-29 21:20:05 -0700168 } else if (superstructure_position_fetcher_->box_distance < 0.25) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700169 intake_goal_ = 0.05;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700170 } else {
Neil Balchba9cbba2018-04-06 22:26:38 -0700171 intake_goal_ = -0.10;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700172 }
Austin Schuha250b2d2019-05-27 16:14:02 -0700173 if (robot_velocity() < -0.1 &&
Austin Schuhd845c972019-06-29 21:20:05 -0700174 superstructure_position_fetcher_->box_distance > 0.15) {
Austin Schuhcf96d322018-04-07 15:52:31 -0700175 intake_goal_ += 0.10;
176 }
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700177 } else {
178 intake_goal_ = -0.60;
179 }
180 }
181 } else {
182 // Bring in the intake.
Austin Schuhcf96d322018-04-07 15:52:31 -0700183 intake_goal_ = -3.20;
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700184 }
185
Neil Balchba9cbba2018-04-06 22:26:38 -0700186 if (new_superstructure_goal->intake.roller_voltage > 0.1 &&
187 intake_goal_ > 0.0) {
Austin Schuhd845c972019-06-29 21:20:05 -0700188 if (superstructure_position_fetcher_->box_distance < 0.10) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700189 new_superstructure_goal->intake.roller_voltage -= 3.0;
190 }
191 new_superstructure_goal->intake.roller_voltage += 3.0;
192 }
193
Austin Schuhb874fd32018-03-05 00:27:10 -0800194 // If we are disabled, stay at the node closest to where we start. This
195 // should remove long motions when enabled.
Neil Balchba9cbba2018-04-06 22:26:38 -0700196 if (!data.GetControlBit(ControlBit::kEnabled) || never_disabled_) {
Austin Schuhd845c972019-06-29 21:20:05 -0700197 arm_goal_position_ = superstructure_status_fetcher_->arm.current_node;
Neil Balchba9cbba2018-04-06 22:26:38 -0700198 never_disabled_ = false;
Austin Schuhb874fd32018-03-05 00:27:10 -0800199 }
200
Austin Schuhab15c4d2018-03-09 21:21:03 -0800201 bool grab_box = false;
202 if (data.IsPressed(kArmPickupBoxFromIntake)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800203 grab_box = true;
Neil Balchba9cbba2018-04-06 22:26:38 -0700204 }
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700205 const bool near_goal =
Austin Schuhd845c972019-06-29 21:20:05 -0700206 superstructure_status_fetcher_->arm.current_node ==
207 arm_goal_position_ &&
208 superstructure_status_fetcher_->arm.path_distance_to_go < 1e-3;
Austin Schuh822a1e52018-04-06 22:50:21 -0700209 if (data.IsPressed(kArmStepDown) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700210 uint32_t *front_point = ::std::find(
211 front_points_.begin(), front_points_.end(), arm_goal_position_);
212 uint32_t *back_point = ::std::find(
213 back_points_.begin(), back_points_.end(), arm_goal_position_);
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700214 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700215 ++front_point;
216 if (front_point != front_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700217 arm_goal_position_ = *front_point;
218 }
219 } else if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700220 ++back_point;
221 if (back_point != back_points_.end()) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700222 arm_goal_position_ = *back_point;
223 }
224 }
Austin Schuh822a1e52018-04-06 22:50:21 -0700225 } else if (data.IsPressed(kArmStepUp) && near_goal) {
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700226 const uint32_t *front_point = ::std::find(
227 front_points_.begin(), front_points_.end(), arm_goal_position_);
228 const uint32_t *back_point = ::std::find(
229 back_points_.begin(), back_points_.end(), arm_goal_position_);
230 if (front_point != front_points_.end()) {
231 if (front_point != front_points_.begin()) {
232 --front_point;
233 arm_goal_position_ = *front_point;
234 }
235 } else if (back_point != back_points_.end()) {
236 if (back_point != back_points_.begin()) {
237 --back_point;
238 arm_goal_position_ = *back_point;
239 }
240 }
241 } else if (data.PosEdge(kArmPickupBoxFromIntake)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700242 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700243 arm_goal_position_ = arm::NeutralIndex();
244 } else if (data.IsPressed(kDuck)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700245 vision_control_.set_high_video(false);
Neil Balchba9cbba2018-04-06 22:26:38 -0700246 arm_goal_position_ = arm::DuckIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800247 } else if (data.IsPressed(kArmNeutral)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700248 vision_control_.set_high_video(false);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800249 arm_goal_position_ = arm::NeutralIndex();
250 } else if (data.IsPressed(kArmUp)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700251 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800252 arm_goal_position_ = arm::UpIndex();
253 } else if (data.IsPressed(kArmFrontSwitch)) {
254 arm_goal_position_ = arm::FrontSwitchIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700255 } else if (data.IsPressed(kArmFrontExtraHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700256 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800257 arm_goal_position_ = arm::FrontHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700258 } else if (data.IsPressed(kArmFrontHighBox)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700259 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800260 arm_goal_position_ = arm::FrontMiddle2BoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700261 } else if (data.IsPressed(kArmFrontMiddle2Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700262 vision_control_.set_high_video(true);
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700263 arm_goal_position_ = arm::FrontMiddle3BoxIndex();
Austin Schuhab15c4d2018-03-09 21:21:03 -0800264 } else if (data.IsPressed(kArmFrontMiddle1Box)) {
Austin Schuh8d5fff42018-05-30 20:44:12 -0700265 vision_control_.set_high_video(true);
Austin Schuhab15c4d2018-03-09 21:21:03 -0800266 arm_goal_position_ = arm::FrontMiddle1BoxIndex();
267 } else if (data.IsPressed(kArmFrontLowBox)) {
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::FrontLowBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700270 } else if (data.IsPressed(kArmBackExtraHighBox)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800271 arm_goal_position_ = arm::BackHighBoxIndex();
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700272 } else if (data.IsPressed(kArmBackHighBox) ||
273 data.IsPressed(kArmBackMiddle2Box)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800274 arm_goal_position_ = arm::BackMiddle2BoxIndex();
275 } else if (data.IsPressed(kArmBackMiddle1Box)) {
276 arm_goal_position_ = arm::BackMiddle1BoxIndex();
277 } else if (data.IsPressed(kArmBackLowBox)) {
278 arm_goal_position_ = arm::BackLowBoxIndex();
Austin Schuhd845c972019-06-29 21:20:05 -0700279 } else if (data.IsPressed(kArmBackSwitch)) {
Austin Schuhab15c4d2018-03-09 21:21:03 -0800280 arm_goal_position_ = arm::BackSwitchIndex();
Austin Schuh17e484e2018-03-11 01:11:36 -0800281 } else if (data.IsPressed(kArmAboveHang)) {
282 if (data.IsPressed(kIntakeIn)) {
283 arm_goal_position_ = arm::SelfHangIndex();
284 } else if (data.IsPressed(kIntakeOut)) {
285 arm_goal_position_ = arm::PartnerHangIndex();
286 } else {
287 arm_goal_position_ = arm::AboveHangIndex();
288 }
289 } else if (data.IsPressed(kArmBelowHang)) {
290 arm_goal_position_ = arm::BelowHangIndex();
Neil Balch07fee582018-01-27 15:46:49 -0800291 }
292
Austin Schuhd76546a2018-07-08 16:05:14 -0700293 if (data.IsPressed(kEmergencyDown)) {
294 arm_goal_position_ = arm::NeutralIndex();
295 new_superstructure_goal->trajectory_override = true;
296 } else if (data.IsPressed(kEmergencyUp)) {
297 arm_goal_position_ = arm::UpIndex();
298 new_superstructure_goal->trajectory_override = true;
299 } else {
300 new_superstructure_goal->trajectory_override = false;
301 }
302
Austin Schuh17e484e2018-03-11 01:11:36 -0800303 new_superstructure_goal->deploy_fork =
304 data.IsPressed(kArmAboveHang) && data.IsPressed(kClawOpen);
305
306 if (new_superstructure_goal->deploy_fork) {
307 intake_goal_ = -2.0;
308 }
309
310 if (data.IsPressed(kWinch)) {
Neil Balchba9cbba2018-04-06 22:26:38 -0700311 LOG(INFO, "Winching\n");
Austin Schuh17e484e2018-03-11 01:11:36 -0800312 new_superstructure_goal->voltage_winch = 12.0;
313 } else {
314 new_superstructure_goal->voltage_winch = 0.0;
315 }
316
317 new_superstructure_goal->hook_release = data.IsPressed(kArmBelowHang);
318
Austin Schuhcb091712018-02-21 20:01:55 -0800319 new_superstructure_goal->arm_goal_position = arm_goal_position_;
Austin Schuhd76546a2018-07-08 16:05:14 -0700320 if (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)) {
321 new_superstructure_goal->open_threshold = 0.35;
322 } else {
323 new_superstructure_goal->open_threshold = 0.0;
324 }
Austin Schuhcb091712018-02-21 20:01:55 -0800325
Neil Balchba9cbba2018-04-06 22:26:38 -0700326 if ((data.IsPressed(kClawOpen) && data.IsPressed(kDriverClawOpen)) ||
Austin Schuhd76546a2018-07-08 16:05:14 -0700327 data.PosEdge(kArmPickupBoxFromIntake) ||
328 (data.IsPressed(kClawOpen) &&
329 (data.IsPressed(kArmFrontSwitch) || data.IsPressed(kArmBackSwitch)))) {
Neil Balch07fee582018-01-27 15:46:49 -0800330 new_superstructure_goal->open_claw = true;
Austin Schuhab15c4d2018-03-09 21:21:03 -0800331 } else {
Neil Balch07fee582018-01-27 15:46:49 -0800332 new_superstructure_goal->open_claw = false;
333 }
334
Austin Schuhab15c4d2018-03-09 21:21:03 -0800335 new_superstructure_goal->grab_box = grab_box;
Neil Balch07fee582018-01-27 15:46:49 -0800336
337 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
338 if (!new_superstructure_goal.Send()) {
339 LOG(ERROR, "Sending superstructure goal failed.\n");
340 }
Austin Schuh8d5fff42018-05-30 20:44:12 -0700341
Austin Schuha8de4a62018-09-03 18:04:28 -0700342 video_tx_->Send(vision_control_);
Neil Balchacfca5b2018-01-28 14:04:08 -0800343 }
344
345 private:
Austin Schuha250b2d2019-05-27 16:14:02 -0700346 uint32_t GetAutonomousMode() override {
Austin Schuh3e45c752019-02-02 12:19:11 -0800347 // Low bit is switch, high bit is scale. 1 means left, 0 means right.
Austin Schuha250b2d2019-05-27 16:14:02 -0700348 return mode();
Neil Balchacfca5b2018-01-28 14:04:08 -0800349 }
350
Austin Schuhd845c972019-06-29 21:20:05 -0700351 ::aos::Fetcher<::y2018::control_loops::SuperstructureQueue::Position>
352 superstructure_position_fetcher_;
353 ::aos::Fetcher<::y2018::control_loops::SuperstructureQueue::Status>
354 superstructure_status_fetcher_;
355 ::aos::Sender<::y2018::control_loops::SuperstructureQueue::Goal>
356 superstructure_goal_sender_;
357
Neil Balch07fee582018-01-27 15:46:49 -0800358 // Current goals to send to the robot.
Austin Schuh17e484e2018-03-11 01:11:36 -0800359 double intake_goal_ = 0.0;
Neil Balch07fee582018-01-27 15:46:49 -0800360
Neil Balchba9cbba2018-04-06 22:26:38 -0700361 bool never_disabled_ = true;
Neil Balchacfca5b2018-01-28 14:04:08 -0800362
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700363 uint32_t arm_goal_position_ = 0;
Austin Schuh8d5fff42018-05-30 20:44:12 -0700364 VisionControl vision_control_;
Austin Schuh60cdb3e2018-04-06 21:52:32 -0700365
366 decltype(FrontPoints()) front_points_ = FrontPoints();
367 decltype(BackPoints()) back_points_ = BackPoints();
Austin Schuhcb091712018-02-21 20:01:55 -0800368
Austin Schuha8de4a62018-09-03 18:04:28 -0700369 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Neil Balchacfca5b2018-01-28 14:04:08 -0800370};
371
372} // namespace joysticks
373} // namespace input
374} // namespace y2018
375
376int main() {
377 ::aos::Init(-1);
Austin Schuh3e45c752019-02-02 12:19:11 -0800378 ::aos::ShmEventLoop event_loop;
379 ::y2018::input::joysticks::Reader reader(&event_loop);
Neil Balchacfca5b2018-01-28 14:04:08 -0800380 reader.Run();
381 ::aos::Cleanup();
382}