blob: 0d4760604ca1314f38a772b9d0aff1e9b70e6898 [file] [log] [blame]
Brian Silverman20141f92015-01-05 17:39:01 -08001#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/prime/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"
Ben Fredricksond69f38b2015-01-28 20:06:15 -080012#include "aos/common/actions/actions.h"
Brian Silverman20141f92015-01-05 17:39:01 -080013
Daniel Petti61896522015-02-15 18:01:43 -080014#include "frc971/control_loops/claw/claw.q.h"
Brian Silverman20141f92015-01-05 17:39:01 -080015#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Daniel Petti61896522015-02-15 18:01:43 -080016#include "frc971/control_loops/fridge/fridge.q.h"
Brian Silverman20141f92015-01-05 17:39:01 -080017#include "frc971/constants.h"
18#include "frc971/queues/gyro.q.h"
19#include "frc971/autonomous/auto.q.h"
Austin Schuhd8b2a242015-02-22 21:46:53 -080020#include "frc971/actors/pickup_actor.h"
21#include "frc971/actors/stack_actor.h"
Brian Silverman10043572015-03-21 23:43:50 -070022#include "frc971/actors/score_actor.h"
Austin Schuhf14727e2015-03-08 18:49:12 -070023#include "frc971/actors/stack_and_lift_actor.h"
24#include "frc971/actors/stack_and_hold_actor.h"
25#include "frc971/actors/held_to_lift_actor.h"
Austin Schuhd8b2a242015-02-22 21:46:53 -080026#include "frc971/actors/lift_actor.h"
Austin Schuh994d42c2015-03-01 00:02:17 -080027#include "frc971/actors/can_pickup_actor.h"
Austin Schuh700b9222015-03-01 03:03:15 -080028#include "frc971/actors/horizontal_can_pickup_actor.h"
Brian Silverman20141f92015-01-05 17:39:01 -080029
Daniel Petti61896522015-02-15 18:01:43 -080030using ::frc971::control_loops::claw_queue;
Brian Silvermanada5f2c2015-02-01 02:41:14 -050031using ::frc971::control_loops::drivetrain_queue;
Daniel Petti61896522015-02-15 18:01:43 -080032using ::frc971::control_loops::fridge_queue;
Brian Silverman20141f92015-01-05 17:39:01 -080033using ::frc971::sensors::gyro_reading;
34
35using ::aos::input::driver_station::ButtonLocation;
Austin Schuhf14727e2015-03-08 18:49:12 -070036using ::aos::input::driver_station::POVLocation;
Brian Silverman20141f92015-01-05 17:39:01 -080037using ::aos::input::driver_station::JoystickAxis;
38using ::aos::input::driver_station::ControlBit;
39
40namespace frc971 {
41namespace input {
42namespace joysticks {
43
Austin Schuhf14727e2015-03-08 18:49:12 -070044// Actions needed.
45
46// Human Player Station Intake Button
47// Claw open
48// Claw close
49// Claw down
50
51// Stack + Lift (together)
52// Place
53
54// Hold stack
55
56// Horizontal can pickup
57// Vertical can pickup
58
59// TODO(austin): Pull a lot of the constants below out up here so they can be
60// globally changed easier.
61
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -080062// preset motion limits
Brian Silvermancb615cf2015-03-21 21:42:35 -070063constexpr actors::ProfileParams kArmMove{0.5, 1.0};
64constexpr actors::ProfileParams kElevatorMove{0.3, 1.0};
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -080065
Brian Silverman20141f92015-01-05 17:39:01 -080066const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2);
67const ButtonLocation kShiftHigh(2, 1), kShiftLow(2, 3);
68const ButtonLocation kQuickTurn(1, 5);
69
Austin Schuhf14727e2015-03-08 18:49:12 -070070//const ButtonLocation kClawClosed(3, 5);
71//const ButtonLocation kFridgeClosed(3, 1);
Austin Schuhd8b2a242015-02-22 21:46:53 -080072
Daniel Petti61896522015-02-15 18:01:43 -080073
Austin Schuhf14727e2015-03-08 18:49:12 -070074const ButtonLocation kRollersIn(4, 5);
75const ButtonLocation kClawToggle(4, 1);
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -080076
Brian Silverman10043572015-03-21 23:43:50 -070077const POVLocation kElevatorCanUp(4, 0);
Austin Schuhf14727e2015-03-08 18:49:12 -070078
79// POV stick 3, 180
80const POVLocation kCanPickup(4, 180);
81const ButtonLocation kToteChute(4, 6);
82const ButtonLocation kStackAndLift(4, 7);
Brian Silverman10043572015-03-21 23:43:50 -070083const ButtonLocation kStackAndHold(3, 5);
Austin Schuhf14727e2015-03-08 18:49:12 -070084
85// Pull in the 6th tote.
Brian Silverman10043572015-03-21 23:43:50 -070086//const ButtonLocation kSixthTote(4, 10);
87const ButtonLocation kCanUp(4, 10);
Austin Schuhf14727e2015-03-08 18:49:12 -070088
89const ButtonLocation kHeldToLift(4, 11);
90const ButtonLocation kPickup(4, 9);
91
92const ButtonLocation kStack(4, 2);
93
94// Move the fridge out with the stack in preparation for scoring.
Brian Silverman10043572015-03-21 23:43:50 -070095const ButtonLocation kScore(4, 8);
Brian Silverman913eafa2015-03-19 23:42:16 -070096const ButtonLocation kCoopTop(3, 8);
97const ButtonLocation kCoopTopRetract(3, 7);
98const ButtonLocation kCoopBottom(3, 6);
99const ButtonLocation kCoopBottomRetract(3, 9);
100
Brian Silvermancb615cf2015-03-21 21:42:35 -0700101const ButtonLocation kCanReset(4, 12);
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700102
Brian Silverman10043572015-03-21 23:43:50 -0700103const POVLocation kFridgeToggle(4, 270);
Austin Schuhf14727e2015-03-08 18:49:12 -0700104const ButtonLocation kSpit(4, 3);
105
106// Set stack down in the bot.
Brian Silverman10043572015-03-21 23:43:50 -0700107const POVLocation kSetStackDownAndHold(4, 90);
Austin Schuhf14727e2015-03-08 18:49:12 -0700108
109const double kClawTotePackAngle = 0.95;
Brian Silverman10043572015-03-21 23:43:50 -0700110const double kArmRaiseLowerClearance = -0.08;
Brian Silverman20141f92015-01-05 17:39:01 -0800111
Brian Silverman697d07b2015-03-19 23:41:11 -0700112const double kStackUpHeight = 0.55;
113const double kStackUpArm = 0.1;
114
Brian Silverman20141f92015-01-05 17:39:01 -0800115class Reader : public ::aos::input::JoystickInput {
116 public:
Austin Schuh331e13d2015-02-15 00:16:51 -0800117 Reader() : was_running_(false) {}
Brian Silverman20141f92015-01-05 17:39:01 -0800118
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700119 static actors::ScoreParams MakeScoreParams() {
Brian Silverman913eafa2015-03-19 23:42:16 -0700120 actors::ScoreParams r;
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700121 r.move_the_stack = r.place_the_stack = true;
Brian Silverman913eafa2015-03-19 23:42:16 -0700122 r.upper_move_height = 0.14;
123 r.begin_horizontal_move_height = 0.13;
124 r.horizontal_move_target = -0.7;
125 r.place_height = -0.10;
126 r.home_return_height = 0.1;
127 return r;
128 }
129
130 static actors::ScoreParams MakeCoopTopParams(bool place_the_stack) {
131 actors::ScoreParams r;
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700132 r.move_the_stack = !place_the_stack;
Brian Silverman913eafa2015-03-19 23:42:16 -0700133 r.place_the_stack = place_the_stack;
134 r.upper_move_height = 0.52;
135 r.begin_horizontal_move_height = 0.5;
136 r.horizontal_move_target = -0.48;
137 r.place_height = 0.39;
138 r.home_return_height = 0.1;
139 return r;
140 }
141
142 static actors::ScoreParams MakeCoopBottomParams(bool place_the_stack) {
143 actors::ScoreParams r;
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700144 r.move_the_stack = !place_the_stack;
Brian Silverman913eafa2015-03-19 23:42:16 -0700145 r.place_the_stack = place_the_stack;
146 r.upper_move_height = 0.17;
147 r.begin_horizontal_move_height = 0.16;
148 r.horizontal_move_target = -0.7;
149 r.place_height = 0.0;
150 r.home_return_height = 0.1;
151 return r;
152 }
153
Brian Silverman20141f92015-01-05 17:39:01 -0800154 virtual void RunIteration(const ::aos::input::driver_station::Data &data) {
Austin Schuh6182f8d2015-02-14 22:15:04 -0800155 bool last_auto_running = auto_running_;
156 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
Brian Silvermane1103e62015-02-15 02:03:38 -0500157 data.GetControlBit(ControlBit::kEnabled);
Austin Schuh6182f8d2015-02-14 22:15:04 -0800158 if (auto_running_ != last_auto_running) {
159 if (auto_running_) {
160 StartAuto();
161 } else {
162 StopAuto();
Brian Silverman20141f92015-01-05 17:39:01 -0800163 }
Austin Schuh6182f8d2015-02-14 22:15:04 -0800164 }
165
166 if (!data.GetControlBit(ControlBit::kAutonomous)) {
Daniel Petti61896522015-02-15 18:01:43 -0800167 HandleDrivetrain(data);
Austin Schuhf14727e2015-03-08 18:49:12 -0700168 HandleTeleop(data);
Brian Silverman20141f92015-01-05 17:39:01 -0800169 }
170 }
171
172 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
Brian Silverman20141f92015-01-05 17:39:01 -0800173 const double wheel = -data.GetAxis(kSteeringWheel);
174 const double throttle = -data.GetAxis(kDriveThrottle);
Brian Silverman20141f92015-01-05 17:39:01 -0800175
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500176 if (!drivetrain_queue.goal.MakeWithBuilder()
Brian Silverman20141f92015-01-05 17:39:01 -0800177 .steering(wheel)
178 .throttle(throttle)
Brian Silverman20141f92015-01-05 17:39:01 -0800179 .quickturn(data.IsPressed(kQuickTurn))
Austin Schuh331e13d2015-02-15 00:16:51 -0800180 .control_loop_driving(false)
Brian Silverman20141f92015-01-05 17:39:01 -0800181 .Send()) {
182 LOG(WARNING, "sending stick values failed\n");
183 }
Brian Silverman20141f92015-01-05 17:39:01 -0800184 }
185
186 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
Austin Schuhf14727e2015-03-08 18:49:12 -0700187 double intake_power = 0.0;
Brian Silverman20141f92015-01-05 17:39:01 -0800188 if (!data.GetControlBit(ControlBit::kEnabled)) {
189 action_queue_.CancelAllActions();
Austin Schuh6182f8d2015-02-14 22:15:04 -0800190 LOG(DEBUG, "Canceling\n");
Brian Silverman20141f92015-01-05 17:39:01 -0800191 }
192
Austin Schuhf14727e2015-03-08 18:49:12 -0700193 if (data.IsPressed(kRollersIn)) {
194 intake_power = 10.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800195 claw_goal_ = 0.0;
Austin Schuhd8b2a242015-02-22 21:46:53 -0800196 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700197 if (data.IsPressed(kSpit)) {
198 intake_power = -12.0;
Austin Schuhd8b2a242015-02-22 21:46:53 -0800199 }
Austin Schuh994d42c2015-03-01 00:02:17 -0800200
Austin Schuhf14727e2015-03-08 18:49:12 -0700201 // Toggle button for the claw
202 if (data.PosEdge(kClawToggle)) {
203 claw_rollers_closed_ = !claw_rollers_closed_;
Austin Schuh994d42c2015-03-01 00:02:17 -0800204 }
205
Austin Schuhf14727e2015-03-08 18:49:12 -0700206 /*
207 if (data.IsPressed(kClawClosed)) {
208 claw_rollers_closed_ = true;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800209 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700210 */
Austin Schuh700b9222015-03-01 03:03:15 -0800211
Austin Schuhf14727e2015-03-08 18:49:12 -0700212 // Horizontal can pickup.
Austin Schuh700b9222015-03-01 03:03:15 -0800213 if (data.PosEdge(kElevatorCanUp)) {
214 actors::HorizontalCanPickupParams params;
215 params.elevator_height = 0.3;
Brian Silverman10043572015-03-21 23:43:50 -0700216 params.pickup_angle = 0.40;
217 params.suck_time = 0.08;
Austin Schuh700b9222015-03-01 03:03:15 -0800218 params.suck_power = 8.0;
219
220 params.claw_settle_time = 0.05;
221 params.claw_settle_power = 5.0;
222 params.claw_full_lift_angle = 1.35;
223 params.claw_end_angle = 0.5;
Austin Schuhf14727e2015-03-08 18:49:12 -0700224
Brian Silverman10043572015-03-21 23:43:50 -0700225 // End low so we don't drop it.
226 params.elevator_end_height = 0.3;
227 params.arm_end_angle = 0.0;
Austin Schuh700b9222015-03-01 03:03:15 -0800228 action_queue_.EnqueueAction(
229 actors::MakeHorizontalCanPickupAction(params));
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800230 fridge_closed_ = true;
231 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700232
233 // -0.942503 arm, 0.374752 elevator
234 // Vertical can pickup.
235 if (data.PosEdge(kCanPickup)) {
236 actors::CanPickupParams params;
237 params.pickup_angle = -0.93;
238 params.pickup_height = 0.265;
239 params.lift_height = 0.65;
Brian Silverman10043572015-03-21 23:43:50 -0700240 // End low so the can is supported.
241 params.end_height = 0.3;
242 params.end_angle = 0.0;
Austin Schuhf14727e2015-03-08 18:49:12 -0700243 action_queue_.EnqueueAction(actors::MakeCanPickupAction(params));
244 fridge_closed_ = true;
245 }
246
Brian Silvermancb615cf2015-03-21 21:42:35 -0700247 if (data.PosEdge(kCanReset)) {
248 action_queue_.CancelAllActions();
249 elevator_goal_ = 0.3;
250 arm_goal_ = 0.0;
251 }
252
Austin Schuhf14727e2015-03-08 18:49:12 -0700253 // Tote chute pull in when button is pressed, pack when done.
254 if (data.IsPressed(kToteChute)) {
255 claw_goal_ = 0.8;
256 intake_power = 7.0;
257 }
258 if (data.NegEdge(kToteChute)) {
259 claw_goal_ = kClawTotePackAngle;
260 }
261
262 if (data.PosEdge(kStackAndLift)) {
263 actors::StackAndLiftParams params;
264 params.stack_params.claw_out_angle = 0.6;
265 params.stack_params.bottom = 0.020;
266 params.stack_params.over_box_before_place_height = 0.39;
Brian Silverman10043572015-03-21 23:43:50 -0700267 params.stack_params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700268
269 params.grab_after_stack = true;
270 params.clamp_pause_time = 0.1;
Brian Silverman697d07b2015-03-19 23:41:11 -0700271 params.lift_params.lift_height = kStackUpHeight;
272 params.lift_params.lift_arm = kStackUpArm;
Austin Schuhf14727e2015-03-08 18:49:12 -0700273 params.grab_after_lift = true;
274 fridge_closed_ = true;
275
276 action_queue_.EnqueueAction(actors::MakeStackAndLiftAction(params));
277 }
278
Brian Silverman10043572015-03-21 23:43:50 -0700279 if (data.PosEdge(kStackAndHold) || data.PosEdge(kSetStackDownAndHold)) {
Austin Schuhf14727e2015-03-08 18:49:12 -0700280 actors::StackAndHoldParams params;
281 params.bottom = 0.020;
282 params.over_box_before_place_height = 0.39;
283
Brian Silverman10043572015-03-21 23:43:50 -0700284 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700285 params.clamp_pause_time = 0.25;
Brian Silverman10043572015-03-21 23:43:50 -0700286 params.claw_clamp_angle = kClawTotePackAngle;
Austin Schuhf14727e2015-03-08 18:49:12 -0700287
288 params.hold_height = 0.68;
Brian Silverman10043572015-03-21 23:43:50 -0700289 params.claw_out_angle = 0.6;
290
291 if (data.PosEdge(kSetStackDownAndHold)) {
292 params.place_not_stack = true;
293 params.clamp_pause_time = 0.1;
294 //params.claw_clamp_angle = kClawTotePackAngle - 0.5;
295 } else {
296 params.place_not_stack = false;
297 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700298
299 action_queue_.EnqueueAction(actors::MakeStackAndHoldAction(params));
300 fridge_closed_ = true;
301 }
302
303 // TODO(austin): Figure out what action needed to pull the 6th tote into the
304 // claw.
305
306 // Lower the fridge from holding the stack, grab the stack, and then lift.
307 if (data.PosEdge(kHeldToLift)) {
308 actors::HeldToLiftParams params;
Brian Silverman10043572015-03-21 23:43:50 -0700309 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700310 params.clamp_pause_time = 0.1;
Brian Silverman10043572015-03-21 23:43:50 -0700311 params.before_lift_settle_time = 0.1;
Austin Schuhf14727e2015-03-08 18:49:12 -0700312 params.bottom_height = 0.020;
313 params.claw_out_angle = 0.6;
Brian Silverman697d07b2015-03-19 23:41:11 -0700314 params.lift_params.lift_height = kStackUpHeight;
315 params.lift_params.lift_arm = kStackUpArm;
Austin Schuhf14727e2015-03-08 18:49:12 -0700316 fridge_closed_ = true;
317
318 action_queue_.EnqueueAction(actors::MakeHeldToLiftAction(params));
319 }
320
Brian Silverman10043572015-03-21 23:43:50 -0700321 // Lift the can up.
322 if (data.PosEdge(kCanUp)) {
323 actors::LiftParams params;
324 params.lift_height = 0.68;
325 params.lift_arm = 0.3;
Brian Silverman697d07b2015-03-19 23:41:11 -0700326 params.pack_claw = false;
327 params.pack_claw_angle = 0;
Brian Silverman10043572015-03-21 23:43:50 -0700328 fridge_closed_ = true;
329
330 action_queue_.EnqueueAction(actors::MakeLiftAction(params));
331 }
332
Austin Schuhf14727e2015-03-08 18:49:12 -0700333 // Pick up a tote from the ground and put it in the bottom of the bot.
334 if (data.PosEdge(kPickup)) {
335 actors::PickupParams params;
336 // Lift to here initially.
337 params.pickup_angle = 0.9;
338 // Start sucking here
339 params.suck_angle = 0.8;
340 // Go back down to here to finish sucking.
341 params.suck_angle_finish = 0.4;
342 // Pack the box back in here.
343 params.pickup_finish_angle = kClawTotePackAngle;
344 params.intake_time = 0.8;
345 params.intake_voltage = 7.0;
346 action_queue_.EnqueueAction(actors::MakePickupAction(params));
347 }
348
349 // Place stack on a tote in the tray, and grab it.
350 if (data.PosEdge(kStack)) {
351 actors::StackParams params;
352 params.claw_out_angle = 0.6;
353 params.bottom = 0.020;
Brian Silverman10043572015-03-21 23:43:50 -0700354 params.only_place = false;
355 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700356 params.over_box_before_place_height = 0.39;
357 action_queue_.EnqueueAction(actors::MakeStackAction(params));
358 claw_rollers_closed_ = true;
Brian Silverman10043572015-03-21 23:43:50 -0700359 fridge_closed_ = true;
Austin Schuhf14727e2015-03-08 18:49:12 -0700360 }
361
Brian Silverman10043572015-03-21 23:43:50 -0700362 if (data.PosEdge(kScore)) {
Brian Silverman913eafa2015-03-19 23:42:16 -0700363 action_queue_.EnqueueAction(
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700364 actors::MakeScoreAction(MakeScoreParams()));
Brian Silverman913eafa2015-03-19 23:42:16 -0700365 fridge_closed_ = false;
Brian Silverman10043572015-03-21 23:43:50 -0700366 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700367
Brian Silverman913eafa2015-03-19 23:42:16 -0700368 if (data.PosEdge(kCoopTop)) {
369 action_queue_.EnqueueAction(
370 actors::MakeScoreAction(MakeCoopTopParams(false)));
371 }
372 if (data.PosEdge(kCoopTopRetract)) {
373 action_queue_.EnqueueAction(
374 actors::MakeScoreAction(MakeCoopTopParams(true)));
375 fridge_closed_ = false;
376 }
377
378 if (data.PosEdge(kCoopBottom)) {
379 action_queue_.EnqueueAction(
380 actors::MakeScoreAction(MakeCoopBottomParams(false)));
381 }
382 if (data.PosEdge(kCoopBottomRetract)) {
383 action_queue_.EnqueueAction(
384 actors::MakeScoreAction(MakeCoopBottomParams(true)));
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800385 fridge_closed_ = false;
386 }
387
Brian Silverman10043572015-03-21 23:43:50 -0700388 if (data.PosEdge(kFridgeToggle)) {
389 fridge_closed_ = !fridge_closed_;
390 }
391
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800392 if (data.PosEdge(ControlBit::kEnabled)) {
393 // If we got enabled, wait for everything to zero.
394 LOG(INFO, "Waiting for zero.\n");
395 waiting_for_zero_ = true;
396 }
397
Austin Schuh700b9222015-03-01 03:03:15 -0800398 claw_queue.status.FetchLatest();
399 fridge_queue.status.FetchLatest();
400 if (!claw_queue.status.get()) {
401 LOG(ERROR, "Got no claw status packet.\n");
402 // Not safe to continue.
403 return;
404 }
405 if (!fridge_queue.status.get()) {
406 LOG(ERROR, "Got no fridge status packet.\n");
407 return;
408 }
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800409
Austin Schuh700b9222015-03-01 03:03:15 -0800410 if (claw_queue.status->zeroed && fridge_queue.status->zeroed) {
411 if (waiting_for_zero_) {
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800412 LOG(INFO, "Zeroed! Starting teleop mode.\n");
413 waiting_for_zero_ = false;
414
415 // Set the initial goals to where we are now.
416 elevator_goal_ = fridge_queue.status->goal_height;
417 arm_goal_ = fridge_queue.status->goal_angle;
418 claw_goal_ = claw_queue.status->angle;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800419 }
420 } else {
Austin Schuh700b9222015-03-01 03:03:15 -0800421 waiting_for_zero_ = true;
422 return;
423 }
424
425 if (!waiting_for_zero_) {
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800426 if (!action_queue_.Running()) {
427 auto new_fridge_goal = fridge_queue.goal.MakeMessage();
Austin Schuh6e242ac2015-03-07 17:08:21 -0800428 new_fridge_goal->max_velocity = elevator_params_.velocity;
429 new_fridge_goal->max_acceleration = elevator_params_.acceleration;
Austin Schuh1d44bd42015-03-15 16:40:45 -0700430 new_fridge_goal->profiling_type = 0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800431 new_fridge_goal->height = elevator_goal_;
Austin Schuh6e242ac2015-03-07 17:08:21 -0800432 new_fridge_goal->velocity = 0.0;
433 new_fridge_goal->max_angular_velocity = arm_params_.velocity;
434 new_fridge_goal->max_angular_acceleration = arm_params_.acceleration;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800435 new_fridge_goal->angle = arm_goal_;
436 new_fridge_goal->angular_velocity = 0.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800437 new_fridge_goal->grabbers.top_front = fridge_closed_;
438 new_fridge_goal->grabbers.top_back = fridge_closed_;
439 new_fridge_goal->grabbers.bottom_front = fridge_closed_;
440 new_fridge_goal->grabbers.bottom_back = fridge_closed_;
441
442 if (!new_fridge_goal.Send()) {
443 LOG(ERROR, "Sending fridge goal failed.\n");
444 } else {
445 LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_,
446 arm_goal_);
447 }
448 if (!claw_queue.goal.MakeWithBuilder()
449 .angle(claw_goal_)
450 .rollers_closed(claw_rollers_closed_)
Brian Silverman10043572015-03-21 23:43:50 -0700451 .max_velocity(4.0)
452 .max_acceleration(6.0)
Austin Schuhf14727e2015-03-08 18:49:12 -0700453 .intake(intake_power)
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800454 .Send()) {
455 LOG(ERROR, "Sending claw goal failed.\n");
456 }
457 }
458 }
459
Austin Schuhd8b2a242015-02-22 21:46:53 -0800460 if (action_queue_.Running()) {
461 // If we are running an action, update our goals to the current goals.
462 control_loops::fridge_queue.status.FetchLatest();
463 if (control_loops::fridge_queue.status.get()) {
464 arm_goal_ = control_loops::fridge_queue.status->goal_angle;
465 elevator_goal_ = control_loops::fridge_queue.status->goal_height;
466 } else {
467 LOG(ERROR, "No fridge status!\n");
468 }
469
470 // If we are running an action, update our goals to the current goals.
471 control_loops::claw_queue.status.FetchLatest();
472 if (control_loops::claw_queue.status.get()) {
473 claw_goal_ = control_loops::claw_queue.status->goal_angle;
474 } else {
475 LOG(ERROR, "No fridge status!\n");
476 }
477 }
Brian Silverman20141f92015-01-05 17:39:01 -0800478 action_queue_.Tick();
479 was_running_ = action_queue_.Running();
480 }
481
482 private:
Austin Schuh6182f8d2015-02-14 22:15:04 -0800483 void StartAuto() {
484 LOG(INFO, "Starting auto mode\n");
485 ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(true).Send();
486 }
487
488 void StopAuto() {
489 LOG(INFO, "Stopping auto mode\n");
490 ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(false).Send();
491 }
492
Brian Silverman20141f92015-01-05 17:39:01 -0800493 bool was_running_;
Daniel Petti61896522015-02-15 18:01:43 -0800494
495 // Previous goals for systems.
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800496 double elevator_goal_ = 0.2;
Daniel Petti61896522015-02-15 18:01:43 -0800497 double arm_goal_ = 0.0;
498 double claw_goal_ = 0.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800499 bool claw_rollers_closed_ = false;
500 bool fridge_closed_ = false;
Austin Schuh6e242ac2015-03-07 17:08:21 -0800501 actors::ProfileParams arm_params_ = kArmMove;
502 actors::ProfileParams elevator_params_ = kElevatorMove;
Daniel Petti61896522015-02-15 18:01:43 -0800503
504 // If we're waiting for the subsystems to zero.
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800505 bool waiting_for_zero_ = true;
Daniel Petti61896522015-02-15 18:01:43 -0800506
Austin Schuh6182f8d2015-02-14 22:15:04 -0800507 bool auto_running_ = false;
508
Austin Schuh331e13d2015-02-15 00:16:51 -0800509 ::aos::common::actions::ActionQueue action_queue_;
Brian Silverman20141f92015-01-05 17:39:01 -0800510
511 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
512 ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING,
513 "no drivetrain status");
514};
515
516} // namespace joysticks
517} // namespace input
518} // namespace frc971
519
520int main() {
521 ::aos::Init();
522 ::frc971::input::joysticks::Reader reader;
523 reader.Run();
524 ::aos::Cleanup();
525}