blob: 8ef2966dea8412ff491f03f745397b5566a97408 [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
Austin Schuh6e242ac2015-03-07 17:08:21 -080063constexpr actors::ProfileParams kArmMove{1.00, 1.0};
64constexpr actors::ProfileParams kElevatorMove{1.00, 3.2};
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);
Austin Schuhf14727e2015-03-08 18:49:12 -070096// Release the stack and retract back in.
Brian Silverman10043572015-03-21 23:43:50 -070097const ButtonLocation kRetractFromScore(4, 12);
Austin Schuhf14727e2015-03-08 18:49:12 -070098
Brian Silverman913eafa2015-03-19 23:42:16 -070099const ButtonLocation kCoopTop(3, 8);
100const ButtonLocation kCoopTopRetract(3, 7);
101const ButtonLocation kCoopBottom(3, 6);
102const ButtonLocation kCoopBottomRetract(3, 9);
103
Brian Silverman10043572015-03-21 23:43:50 -0700104const POVLocation kFridgeToggle(4, 270);
Austin Schuhf14727e2015-03-08 18:49:12 -0700105const ButtonLocation kSpit(4, 3);
106
107// Set stack down in the bot.
Brian Silverman10043572015-03-21 23:43:50 -0700108const POVLocation kSetStackDownAndHold(4, 90);
Austin Schuhf14727e2015-03-08 18:49:12 -0700109
110const double kClawTotePackAngle = 0.95;
Brian Silverman10043572015-03-21 23:43:50 -0700111const double kArmRaiseLowerClearance = -0.08;
Brian Silverman20141f92015-01-05 17:39:01 -0800112
113class Reader : public ::aos::input::JoystickInput {
114 public:
Austin Schuh331e13d2015-02-15 00:16:51 -0800115 Reader() : was_running_(false) {}
Brian Silverman20141f92015-01-05 17:39:01 -0800116
Brian Silverman913eafa2015-03-19 23:42:16 -0700117 static actors::ScoreParams MakeScoreParams(bool place_the_stack) {
118 actors::ScoreParams r;
119 r.place_the_stack = place_the_stack;
120 r.upper_move_height = 0.14;
121 r.begin_horizontal_move_height = 0.13;
122 r.horizontal_move_target = -0.7;
123 r.place_height = -0.10;
124 r.home_return_height = 0.1;
125 return r;
126 }
127
128 static actors::ScoreParams MakeCoopTopParams(bool place_the_stack) {
129 actors::ScoreParams r;
130 r.place_the_stack = place_the_stack;
131 r.upper_move_height = 0.52;
132 r.begin_horizontal_move_height = 0.5;
133 r.horizontal_move_target = -0.48;
134 r.place_height = 0.39;
135 r.home_return_height = 0.1;
136 return r;
137 }
138
139 static actors::ScoreParams MakeCoopBottomParams(bool place_the_stack) {
140 actors::ScoreParams r;
141 r.place_the_stack = place_the_stack;
142 r.upper_move_height = 0.17;
143 r.begin_horizontal_move_height = 0.16;
144 r.horizontal_move_target = -0.7;
145 r.place_height = 0.0;
146 r.home_return_height = 0.1;
147 return r;
148 }
149
Brian Silverman20141f92015-01-05 17:39:01 -0800150 virtual void RunIteration(const ::aos::input::driver_station::Data &data) {
Austin Schuh6182f8d2015-02-14 22:15:04 -0800151 bool last_auto_running = auto_running_;
152 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
Brian Silvermane1103e62015-02-15 02:03:38 -0500153 data.GetControlBit(ControlBit::kEnabled);
Austin Schuh6182f8d2015-02-14 22:15:04 -0800154 if (auto_running_ != last_auto_running) {
155 if (auto_running_) {
156 StartAuto();
157 } else {
158 StopAuto();
Brian Silverman20141f92015-01-05 17:39:01 -0800159 }
Austin Schuh6182f8d2015-02-14 22:15:04 -0800160 }
161
162 if (!data.GetControlBit(ControlBit::kAutonomous)) {
Daniel Petti61896522015-02-15 18:01:43 -0800163 HandleDrivetrain(data);
Austin Schuhf14727e2015-03-08 18:49:12 -0700164 HandleTeleop(data);
Brian Silverman20141f92015-01-05 17:39:01 -0800165 }
166 }
167
168 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
Brian Silverman20141f92015-01-05 17:39:01 -0800169 const double wheel = -data.GetAxis(kSteeringWheel);
170 const double throttle = -data.GetAxis(kDriveThrottle);
Brian Silverman20141f92015-01-05 17:39:01 -0800171
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500172 if (!drivetrain_queue.goal.MakeWithBuilder()
Brian Silverman20141f92015-01-05 17:39:01 -0800173 .steering(wheel)
174 .throttle(throttle)
Brian Silverman20141f92015-01-05 17:39:01 -0800175 .quickturn(data.IsPressed(kQuickTurn))
Austin Schuh331e13d2015-02-15 00:16:51 -0800176 .control_loop_driving(false)
Brian Silverman20141f92015-01-05 17:39:01 -0800177 .Send()) {
178 LOG(WARNING, "sending stick values failed\n");
179 }
Brian Silverman20141f92015-01-05 17:39:01 -0800180 }
181
182 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
Austin Schuhf14727e2015-03-08 18:49:12 -0700183 double intake_power = 0.0;
Brian Silverman20141f92015-01-05 17:39:01 -0800184 if (!data.GetControlBit(ControlBit::kEnabled)) {
185 action_queue_.CancelAllActions();
Austin Schuh6182f8d2015-02-14 22:15:04 -0800186 LOG(DEBUG, "Canceling\n");
Brian Silverman20141f92015-01-05 17:39:01 -0800187 }
188
Austin Schuhf14727e2015-03-08 18:49:12 -0700189 if (data.IsPressed(kRollersIn)) {
190 intake_power = 10.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800191 claw_goal_ = 0.0;
Austin Schuhd8b2a242015-02-22 21:46:53 -0800192 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700193 if (data.IsPressed(kSpit)) {
194 intake_power = -12.0;
Austin Schuhd8b2a242015-02-22 21:46:53 -0800195 }
Austin Schuh994d42c2015-03-01 00:02:17 -0800196
Austin Schuhf14727e2015-03-08 18:49:12 -0700197 // Toggle button for the claw
198 if (data.PosEdge(kClawToggle)) {
199 claw_rollers_closed_ = !claw_rollers_closed_;
Austin Schuh994d42c2015-03-01 00:02:17 -0800200 }
201
Austin Schuhf14727e2015-03-08 18:49:12 -0700202 /*
203 if (data.IsPressed(kClawClosed)) {
204 claw_rollers_closed_ = true;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800205 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700206 */
Austin Schuh700b9222015-03-01 03:03:15 -0800207
Austin Schuhf14727e2015-03-08 18:49:12 -0700208 // Horizontal can pickup.
Austin Schuh700b9222015-03-01 03:03:15 -0800209 if (data.PosEdge(kElevatorCanUp)) {
210 actors::HorizontalCanPickupParams params;
211 params.elevator_height = 0.3;
Brian Silverman10043572015-03-21 23:43:50 -0700212 params.pickup_angle = 0.40;
213 params.suck_time = 0.08;
Austin Schuh700b9222015-03-01 03:03:15 -0800214 params.suck_power = 8.0;
215
216 params.claw_settle_time = 0.05;
217 params.claw_settle_power = 5.0;
218 params.claw_full_lift_angle = 1.35;
219 params.claw_end_angle = 0.5;
Austin Schuhf14727e2015-03-08 18:49:12 -0700220
Brian Silverman10043572015-03-21 23:43:50 -0700221 // End low so we don't drop it.
222 params.elevator_end_height = 0.3;
223 params.arm_end_angle = 0.0;
Austin Schuh700b9222015-03-01 03:03:15 -0800224 action_queue_.EnqueueAction(
225 actors::MakeHorizontalCanPickupAction(params));
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800226 fridge_closed_ = true;
227 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700228
229 // -0.942503 arm, 0.374752 elevator
230 // Vertical can pickup.
231 if (data.PosEdge(kCanPickup)) {
232 actors::CanPickupParams params;
233 params.pickup_angle = -0.93;
234 params.pickup_height = 0.265;
235 params.lift_height = 0.65;
Brian Silverman10043572015-03-21 23:43:50 -0700236 // End low so the can is supported.
237 params.end_height = 0.3;
238 params.end_angle = 0.0;
Austin Schuhf14727e2015-03-08 18:49:12 -0700239 action_queue_.EnqueueAction(actors::MakeCanPickupAction(params));
240 fridge_closed_ = true;
241 }
242
243 // Tote chute pull in when button is pressed, pack when done.
244 if (data.IsPressed(kToteChute)) {
245 claw_goal_ = 0.8;
246 intake_power = 7.0;
247 }
248 if (data.NegEdge(kToteChute)) {
249 claw_goal_ = kClawTotePackAngle;
250 }
251
252 if (data.PosEdge(kStackAndLift)) {
253 actors::StackAndLiftParams params;
254 params.stack_params.claw_out_angle = 0.6;
255 params.stack_params.bottom = 0.020;
256 params.stack_params.over_box_before_place_height = 0.39;
Brian Silverman10043572015-03-21 23:43:50 -0700257 params.stack_params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700258
259 params.grab_after_stack = true;
260 params.clamp_pause_time = 0.1;
261 params.lift_params.lift_height = 0.45;
262 params.lift_params.lift_arm = 0.3;
263 params.grab_after_lift = true;
264 fridge_closed_ = true;
265
266 action_queue_.EnqueueAction(actors::MakeStackAndLiftAction(params));
267 }
268
Brian Silverman10043572015-03-21 23:43:50 -0700269 if (data.PosEdge(kStackAndHold) || data.PosEdge(kSetStackDownAndHold)) {
Austin Schuhf14727e2015-03-08 18:49:12 -0700270 actors::StackAndHoldParams params;
271 params.bottom = 0.020;
272 params.over_box_before_place_height = 0.39;
273
Brian Silverman10043572015-03-21 23:43:50 -0700274 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700275 params.clamp_pause_time = 0.25;
Brian Silverman10043572015-03-21 23:43:50 -0700276 params.claw_clamp_angle = kClawTotePackAngle;
Austin Schuhf14727e2015-03-08 18:49:12 -0700277
278 params.hold_height = 0.68;
Brian Silverman10043572015-03-21 23:43:50 -0700279 params.claw_out_angle = 0.6;
280
281 if (data.PosEdge(kSetStackDownAndHold)) {
282 params.place_not_stack = true;
283 params.clamp_pause_time = 0.1;
284 //params.claw_clamp_angle = kClawTotePackAngle - 0.5;
285 } else {
286 params.place_not_stack = false;
287 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700288
289 action_queue_.EnqueueAction(actors::MakeStackAndHoldAction(params));
290 fridge_closed_ = true;
291 }
292
293 // TODO(austin): Figure out what action needed to pull the 6th tote into the
294 // claw.
295
296 // Lower the fridge from holding the stack, grab the stack, and then lift.
297 if (data.PosEdge(kHeldToLift)) {
298 actors::HeldToLiftParams params;
Brian Silverman10043572015-03-21 23:43:50 -0700299 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700300 params.clamp_pause_time = 0.1;
Brian Silverman10043572015-03-21 23:43:50 -0700301 params.before_lift_settle_time = 0.1;
Austin Schuhf14727e2015-03-08 18:49:12 -0700302 params.bottom_height = 0.020;
303 params.claw_out_angle = 0.6;
304 params.lift_params.lift_height = 0.45;
305 params.lift_params.lift_arm = 0.3;
306 fridge_closed_ = true;
307
308 action_queue_.EnqueueAction(actors::MakeHeldToLiftAction(params));
309 }
310
Brian Silverman10043572015-03-21 23:43:50 -0700311 // Lift the can up.
312 if (data.PosEdge(kCanUp)) {
313 actors::LiftParams params;
314 params.lift_height = 0.68;
315 params.lift_arm = 0.3;
316 fridge_closed_ = true;
317
318 action_queue_.EnqueueAction(actors::MakeLiftAction(params));
319 }
320
Austin Schuhf14727e2015-03-08 18:49:12 -0700321 // Pick up a tote from the ground and put it in the bottom of the bot.
322 if (data.PosEdge(kPickup)) {
323 actors::PickupParams params;
324 // Lift to here initially.
325 params.pickup_angle = 0.9;
326 // Start sucking here
327 params.suck_angle = 0.8;
328 // Go back down to here to finish sucking.
329 params.suck_angle_finish = 0.4;
330 // Pack the box back in here.
331 params.pickup_finish_angle = kClawTotePackAngle;
332 params.intake_time = 0.8;
333 params.intake_voltage = 7.0;
334 action_queue_.EnqueueAction(actors::MakePickupAction(params));
335 }
336
337 // Place stack on a tote in the tray, and grab it.
338 if (data.PosEdge(kStack)) {
339 actors::StackParams params;
340 params.claw_out_angle = 0.6;
341 params.bottom = 0.020;
Brian Silverman10043572015-03-21 23:43:50 -0700342 params.only_place = false;
343 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700344 params.over_box_before_place_height = 0.39;
345 action_queue_.EnqueueAction(actors::MakeStackAction(params));
346 claw_rollers_closed_ = true;
Brian Silverman10043572015-03-21 23:43:50 -0700347 fridge_closed_ = true;
Austin Schuhf14727e2015-03-08 18:49:12 -0700348 }
349
Brian Silverman10043572015-03-21 23:43:50 -0700350 if (data.PosEdge(kScore)) {
Brian Silverman913eafa2015-03-19 23:42:16 -0700351 action_queue_.EnqueueAction(
352 actors::MakeScoreAction(MakeScoreParams(false)));
353 }
354 if (data.PosEdge(kRetractFromScore)) {
355 action_queue_.EnqueueAction(
356 actors::MakeScoreAction(MakeScoreParams(true)));
357 fridge_closed_ = false;
Brian Silverman10043572015-03-21 23:43:50 -0700358 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700359
Brian Silverman913eafa2015-03-19 23:42:16 -0700360 if (data.PosEdge(kCoopTop)) {
361 action_queue_.EnqueueAction(
362 actors::MakeScoreAction(MakeCoopTopParams(false)));
363 }
364 if (data.PosEdge(kCoopTopRetract)) {
365 action_queue_.EnqueueAction(
366 actors::MakeScoreAction(MakeCoopTopParams(true)));
367 fridge_closed_ = false;
368 }
369
370 if (data.PosEdge(kCoopBottom)) {
371 action_queue_.EnqueueAction(
372 actors::MakeScoreAction(MakeCoopBottomParams(false)));
373 }
374 if (data.PosEdge(kCoopBottomRetract)) {
375 action_queue_.EnqueueAction(
376 actors::MakeScoreAction(MakeCoopBottomParams(true)));
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800377 fridge_closed_ = false;
378 }
379
Brian Silverman10043572015-03-21 23:43:50 -0700380 if (data.PosEdge(kFridgeToggle)) {
381 fridge_closed_ = !fridge_closed_;
382 }
383
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800384 if (data.PosEdge(ControlBit::kEnabled)) {
385 // If we got enabled, wait for everything to zero.
386 LOG(INFO, "Waiting for zero.\n");
387 waiting_for_zero_ = true;
388 }
389
Austin Schuh700b9222015-03-01 03:03:15 -0800390 claw_queue.status.FetchLatest();
391 fridge_queue.status.FetchLatest();
392 if (!claw_queue.status.get()) {
393 LOG(ERROR, "Got no claw status packet.\n");
394 // Not safe to continue.
395 return;
396 }
397 if (!fridge_queue.status.get()) {
398 LOG(ERROR, "Got no fridge status packet.\n");
399 return;
400 }
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800401
Austin Schuh700b9222015-03-01 03:03:15 -0800402 if (claw_queue.status->zeroed && fridge_queue.status->zeroed) {
403 if (waiting_for_zero_) {
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800404 LOG(INFO, "Zeroed! Starting teleop mode.\n");
405 waiting_for_zero_ = false;
406
407 // Set the initial goals to where we are now.
408 elevator_goal_ = fridge_queue.status->goal_height;
409 arm_goal_ = fridge_queue.status->goal_angle;
410 claw_goal_ = claw_queue.status->angle;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800411 }
412 } else {
Austin Schuh700b9222015-03-01 03:03:15 -0800413 waiting_for_zero_ = true;
414 return;
415 }
416
417 if (!waiting_for_zero_) {
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800418 if (!action_queue_.Running()) {
419 auto new_fridge_goal = fridge_queue.goal.MakeMessage();
Austin Schuh6e242ac2015-03-07 17:08:21 -0800420 new_fridge_goal->max_velocity = elevator_params_.velocity;
421 new_fridge_goal->max_acceleration = elevator_params_.acceleration;
Austin Schuh1d44bd42015-03-15 16:40:45 -0700422 new_fridge_goal->profiling_type = 0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800423 new_fridge_goal->height = elevator_goal_;
Austin Schuh6e242ac2015-03-07 17:08:21 -0800424 new_fridge_goal->velocity = 0.0;
425 new_fridge_goal->max_angular_velocity = arm_params_.velocity;
426 new_fridge_goal->max_angular_acceleration = arm_params_.acceleration;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800427 new_fridge_goal->angle = arm_goal_;
428 new_fridge_goal->angular_velocity = 0.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800429 new_fridge_goal->grabbers.top_front = fridge_closed_;
430 new_fridge_goal->grabbers.top_back = fridge_closed_;
431 new_fridge_goal->grabbers.bottom_front = fridge_closed_;
432 new_fridge_goal->grabbers.bottom_back = fridge_closed_;
433
434 if (!new_fridge_goal.Send()) {
435 LOG(ERROR, "Sending fridge goal failed.\n");
436 } else {
437 LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_,
438 arm_goal_);
439 }
440 if (!claw_queue.goal.MakeWithBuilder()
441 .angle(claw_goal_)
442 .rollers_closed(claw_rollers_closed_)
Brian Silverman10043572015-03-21 23:43:50 -0700443 .max_velocity(4.0)
444 .max_acceleration(6.0)
Austin Schuhf14727e2015-03-08 18:49:12 -0700445 .intake(intake_power)
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800446 .Send()) {
447 LOG(ERROR, "Sending claw goal failed.\n");
448 }
449 }
450 }
451
Austin Schuhd8b2a242015-02-22 21:46:53 -0800452 if (action_queue_.Running()) {
453 // If we are running an action, update our goals to the current goals.
454 control_loops::fridge_queue.status.FetchLatest();
455 if (control_loops::fridge_queue.status.get()) {
456 arm_goal_ = control_loops::fridge_queue.status->goal_angle;
457 elevator_goal_ = control_loops::fridge_queue.status->goal_height;
458 } else {
459 LOG(ERROR, "No fridge status!\n");
460 }
461
462 // If we are running an action, update our goals to the current goals.
463 control_loops::claw_queue.status.FetchLatest();
464 if (control_loops::claw_queue.status.get()) {
465 claw_goal_ = control_loops::claw_queue.status->goal_angle;
466 } else {
467 LOG(ERROR, "No fridge status!\n");
468 }
469 }
Brian Silverman20141f92015-01-05 17:39:01 -0800470 action_queue_.Tick();
471 was_running_ = action_queue_.Running();
472 }
473
474 private:
Austin Schuh6182f8d2015-02-14 22:15:04 -0800475 void StartAuto() {
476 LOG(INFO, "Starting auto mode\n");
477 ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(true).Send();
478 }
479
480 void StopAuto() {
481 LOG(INFO, "Stopping auto mode\n");
482 ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(false).Send();
483 }
484
Brian Silverman20141f92015-01-05 17:39:01 -0800485 bool was_running_;
Daniel Petti61896522015-02-15 18:01:43 -0800486
487 // Previous goals for systems.
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800488 double elevator_goal_ = 0.2;
Daniel Petti61896522015-02-15 18:01:43 -0800489 double arm_goal_ = 0.0;
490 double claw_goal_ = 0.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800491 bool claw_rollers_closed_ = false;
492 bool fridge_closed_ = false;
Austin Schuh6e242ac2015-03-07 17:08:21 -0800493 actors::ProfileParams arm_params_ = kArmMove;
494 actors::ProfileParams elevator_params_ = kElevatorMove;
Daniel Petti61896522015-02-15 18:01:43 -0800495
496 // If we're waiting for the subsystems to zero.
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800497 bool waiting_for_zero_ = true;
Daniel Petti61896522015-02-15 18:01:43 -0800498
Austin Schuh6182f8d2015-02-14 22:15:04 -0800499 bool auto_running_ = false;
500
Austin Schuh331e13d2015-02-15 00:16:51 -0800501 ::aos::common::actions::ActionQueue action_queue_;
Brian Silverman20141f92015-01-05 17:39:01 -0800502
503 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
504 ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING,
505 "no drivetrain status");
506};
507
508} // namespace joysticks
509} // namespace input
510} // namespace frc971
511
512int main() {
513 ::aos::Init();
514 ::frc971::input::joysticks::Reader reader;
515 reader.Run();
516 ::aos::Cleanup();
517}