blob: 45733ffb850d98477512809917b29a232f1caff3 [file] [log] [blame]
Comran Morshed9a9948c2016-01-16 15:58:04 +00001#include <stdio.h>
2#include <string.h>
3#include <unistd.h>
4#include <math.h>
5
6#include "aos/linux_code/init.h"
7#include "aos/input/joystick_input.h"
8#include "aos/common/input/driver_station_data.h"
9#include "aos/common/logging/logging.h"
10#include "aos/common/util/log_interval.h"
11#include "aos/common/time.h"
12#include "aos/common/actions/actions.h"
13
14#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Comran Morshed200dd4b2016-02-16 17:54:58 +000015#include "y2016/control_loops/shooter/shooter.q.h"
16#include "y2016/control_loops/superstructure/superstructure.q.h"
Austin Schuh45d07f62016-03-13 15:33:31 -070017#include "y2016/control_loops/superstructure/superstructure.h"
Comran Morshedaa0573c2016-03-05 19:05:54 +000018#include "y2016/queues/ball_detector.q.h"
Austin Schuhadd6d792016-03-19 01:20:01 -070019#include "y2016/vision/vision.q.h"
Comran Morshed200dd4b2016-02-16 17:54:58 +000020
Comran Morshed6c6a0a92016-01-17 12:45:16 +000021#include "y2016/constants.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000022#include "frc971/queues/gyro.q.h"
23#include "frc971/autonomous/auto.q.h"
Comran Morshede68e3732016-03-12 14:12:11 +000024#include "y2016/actors/autonomous_actor.h"
Austin Schuh18799112016-03-16 22:09:54 -070025#include "y2016/actors/vision_align_actor.h"
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -070026#include "y2016/actors/superstructure_actor.h"
Austin Schuhd52df772016-03-19 15:38:41 -070027#include "y2016/control_loops/drivetrain/drivetrain_base.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000028
29using ::frc971::control_loops::drivetrain_queue;
Comran Morshed200dd4b2016-02-16 17:54:58 +000030using ::y2016::control_loops::shooter::shooter_queue;
31using ::y2016::control_loops::superstructure_queue;
Comran Morshed9a9948c2016-01-16 15:58:04 +000032
33using ::aos::input::driver_station::ButtonLocation;
Comran Morshed9a9948c2016-01-16 15:58:04 +000034using ::aos::input::driver_station::ControlBit;
Austin Schuh4ea06c12016-03-12 17:54:31 -080035using ::aos::input::driver_station::JoystickAxis;
36using ::aos::input::driver_station::POVLocation;
Comran Morshed9a9948c2016-01-16 15:58:04 +000037
Comran Morshed6c6a0a92016-01-17 12:45:16 +000038namespace y2016 {
Comran Morshed9a9948c2016-01-16 15:58:04 +000039namespace input {
40namespace joysticks {
41
Austin Schuh45d07f62016-03-13 15:33:31 -070042namespace {
43
44constexpr double kMaxIntakeAngleBeforeArmInterference = control_loops::
45 superstructure::CollisionAvoidance::kMaxIntakeAngleBeforeArmInterference;
46
47} // namespace
48
Comran Morshed9a9948c2016-01-16 15:58:04 +000049const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2);
Campbell Crowley5b27f022016-02-20 16:55:35 -080050const ButtonLocation kShiftHigh(2, 3), kShiftHigh2(2, 2), kShiftLow(2, 1);
Comran Morshed9a9948c2016-01-16 15:58:04 +000051const ButtonLocation kQuickTurn(1, 5);
52
Austin Schuh781cdcc2016-03-12 13:03:12 -080053const ButtonLocation kTurn1(1, 7);
54const ButtonLocation kTurn2(1, 11);
55
Comran Morshed200dd4b2016-02-16 17:54:58 +000056// Buttons on the lexan driver station to get things running on bring-up day.
Austin Schuh4ea06c12016-03-12 17:54:31 -080057const ButtonLocation kIntakeDown(3, 11);
58const POVLocation kFrontLong(3, 180);
59const POVLocation kBackLong(3, 0);
Austin Schuh45d07f62016-03-13 15:33:31 -070060const POVLocation kBackFender(3, 90);
61const POVLocation kFrontFender(3, 270);
Austin Schuh4ea06c12016-03-12 17:54:31 -080062const ButtonLocation kIntakeIn(3, 12);
Austin Schuh4ea06c12016-03-12 17:54:31 -080063const ButtonLocation kFire(3, 3);
Austin Schuh4ea06c12016-03-12 17:54:31 -080064const ButtonLocation kIntakeOut(3, 9);
Austin Schuh843412b2016-03-20 16:48:46 -070065const ButtonLocation kPortcullis(3, 7);
66const ButtonLocation kChevalDeFrise(3, 8);
Comran Morshed200dd4b2016-02-16 17:54:58 +000067
Austin Schuhadd6d792016-03-19 01:20:01 -070068const ButtonLocation kVisionAlign(3, 4);
Austin Schuh18799112016-03-16 22:09:54 -070069
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -070070const ButtonLocation kExpand(3, 6);
71const ButtonLocation kWinch(3, 5);
72
Comran Morshed9a9948c2016-01-16 15:58:04 +000073class Reader : public ::aos::input::JoystickInput {
74 public:
75 Reader()
Austin Schuh94596dd2016-03-13 21:41:26 -070076 : is_high_gear_(true),
Comran Morshed200dd4b2016-02-16 17:54:58 +000077 intake_goal_(0.0),
78 shoulder_goal_(M_PI / 2.0),
Austin Schuhd52df772016-03-19 15:38:41 -070079 wrist_goal_(0.0),
80 dt_config_(control_loops::drivetrain::GetDrivetrainConfig()) {}
Comran Morshed9a9948c2016-01-16 15:58:04 +000081
82 void RunIteration(const ::aos::input::driver_station::Data &data) override {
83 bool last_auto_running = auto_running_;
84 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
85 data.GetControlBit(ControlBit::kEnabled);
86 if (auto_running_ != last_auto_running) {
87 if (auto_running_) {
88 StartAuto();
89 } else {
90 StopAuto();
91 }
92 }
93
Austin Schuh94596dd2016-03-13 21:41:26 -070094 if (!data.GetControlBit(ControlBit::kEnabled)) {
95 // If we are not enabled, reset the waiting for zero bit.
96 LOG(DEBUG, "Waiting for zero.\n");
97 waiting_for_zero_ = true;
98 is_high_gear_ = true;
99 }
100
Austin Schuhadd6d792016-03-19 01:20:01 -0700101 vision_valid_ = false;
102
103 ::y2016::vision::vision_status.FetchLatest();
104
105 if (::y2016::vision::vision_status.get()) {
106 vision_valid_ = (::y2016::vision::vision_status->left_image_valid &&
107 ::y2016::vision::vision_status->right_image_valid);
Austin Schuhd52df772016-03-19 15:38:41 -0700108 last_angle_ = ::y2016::vision::vision_status->horizontal_angle;
Austin Schuhadd6d792016-03-19 01:20:01 -0700109 }
110
Austin Schuh94596dd2016-03-13 21:41:26 -0700111 if (!auto_running_) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000112 HandleDrivetrain(data);
113 HandleTeleop(data);
114 }
Austin Schuh81d71db2016-03-15 20:56:24 -0700115
116 // Process any pending actions.
117 action_queue_.Tick();
118 was_running_ = action_queue_.Running();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000119 }
120
121 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
122 bool is_control_loop_driving = false;
Austin Schuh781cdcc2016-03-12 13:03:12 -0800123 static double left_goal = 0.0;
124 static double right_goal = 0.0;
125
Comran Morshed9a9948c2016-01-16 15:58:04 +0000126 const double wheel = -data.GetAxis(kSteeringWheel);
127 const double throttle = -data.GetAxis(kDriveThrottle);
Austin Schuhb0099642016-04-03 21:37:27 -0700128 drivetrain_queue.status.FetchLatest();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000129
Austin Schuh974cf652016-04-20 20:18:13 -0700130 if (data.IsPressed(kVisionAlign)) {
131 if (vision_valid_ && !vision_action_running_) {
132 actors::VisionAlignActionParams params;
133 action_queue_.EnqueueAction(actors::MakeVisionAlignAction(params));
134 vision_action_running_ = true;
135 LOG(INFO, "Starting vision align\n");
136 } else {
137 if (!vision_valid_) {
138 LOG(INFO, "Vision align but not valid\n");
139 }
140 }
Austin Schuh18799112016-03-16 22:09:54 -0700141 }
142
143 if (data.NegEdge(kVisionAlign)) {
144 action_queue_.CancelAllActions();
145 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700146 if (!data.IsPressed(kVisionAlign)) {
147 vision_action_running_ = false;
148 }
Austin Schuh18799112016-03-16 22:09:54 -0700149
150 // Don't do any normal drivetrain stuff if vision is in charge.
Austin Schuhfef64ac2016-04-24 19:08:01 -0700151 if (vision_action_running_) {
Austin Schuh18799112016-03-16 22:09:54 -0700152 return;
153 }
154
Austin Schuh781cdcc2016-03-12 13:03:12 -0800155 if (data.PosEdge(kTurn1) || data.PosEdge(kTurn2)) {
Austin Schuh781cdcc2016-03-12 13:03:12 -0800156 if (drivetrain_queue.status.get()) {
Austin Schuh45d07f62016-03-13 15:33:31 -0700157 left_goal = drivetrain_queue.status->estimated_left_position;
158 right_goal = drivetrain_queue.status->estimated_right_position;
Austin Schuh781cdcc2016-03-12 13:03:12 -0800159 }
160 }
161 if (data.IsPressed(kTurn1) || data.IsPressed(kTurn2)) {
162 is_control_loop_driving = true;
163 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000164 if (!drivetrain_queue.goal.MakeWithBuilder()
165 .steering(wheel)
166 .throttle(throttle)
167 .highgear(is_high_gear_)
168 .quickturn(data.IsPressed(kQuickTurn))
169 .control_loop_driving(is_control_loop_driving)
Austin Schuh45d07f62016-03-13 15:33:31 -0700170 .left_goal(left_goal - wheel * 0.5 + throttle * 0.3)
171 .right_goal(right_goal + wheel * 0.5 + throttle * 0.3)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000172 .left_velocity_goal(0)
173 .right_velocity_goal(0)
174 .Send()) {
175 LOG(WARNING, "sending stick values failed\n");
176 }
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000177
Campbell Crowley5b27f022016-02-20 16:55:35 -0800178 if (data.PosEdge(kShiftLow)) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000179 is_high_gear_ = false;
180 }
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000181
Campbell Crowley5b27f022016-02-20 16:55:35 -0800182 if (data.PosEdge(kShiftHigh) || data.PosEdge(kShiftHigh2)) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000183 is_high_gear_ = true;
184 }
185 }
186
Comran Morshed9a9948c2016-01-16 15:58:04 +0000187 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700188 float voltage_climber = 0.0;
Austin Schuh45d07f62016-03-13 15:33:31 -0700189 // Default the intake to up.
190 intake_goal_ = constants::Values::kIntakeRange.upper - 0.04;
191
192 bool force_lights_on = false;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000193 if (!data.GetControlBit(ControlBit::kEnabled)) {
194 action_queue_.CancelAllActions();
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000195 LOG(DEBUG, "Canceling\n");
Comran Morshed9a9948c2016-01-16 15:58:04 +0000196 }
197
Comran Morshed200dd4b2016-02-16 17:54:58 +0000198 superstructure_queue.status.FetchLatest();
199 if (!superstructure_queue.status.get()) {
200 LOG(ERROR, "Got no superstructure status packet.\n");
201 }
202
203 if (superstructure_queue.status.get() &&
204 superstructure_queue.status->zeroed) {
205 if (waiting_for_zero_) {
Austin Schuh94596dd2016-03-13 21:41:26 -0700206 LOG(DEBUG, "Zeroed! Starting teleop mode.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000207 waiting_for_zero_ = false;
208 }
209 } else {
210 waiting_for_zero_ = true;
211 }
212
Austin Schuhadd6d792016-03-19 01:20:01 -0700213 double intake_when_shooting = kMaxIntakeAngleBeforeArmInterference;
214 bool use_slow_profile = false;
215 if (vision_action_running_) {
216 use_slow_profile = true;
217 if (vision_valid_) {
218 intake_when_shooting -= 0.5;
219 }
220 }
221
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700222 if (data.IsPressed(kFrontLong)) {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800223 // Forwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700224 shoulder_goal_ = M_PI / 2.0 + 0.1;
Austin Schuh6a871ff2016-05-01 12:31:23 -0700225 wrist_goal_ = M_PI + 0.41 + 0.02 - 0.005;
Austin Schuhb0099642016-04-03 21:37:27 -0700226 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700227 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700228 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800229 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700230 intake_goal_ = intake_when_shooting;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800231 } else if (data.IsPressed(kBackLong)) {
232 // Backwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700233 shoulder_goal_ = M_PI / 2.0 - 0.4;
Austin Schuhe153c5a2016-04-20 20:18:42 -0700234 wrist_goal_ = -0.62 - 0.02;
Austin Schuhb0099642016-04-03 21:37:27 -0700235 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700236 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700237 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800238 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700239 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700240 } else if (data.IsPressed(kBackFender)) {
241 // Fender shot back
Austin Schuh6a871ff2016-05-01 12:31:23 -0700242 shoulder_goal_ = M_PI / 2.0 - 0.2;
243 wrist_goal_ = -0.55;
244 shooter_velocity_ = 600.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700245 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700246 } else if (data.IsPressed(kFrontFender)) {
Austin Schuh6a871ff2016-05-01 12:31:23 -0700247 // Forwards shot, higher
248 shoulder_goal_ = M_PI / 2.0 + 0.1;
249 wrist_goal_ = M_PI + 0.41 + 0.02 + 0.020;
250 if (drivetrain_queue.status.get()) {
251 wrist_goal_ += drivetrain_queue.status->ground_angle;
252 }
253 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700254 intake_goal_ = intake_when_shooting;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700255 } else if (data.IsPressed(kExpand) || data.IsPressed(kWinch)) {
256 // Set the goals to the hanging position so when the actor finishes, we
257 // will still be at the right spot.
258 shoulder_goal_ = 1.2;
Austin Schuhfef64ac2016-04-24 19:08:01 -0700259 wrist_goal_ = 1.0;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700260 intake_goal_ = 0.0;
261 if (data.PosEdge(kExpand)) {
262 is_expanding_ = true;
263 actors::SuperstructureActionParams params;
264 params.partial_angle = 0.3;
265 params.delay_time = 0.7;
266 params.full_angle = shoulder_goal_;
Austin Schuhfef64ac2016-04-24 19:08:01 -0700267 params.shooter_angle = wrist_goal_;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700268 action_queue_.EnqueueAction(actors::MakeSuperstructureAction(params));
269 }
270 if (data.IsPressed(kWinch)) {
271 voltage_climber = 12.0;
272 }
Austin Schuhde802e92016-02-27 14:49:03 -0800273 } else {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800274 wrist_goal_ = 0.0;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800275 shoulder_goal_ = -0.010;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800276 shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000277 }
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700278 if (data.NegEdge(kExpand) || voltage_climber > 1.0) {
279 is_expanding_ = false;
280 action_queue_.CancelAllActions();
281 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000282
Comran Morshedaa0573c2016-03-05 19:05:54 +0000283 bool ball_detected = false;
284 ::y2016::sensors::ball_detector.FetchLatest();
285 if (::y2016::sensors::ball_detector.get()) {
286 ball_detected = ::y2016::sensors::ball_detector->voltage > 2.5;
287 }
288 if (data.PosEdge(kIntakeIn)) {
289 saw_ball_when_started_intaking_ = ball_detected;
290 }
291
Austin Schuh45d07f62016-03-13 15:33:31 -0700292 if (data.IsPressed(kIntakeIn)) {
293 is_intaking_ = (!ball_detected || saw_ball_when_started_intaking_);
294 if (ball_detected) {
295 force_lights_on = true;
296 }
297 } else {
298 is_intaking_ = false;
299 }
300
Austin Schuhd52df772016-03-19 15:38:41 -0700301 fire_ = false;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800302 if (data.IsPressed(kFire) && shooter_velocity_ != 0.0) {
Austin Schuhd52df772016-03-19 15:38:41 -0700303 if (data.IsPressed(kVisionAlign)) {
304 // Make sure that we are lined up.
305 drivetrain_queue.status.FetchLatest();
306 drivetrain_queue.goal.FetchLatest();
307 if (drivetrain_queue.status.get() && drivetrain_queue.goal.get()) {
308 const double left_goal = drivetrain_queue.goal->left_goal;
309 const double right_goal = drivetrain_queue.goal->right_goal;
310 const double left_current =
311 drivetrain_queue.status->estimated_left_position;
312 const double right_current =
313 drivetrain_queue.status->estimated_right_position;
314 const double left_velocity =
315 drivetrain_queue.status->estimated_left_velocity;
316 const double right_velocity =
317 drivetrain_queue.status->estimated_right_velocity;
318 if (vision_action_running_ && ::std::abs(last_angle_) < 0.02 &&
319 ::std::abs((left_goal - right_goal) -
320 (left_current - right_current)) /
321 dt_config_.robot_radius / 2.0 <
322 0.02 &&
323 ::std::abs(left_velocity - right_velocity) < 0.01) {
324 ++ready_to_fire_;
325 } else {
326 ready_to_fire_ = 0;
327 }
Austin Schuh3d79cc02016-03-20 21:08:53 -0700328 if (ready_to_fire_ > 9) {
Austin Schuhd52df772016-03-19 15:38:41 -0700329 fire_ = true;
330 }
331 }
332 } else {
333 fire_ = true;
334 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000335 }
336
Austin Schuh4ea06c12016-03-12 17:54:31 -0800337 is_outtaking_ = data.IsPressed(kIntakeOut);
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800338
Austin Schuhd52df772016-03-19 15:38:41 -0700339 if (is_intaking_ || is_outtaking_) {
340 recently_intaking_accumulator_ = 20;
341 }
342
343 if (data.IsPressed(kIntakeDown)) {
344 if (recently_intaking_accumulator_) {
345 intake_goal_ = 0.1;
346 } else {
347 intake_goal_ = -0.05;
348 }
349 }
350
351 if (recently_intaking_accumulator_ > 0) {
352 --recently_intaking_accumulator_;
353 }
354
Austin Schuh843412b2016-03-20 16:48:46 -0700355 if (data.IsPressed(kPortcullis)) {
356 traverse_unlatched_ = true;
357 traverse_down_ = true;
358 } else if (data.IsPressed(kChevalDeFrise)) {
359 traverse_unlatched_ = false;
360 traverse_down_ = true;
361 } else {
362 traverse_unlatched_ = true;
363 traverse_down_ = false;
364 }
365
Comran Morshed200dd4b2016-02-16 17:54:58 +0000366 if (!waiting_for_zero_) {
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700367 if (!is_expanding_) {
368 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
369 new_superstructure_goal->angle_intake = intake_goal_;
370 new_superstructure_goal->angle_shoulder = shoulder_goal_;
371 new_superstructure_goal->angle_wrist = wrist_goal_;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800372
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700373 new_superstructure_goal->max_angular_velocity_intake = 7.0;
374 new_superstructure_goal->max_angular_velocity_shoulder = 4.0;
375 new_superstructure_goal->max_angular_velocity_wrist = 10.0;
376 if (use_slow_profile) {
377 new_superstructure_goal->max_angular_acceleration_intake = 10.0;
378 } else {
379 new_superstructure_goal->max_angular_acceleration_intake = 40.0;
380 }
381 new_superstructure_goal->max_angular_acceleration_shoulder = 10.0;
382 if (shoulder_goal_ > 1.0) {
383 new_superstructure_goal->max_angular_acceleration_wrist = 45.0;
384 } else {
385 new_superstructure_goal->max_angular_acceleration_wrist = 25.0;
386 }
Austin Schuh3f0b1192016-03-12 13:03:56 -0800387
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700388 // Granny mode
389 /*
390 new_superstructure_goal->max_angular_velocity_intake = 0.2;
391 new_superstructure_goal->max_angular_velocity_shoulder = 0.2;
392 new_superstructure_goal->max_angular_velocity_wrist = 0.2;
393 new_superstructure_goal->max_angular_acceleration_intake = 1.0;
394 new_superstructure_goal->max_angular_acceleration_shoulder = 1.0;
395 new_superstructure_goal->max_angular_acceleration_wrist = 1.0;
396 */
397 if (is_intaking_) {
398 new_superstructure_goal->voltage_top_rollers = 12.0;
399 new_superstructure_goal->voltage_bottom_rollers = 12.0;
400 } else if (is_outtaking_) {
401 new_superstructure_goal->voltage_top_rollers = -12.0;
402 new_superstructure_goal->voltage_bottom_rollers = -7.0;
403 } else {
404 new_superstructure_goal->voltage_top_rollers = 0.0;
405 new_superstructure_goal->voltage_bottom_rollers = 0.0;
406 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000407
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700408 new_superstructure_goal->traverse_unlatched = traverse_unlatched_;
409 new_superstructure_goal->unfold_climber = false;
410 new_superstructure_goal->voltage_climber = voltage_climber;
411 new_superstructure_goal->traverse_down = traverse_down_;
412 new_superstructure_goal->force_intake = true;
Austin Schuh843412b2016-03-20 16:48:46 -0700413
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700414 if (!new_superstructure_goal.Send()) {
415 LOG(ERROR, "Sending superstructure goal failed.\n");
416 } else {
417 LOG(DEBUG, "sending goals: intake: %f, shoulder: %f, wrist: %f\n",
418 intake_goal_, shoulder_goal_, wrist_goal_);
419 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700420 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000421
Austin Schuhadd6d792016-03-19 01:20:01 -0700422 if (!shooter_queue.goal.MakeWithBuilder()
423 .angular_velocity(shooter_velocity_)
424 .clamp_open(is_intaking_ || is_outtaking_)
425 .push_to_shooter(fire_)
426 .force_lights_on(force_lights_on)
Austin Schuhb2c33382016-04-03 16:09:17 -0700427 .shooting_forwards(wrist_goal_ > 0)
Austin Schuhadd6d792016-03-19 01:20:01 -0700428 .Send()) {
429 LOG(ERROR, "Sending shooter goal failed.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000430 }
431 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000432 }
433
Comran Morshed9a9948c2016-01-16 15:58:04 +0000434 private:
435 void StartAuto() {
436 LOG(INFO, "Starting auto mode\n");
Comran Morshede68e3732016-03-12 14:12:11 +0000437
438 actors::AutonomousActionParams params;
Brian Silverman68cb5c22016-03-20 18:11:14 -0700439 actors::auto_mode.FetchLatest();
440 if (actors::auto_mode.get() != nullptr) {
441 params.mode = actors::auto_mode->mode;
442 } else {
443 LOG(WARNING, "no auto mode values\n");
444 params.mode = 0;
445 }
Comran Morshede68e3732016-03-12 14:12:11 +0000446 action_queue_.EnqueueAction(actors::MakeAutonomousAction(params));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000447 }
448
449 void StopAuto() {
450 LOG(INFO, "Stopping auto mode\n");
Comran Morshede68e3732016-03-12 14:12:11 +0000451 action_queue_.CancelAllActions();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000452 }
453
454 bool is_high_gear_;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000455 // Whatever these are set to are our default goals to send out after zeroing.
456 double intake_goal_;
457 double shoulder_goal_;
458 double wrist_goal_;
Austin Schuhde802e92016-02-27 14:49:03 -0800459 double shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000460
461 bool was_running_ = false;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000462 bool auto_running_ = false;
463
Austin Schuh843412b2016-03-20 16:48:46 -0700464 bool traverse_unlatched_ = false;
465 bool traverse_down_ = false;
466
Comran Morshed200dd4b2016-02-16 17:54:58 +0000467 // If we're waiting for the subsystems to zero.
468 bool waiting_for_zero_ = true;
469
Comran Morshedaa0573c2016-03-05 19:05:54 +0000470 // If true, the ball was present when the intaking button was pressed.
471 bool saw_ball_when_started_intaking_ = false;
472
Austin Schuhde802e92016-02-27 14:49:03 -0800473 bool is_intaking_ = false;
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800474 bool is_outtaking_ = false;
Austin Schuhde802e92016-02-27 14:49:03 -0800475 bool fire_ = false;
476
Austin Schuhadd6d792016-03-19 01:20:01 -0700477 bool vision_action_running_ = false;
478 bool vision_valid_ = false;
479
Austin Schuhd52df772016-03-19 15:38:41 -0700480 int recently_intaking_accumulator_ = 0;
481 double last_angle_ = 100;
482
483 int ready_to_fire_ = 0;
484
Comran Morshed9a9948c2016-01-16 15:58:04 +0000485 ::aos::common::actions::ActionQueue action_queue_;
486
Austin Schuhd52df772016-03-19 15:38:41 -0700487 const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_;
488
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700489 bool is_expanding_ = false;
490
Comran Morshed9a9948c2016-01-16 15:58:04 +0000491 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
492 ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING,
493 "no drivetrain status");
494};
495
496} // namespace joysticks
497} // namespace input
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000498} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000499
500int main() {
501 ::aos::Init(-1);
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000502 ::y2016::input::joysticks::Reader reader;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000503 reader.Run();
504 ::aos::Cleanup();
505}