blob: c0113c3352ac273c8b5e784830bfac07cfa6bff0 [file] [log] [blame]
Campbell Crowley71b5f132017-02-18 13:16:08 -08001#include <stdio.h>
2#include <string.h>
3#include <unistd.h>
4#include <math.h>
5
Austin Schuh3028b1d2017-03-11 22:12:13 -08006#include "aos/common/actions/actions.h"
Campbell Crowley71b5f132017-02-18 13:16:08 -08007#include "aos/common/input/driver_station_data.h"
8#include "aos/common/logging/logging.h"
Campbell Crowley71b5f132017-02-18 13:16:08 -08009#include "aos/common/time.h"
Austin Schuh3028b1d2017-03-11 22:12:13 -080010#include "aos/common/util/log_interval.h"
11#include "aos/input/joystick_input.h"
12#include "aos/linux_code/init.h"
Campbell Crowley71b5f132017-02-18 13:16:08 -080013#include "frc971/autonomous/auto.q.h"
Austin Schuh3028b1d2017-03-11 22:12:13 -080014#include "frc971/autonomous/base_autonomous_actor.h"
15#include "frc971/control_loops/drivetrain/drivetrain.q.h"
16#include "y2017/constants.h"
17#include "y2017/control_loops/superstructure/superstructure.q.h"
Campbell Crowley71b5f132017-02-18 13:16:08 -080018
19using ::frc971::control_loops::drivetrain_queue;
20using ::y2017::control_loops::superstructure_queue;
21
22using ::aos::input::driver_station::ButtonLocation;
23using ::aos::input::driver_station::ControlBit;
24using ::aos::input::driver_station::JoystickAxis;
25using ::aos::input::driver_station::POVLocation;
26
27namespace y2017 {
28namespace input {
29namespace joysticks {
30
Austin Schuh51b1bae2017-04-09 18:31:57 -070031// Keep the other versions around so we can switch quickly.
32//#define STEERINGWHEEL
33#define PISTOL
34//#define XBOX
35
36#ifdef STEERINGWHEEL
Campbell Crowley71b5f132017-02-18 13:16:08 -080037const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2);
38const ButtonLocation kQuickTurn(1, 5);
Campbell Crowley71b5f132017-02-18 13:16:08 -080039const ButtonLocation kTurn1(1, 7);
40const ButtonLocation kTurn2(1, 11);
41
Austin Schuh51b1bae2017-04-09 18:31:57 -070042#endif
43
44#ifdef PISTOL
45// Pistol Grip controller
Austin Schuh8ace3802017-04-16 19:19:33 -070046const JoystickAxis kSteeringWheel(1, 2), kDriveThrottle(1, 1);
47const ButtonLocation kQuickTurn(1, 7);
48const ButtonLocation kTurn1(1, 8);
Austin Schuh51b1bae2017-04-09 18:31:57 -070049
50// Nop
Austin Schuh51b1bae2017-04-09 18:31:57 -070051const ButtonLocation kTurn2(1, 9);
Austin Schuh51b1bae2017-04-09 18:31:57 -070052#endif
53
54#ifdef XBOX
55// xbox
56const JoystickAxis kSteeringWheel(1, 5), kDriveThrottle(1, 2);
57const ButtonLocation kQuickTurn(1, 5);
58
59// Nop
60const ButtonLocation kTurn1(1, 1);
61const ButtonLocation kTurn2(1, 2);
62
63#endif
64
65
Austin Schuh55c8d302017-04-05 19:25:37 -070066const ButtonLocation kGearSlotBack(2, 11);
67
Campbell Crowley71b5f132017-02-18 13:16:08 -080068const ButtonLocation kIntakeDown(3, 9);
Austin Schuhd0629b12017-03-22 22:37:16 -070069const POVLocation kIntakeUp(3, 90);
Campbell Crowley71b5f132017-02-18 13:16:08 -080070const ButtonLocation kIntakeIn(3, 12);
71const ButtonLocation kIntakeOut(3, 8);
Campbell Crowley71b5f132017-02-18 13:16:08 -080072const ButtonLocation kFire(3, 3);
Parker Schuh208a58d2017-04-12 20:51:38 -070073const ButtonLocation kVisionDistanceShot(3, 7);
Campbell Crowley71b5f132017-02-18 13:16:08 -080074const ButtonLocation kMiddleShot(3, 6);
75const POVLocation kFarShot(3, 270);
76
77const ButtonLocation kVisionAlign(3, 5);
78
79const ButtonLocation kReverseIndexer(3, 4);
80const ButtonLocation kExtra1(3, 11);
81const ButtonLocation kExtra2(3, 10);
Austin Schuhd0629b12017-03-22 22:37:16 -070082const ButtonLocation kHang(3, 2);
Campbell Crowley71b5f132017-02-18 13:16:08 -080083
84class Reader : public ::aos::input::JoystickInput {
85 public:
86 Reader() {}
87
Parker Schuh208a58d2017-04-12 20:51:38 -070088 enum class ShotDistance { VISION_SHOT, MIDDLE_SHOT, FAR_SHOT };
Austin Schuhd0629b12017-03-22 22:37:16 -070089
Austin Schuh4b5f7df2017-04-16 20:31:12 -070090 ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT;
Austin Schuhd0629b12017-03-22 22:37:16 -070091
Campbell Crowley71b5f132017-02-18 13:16:08 -080092 void RunIteration(const ::aos::input::driver_station::Data &data) override {
93 bool last_auto_running = auto_running_;
94 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
95 data.GetControlBit(ControlBit::kEnabled);
96 if (auto_running_ != last_auto_running) {
97 if (auto_running_) {
98 StartAuto();
99 } else {
100 StopAuto();
101 }
102 }
103
Campbell Crowley71b5f132017-02-18 13:16:08 -0800104 if (!auto_running_) {
105 HandleDrivetrain(data);
106 HandleTeleop(data);
107 }
108
109 // Process any pending actions.
110 action_queue_.Tick();
111 was_running_ = action_queue_.Running();
112 }
Austin Schuhd0629b12017-03-22 22:37:16 -0700113 int intake_accumulator_ = 0;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800114
Austin Schuh51b1bae2017-04-09 18:31:57 -0700115 double Deadband(double value, const double deadband) {
116 if (::std::abs(value) < deadband) {
117 value = 0.0;
118 } else if (value > 0.0) {
119 value = (value - deadband) / (1.0 - deadband);
120 } else {
121 value = (value + deadband) / (1.0 - deadband);
122 }
123 return value;
124 }
125
Campbell Crowley71b5f132017-02-18 13:16:08 -0800126 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
127 bool is_control_loop_driving = false;
128
Austin Schuh51b1bae2017-04-09 18:31:57 -0700129#ifdef STEERINGWHEEL
Campbell Crowley71b5f132017-02-18 13:16:08 -0800130 const double wheel = -data.GetAxis(kSteeringWheel);
131 const double throttle = -data.GetAxis(kDriveThrottle);
Austin Schuh51b1bae2017-04-09 18:31:57 -0700132#endif
133
134#ifdef XBOX
135 // xbox
136 constexpr double kWheelDeadband = 0.05;
137 constexpr double kThrottleDeadband = 0.05;
138 const double wheel =
139 Deadband(-data.GetAxis(kSteeringWheel), kWheelDeadband);
140
141 const double unmodified_throttle =
142 Deadband(-data.GetAxis(kDriveThrottle), kThrottleDeadband);
143
144 // Apply a sin function that's scaled to make it feel better.
145 constexpr double throttle_range = M_PI_2 * 0.9;
146
147 double throttle = ::std::sin(throttle_range * unmodified_throttle) /
148 ::std::sin(throttle_range);
149 throttle =
150 ::std::sin(throttle_range * throttle) / ::std::sin(throttle_range);
151 throttle = 2.0 * unmodified_throttle - throttle;
152#endif
153
154#ifdef PISTOL
Austin Schuh8ace3802017-04-16 19:19:33 -0700155 const double unscaled_wheel = data.GetAxis(kSteeringWheel);
156 double wheel;
157 if (unscaled_wheel < 0.0) {
158 wheel = unscaled_wheel / 0.484375;
159 } else {
160 wheel = unscaled_wheel / 0.385827;
161 }
Austin Schuh51b1bae2017-04-09 18:31:57 -0700162
163 const double unscaled_throttle = -data.GetAxis(kDriveThrottle);
164 double unmodified_throttle;
165 if (unscaled_throttle < 0.0) {
Austin Schuh8ace3802017-04-16 19:19:33 -0700166 unmodified_throttle = unscaled_throttle / 0.086614;
Austin Schuh51b1bae2017-04-09 18:31:57 -0700167 } else {
Austin Schuh8ace3802017-04-16 19:19:33 -0700168 unmodified_throttle = unscaled_throttle / 0.265625;
Austin Schuh51b1bae2017-04-09 18:31:57 -0700169 }
170 unmodified_throttle = Deadband(unmodified_throttle, 0.1);
171
172 // Apply a sin function that's scaled to make it feel better.
173 constexpr double throttle_range = M_PI_2 * 0.5;
174
175 double throttle = ::std::sin(throttle_range * unmodified_throttle) /
176 ::std::sin(throttle_range);
177 throttle =
178 ::std::sin(throttle_range * throttle) / ::std::sin(throttle_range);
179 throttle = 2.0 * unmodified_throttle - throttle;
180#endif
181
Campbell Crowley71b5f132017-02-18 13:16:08 -0800182 drivetrain_queue.status.FetchLatest();
Austin Schuhd0629b12017-03-22 22:37:16 -0700183 if (drivetrain_queue.status.get()) {
184 robot_velocity_ = drivetrain_queue.status->robot_speed;
185 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800186
Austin Schuh55c8d302017-04-05 19:25:37 -0700187 if (data.PosEdge(kTurn1) || data.PosEdge(kTurn2) ||
188 data.PosEdge(kGearSlotBack)) {
Campbell Crowley71b5f132017-02-18 13:16:08 -0800189 if (drivetrain_queue.status.get()) {
190 left_goal_ = drivetrain_queue.status->estimated_left_position;
191 right_goal_ = drivetrain_queue.status->estimated_right_position;
192 }
193 }
Austin Schuh51b1bae2017-04-09 18:31:57 -0700194#ifdef PISTOL
195 double current_left_goal = left_goal_ - wheel * 0.20 + throttle * 0.3;
196 double current_right_goal = right_goal_ + wheel * 0.20 + throttle * 0.3;
197#else
Austin Schuh55c8d302017-04-05 19:25:37 -0700198 double current_left_goal = left_goal_ - wheel * 0.5 + throttle * 0.3;
199 double current_right_goal = right_goal_ + wheel * 0.5 + throttle * 0.3;
Austin Schuh51b1bae2017-04-09 18:31:57 -0700200#endif
Campbell Crowley71b5f132017-02-18 13:16:08 -0800201 if (data.IsPressed(kTurn1) || data.IsPressed(kTurn2)) {
202 is_control_loop_driving = true;
203 }
Austin Schuh55c8d302017-04-05 19:25:37 -0700204 if (data.IsPressed(kGearSlotBack)) {
205 is_control_loop_driving = true;
206 current_left_goal = left_goal_ - 0.03;
207 current_right_goal = right_goal_ - 0.03;
208 }
209 auto new_drivetrain_goal = drivetrain_queue.goal.MakeMessage();
210 new_drivetrain_goal->steering = wheel;
211 new_drivetrain_goal->throttle = throttle;
212 new_drivetrain_goal->quickturn = data.IsPressed(kQuickTurn);
213 new_drivetrain_goal->control_loop_driving = is_control_loop_driving;
214 new_drivetrain_goal->left_goal = current_left_goal;
215 new_drivetrain_goal->right_goal = current_right_goal;
216 new_drivetrain_goal->left_velocity_goal = 0;
217 new_drivetrain_goal->right_velocity_goal = 0;
218
219 new_drivetrain_goal->linear.max_velocity = 3.0;
220 new_drivetrain_goal->linear.max_acceleration = 20.0;
221
222 if (!new_drivetrain_goal.Send()) {
Campbell Crowley71b5f132017-02-18 13:16:08 -0800223 LOG(WARNING, "sending stick values failed\n");
224 }
225 }
226
227 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
228 // Default the intake to in.
Austin Schuhd0629b12017-03-22 22:37:16 -0700229 intake_goal_ = 0.07;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800230 bool lights_on = false;
Austin Schuhd0629b12017-03-22 22:37:16 -0700231 bool vision_track = false;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800232
233 if (!data.GetControlBit(ControlBit::kEnabled)) {
234 action_queue_.CancelAllActions();
235 LOG(DEBUG, "Canceling\n");
236 }
237
238 superstructure_queue.status.FetchLatest();
239 if (!superstructure_queue.status.get()) {
240 LOG(ERROR, "Got no superstructure status packet.\n");
241 return;
242 }
243
Austin Schuhd0629b12017-03-22 22:37:16 -0700244 if (data.IsPressed(kIntakeUp)) {
245 intake_goal_ = 0.0;
Austin Schuh3ae47432017-04-16 19:15:46 -0700246 turret_goal_ = M_PI / 3.0;
Austin Schuhd0629b12017-03-22 22:37:16 -0700247 }
Austin Schuh405724e2017-04-09 18:34:18 -0700248 if (data.IsPressed(kIntakeDown)) {
249 intake_goal_ = 0.235;
250 // Don't go quite so far out since we have a gear mech out now.
251 if (data.IsPressed(kIntakeUp)) {
252 intake_goal_ = 0.160;
253 }
254 }
Austin Schuhd0629b12017-03-22 22:37:16 -0700255
Campbell Crowley71b5f132017-02-18 13:16:08 -0800256
257 if (data.IsPressed(kVisionAlign)) {
258 // Align shot using vision
259 // TODO(campbell): Add vision aligning.
Adam Snaidere0554ef2017-03-11 23:02:45 -0800260 lights_on = true;
Austin Schuhd0629b12017-03-22 22:37:16 -0700261 vision_track = true;
262 }
263 if (data.PosEdge(kMiddleShot)) {
264 turret_goal_ = -M_PI;
265 }
266 if (data.PosEdge(kFarShot)) {
267 turret_goal_ = 0.0;
268 }
Parker Schuh208a58d2017-04-12 20:51:38 -0700269 if (data.PosEdge(kVisionDistanceShot)) {
270 turret_goal_ = 0.0;
271 }
Austin Schuhd0629b12017-03-22 22:37:16 -0700272
Parker Schuh208a58d2017-04-12 20:51:38 -0700273 if (data.IsPressed(kVisionDistanceShot)) {
274 last_shot_distance_ = ShotDistance::VISION_SHOT;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800275 } else if (data.IsPressed(kMiddleShot)) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700276 last_shot_distance_ = ShotDistance::MIDDLE_SHOT;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800277 } else if (data.IsPressed(kFarShot)) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700278 last_shot_distance_ = ShotDistance::FAR_SHOT;
279 }
280
Parker Schuh208a58d2017-04-12 20:51:38 -0700281 if (data.IsPressed(kVisionAlign) ||
Austin Schuhd0629b12017-03-22 22:37:16 -0700282 data.IsPressed(kMiddleShot) || data.IsPressed(kFarShot) ||
283 data.IsPressed(kFire)) {
284 switch (last_shot_distance_) {
Parker Schuh208a58d2017-04-12 20:51:38 -0700285 case ShotDistance::VISION_SHOT:
Austin Schuh4b5f7df2017-04-16 20:31:12 -0700286 hood_goal_ = 0.10;
287 shooter_velocity_ = 300.0;
288
Parker Schuh208a58d2017-04-12 20:51:38 -0700289 vision_distance_shot_ = true;
Austin Schuhd0629b12017-03-22 22:37:16 -0700290 break;
291 case ShotDistance::MIDDLE_SHOT:
Austin Schuh405724e2017-04-09 18:34:18 -0700292 hood_goal_ = 0.43 - 0.00;
Austin Schuh4b5f7df2017-04-16 20:31:12 -0700293 shooter_velocity_ = 364.0;
Parker Schuh208a58d2017-04-12 20:51:38 -0700294 vision_distance_shot_ = false;
Austin Schuhd0629b12017-03-22 22:37:16 -0700295 break;
296 case ShotDistance::FAR_SHOT:
Austin Schuh4b5f7df2017-04-16 20:31:12 -0700297 hood_goal_ = 0.47;
298 shooter_velocity_ = 410.0;
Parker Schuh208a58d2017-04-12 20:51:38 -0700299 vision_distance_shot_ = false;
Austin Schuhd0629b12017-03-22 22:37:16 -0700300 break;
301 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800302 } else {
Austin Schuhd0629b12017-03-22 22:37:16 -0700303 //hood_goal_ = 0.15;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800304 shooter_velocity_ = 0.0;
305 }
306
307 if (data.IsPressed(kExtra1)) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700308 //turret_goal_ = -M_PI * 3.0 / 4.0;
309 turret_goal_ += 0.150;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800310 }
311 if (data.IsPressed(kExtra2)) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700312 //turret_goal_ = M_PI * 3.0 / 4.0;
313 turret_goal_ -= 0.150;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800314 }
Austin Schuhd0629b12017-03-22 22:37:16 -0700315 turret_goal_ = ::std::max(::std::min(turret_goal_, M_PI), -M_PI);
Campbell Crowley71b5f132017-02-18 13:16:08 -0800316
317 fire_ = data.IsPressed(kFire) && shooter_velocity_ != 0.0;
Austin Schuhd0629b12017-03-22 22:37:16 -0700318 if (data.IsPressed(kVisionAlign)) {
319 fire_ = fire_ && superstructure_queue.status->turret.vision_tracking;
320 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800321
322 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
Austin Schuhd0629b12017-03-22 22:37:16 -0700323 if (data.IsPressed(kHang)) {
324 intake_goal_ = 0.23;
325 }
326
Campbell Crowley71b5f132017-02-18 13:16:08 -0800327 new_superstructure_goal->intake.distance = intake_goal_;
Austin Schuh3028b1d2017-03-11 22:12:13 -0800328 new_superstructure_goal->intake.disable_intake = false;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800329 new_superstructure_goal->turret.angle = turret_goal_;
Austin Schuhd0629b12017-03-22 22:37:16 -0700330 new_superstructure_goal->turret.track = vision_track;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800331 new_superstructure_goal->hood.angle = hood_goal_;
332 new_superstructure_goal->shooter.angular_velocity = shooter_velocity_;
333
Austin Schuh6a8131b2017-04-08 15:39:22 -0700334 if (data.IsPressed(kIntakeUp)) {
Austin Schuhd6fa5e02017-04-12 20:52:17 -0700335 new_superstructure_goal->intake.gear_servo = 0.30;
Austin Schuh6a8131b2017-04-08 15:39:22 -0700336 } else {
337 // Clamp the gear
Austin Schuhd6fa5e02017-04-12 20:52:17 -0700338 new_superstructure_goal->intake.gear_servo = 0.66;
Austin Schuh6a8131b2017-04-08 15:39:22 -0700339 }
340
Campbell Crowley71b5f132017-02-18 13:16:08 -0800341 new_superstructure_goal->intake.profile_params.max_velocity = 0.50;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800342 new_superstructure_goal->hood.profile_params.max_velocity = 5.0;
343
Austin Schuh4b5f7df2017-04-16 20:31:12 -0700344 new_superstructure_goal->intake.profile_params.max_acceleration = 3.0;
Austin Schuhd0629b12017-03-22 22:37:16 -0700345 if (vision_track) {
346 new_superstructure_goal->turret.profile_params.max_acceleration = 35.0;
347 new_superstructure_goal->turret.profile_params.max_velocity = 10.0;
348 } else {
349 new_superstructure_goal->turret.profile_params.max_acceleration = 15.0;
350 new_superstructure_goal->turret.profile_params.max_velocity = 6.0;
351 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800352 new_superstructure_goal->hood.profile_params.max_acceleration = 25.0;
353
Austin Schuh3028b1d2017-03-11 22:12:13 -0800354 new_superstructure_goal->intake.voltage_rollers = 0.0;
Adam Snaidere0554ef2017-03-11 23:02:45 -0800355 new_superstructure_goal->lights_on = lights_on;
Austin Schuh3028b1d2017-03-11 22:12:13 -0800356
Parker Schuh208a58d2017-04-12 20:51:38 -0700357 if (data.IsPressed(kVisionAlign) && vision_distance_shot_) {
358 new_superstructure_goal->use_vision_for_shots = true;
359 } else {
360 new_superstructure_goal->use_vision_for_shots = false;
361 }
362
Austin Schuh8e4a7ee2017-04-05 19:26:06 -0700363 if (superstructure_queue.status->intake.position >
364 superstructure_queue.status->intake.unprofiled_goal_position + 0.01) {
365 intake_accumulator_ = 10;
366 }
367 if (intake_accumulator_ > 0) {
368 --intake_accumulator_;
369 if (!superstructure_queue.status->intake.estopped) {
370 new_superstructure_goal->intake.voltage_rollers = 10.0;
371 }
372 }
373
Campbell Crowley71b5f132017-02-18 13:16:08 -0800374 if (data.IsPressed(kHang)) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700375 new_superstructure_goal->intake.voltage_rollers = -10.0;
Austin Schuh3028b1d2017-03-11 22:12:13 -0800376 new_superstructure_goal->intake.disable_intake = true;
Austin Schuhd0629b12017-03-22 22:37:16 -0700377 } else if (data.IsPressed(kIntakeIn) || data.IsPressed(kFire)) {
378 if (robot_velocity_ > 2.0) {
379 new_superstructure_goal->intake.voltage_rollers = 12.0;
380 } else {
Austin Schuh4b5f7df2017-04-16 20:31:12 -0700381 new_superstructure_goal->intake.voltage_rollers = 11.0;
Austin Schuhd0629b12017-03-22 22:37:16 -0700382 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800383 } else if (data.IsPressed(kIntakeOut)) {
384 new_superstructure_goal->intake.voltage_rollers = -8.0;
Austin Schuh3028b1d2017-03-11 22:12:13 -0800385 }
386 if (intake_goal_ < 0.1) {
387 new_superstructure_goal->intake.voltage_rollers =
388 ::std::min(8.0, new_superstructure_goal->intake.voltage_rollers);
Campbell Crowley71b5f132017-02-18 13:16:08 -0800389 }
390
391 if (data.IsPressed(kReverseIndexer)) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700392 new_superstructure_goal->indexer.voltage_rollers = -12.0;
Austin Schuh3028b1d2017-03-11 22:12:13 -0800393 new_superstructure_goal->indexer.angular_velocity = 4.0;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800394 new_superstructure_goal->indexer.angular_velocity = 1.0;
Austin Schuh3028b1d2017-03-11 22:12:13 -0800395 } else if (fire_) {
Austin Schuhd0629b12017-03-22 22:37:16 -0700396 new_superstructure_goal->indexer.voltage_rollers = 12.0;
397 switch (last_shot_distance_) {
Parker Schuh208a58d2017-04-12 20:51:38 -0700398 case ShotDistance::VISION_SHOT:
Austin Schuh4b5f7df2017-04-16 20:31:12 -0700399 new_superstructure_goal->indexer.angular_velocity = -1.25 * M_PI;
Austin Schuhd0629b12017-03-22 22:37:16 -0700400 break;
401 case ShotDistance::MIDDLE_SHOT:
402 case ShotDistance::FAR_SHOT:
403 new_superstructure_goal->indexer.angular_velocity = -2.25 * M_PI;
404 break;
405 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800406 } else {
407 new_superstructure_goal->indexer.voltage_rollers = 0.0;
408 new_superstructure_goal->indexer.angular_velocity = 0.0;
409 }
410
411 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
412 if (!new_superstructure_goal.Send()) {
413 LOG(ERROR, "Sending superstructure goal failed.\n");
414 }
415 }
416
417 private:
Austin Schuh3028b1d2017-03-11 22:12:13 -0800418 void StartAuto() {
419 LOG(INFO, "Starting auto mode\n");
420
421 ::frc971::autonomous::AutonomousActionParams params;
422 ::frc971::autonomous::auto_mode.FetchLatest();
423 if (::frc971::autonomous::auto_mode.get() != nullptr) {
424 params.mode = ::frc971::autonomous::auto_mode->mode;
425 } else {
426 LOG(WARNING, "no auto mode values\n");
427 params.mode = 0;
428 }
429 action_queue_.EnqueueAction(
430 ::frc971::autonomous::MakeAutonomousAction(params));
431 }
Campbell Crowley71b5f132017-02-18 13:16:08 -0800432
433 void StopAuto() {
434 LOG(INFO, "Stopping auto mode\n");
435 action_queue_.CancelAllActions();
436 }
437
438 // Current goals to send to the robot.
439 double intake_goal_ = 0.0;
440 double turret_goal_ = 0.0;
441 double hood_goal_ = 0.3;
442 double shooter_velocity_ = 0.0;
443
444 // Goals to send to the drivetrain in closed loop mode.
Austin Schuh3028b1d2017-03-11 22:12:13 -0800445 double left_goal_ = 0.0;
446 double right_goal_ = 0.0;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800447
448 bool was_running_ = false;
449 bool auto_running_ = false;
450
Parker Schuh208a58d2017-04-12 20:51:38 -0700451 bool vision_distance_shot_ = false;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800452
453 bool fire_ = false;
Austin Schuhd0629b12017-03-22 22:37:16 -0700454 double robot_velocity_ = 0.0;
Campbell Crowley71b5f132017-02-18 13:16:08 -0800455
456 ::aos::common::actions::ActionQueue action_queue_;
457};
458
459} // namespace joysticks
460} // namespace input
461} // namespace y2017
462
463int main() {
464 ::aos::Init(-1);
465 ::y2017::input::joysticks::Reader reader;
466 reader.Run();
467 ::aos::Cleanup();
468}