blob: 6311100360abde3d43ac87016a7fe841c4f672ae [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);
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 Silvermanb9811eb2015-03-20 16:54:41 -0700101const ButtonLocation kRetractFromScore(4, 12);
102
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
112class Reader : public ::aos::input::JoystickInput {
113 public:
Austin Schuh331e13d2015-02-15 00:16:51 -0800114 Reader() : was_running_(false) {}
Brian Silverman20141f92015-01-05 17:39:01 -0800115
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700116 static actors::ScoreParams MakeScoreParams() {
Brian Silverman913eafa2015-03-19 23:42:16 -0700117 actors::ScoreParams r;
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700118 r.move_the_stack = r.place_the_stack = true;
Brian Silverman913eafa2015-03-19 23:42:16 -0700119 r.upper_move_height = 0.14;
120 r.begin_horizontal_move_height = 0.13;
121 r.horizontal_move_target = -0.7;
122 r.place_height = -0.10;
123 r.home_return_height = 0.1;
124 return r;
125 }
126
127 static actors::ScoreParams MakeCoopTopParams(bool place_the_stack) {
128 actors::ScoreParams r;
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700129 r.move_the_stack = !place_the_stack;
Brian Silverman913eafa2015-03-19 23:42:16 -0700130 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;
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700141 r.move_the_stack = !place_the_stack;
Brian Silverman913eafa2015-03-19 23:42:16 -0700142 r.place_the_stack = place_the_stack;
143 r.upper_move_height = 0.17;
144 r.begin_horizontal_move_height = 0.16;
145 r.horizontal_move_target = -0.7;
146 r.place_height = 0.0;
147 r.home_return_height = 0.1;
148 return r;
149 }
150
Brian Silverman20141f92015-01-05 17:39:01 -0800151 virtual void RunIteration(const ::aos::input::driver_station::Data &data) {
Austin Schuh6182f8d2015-02-14 22:15:04 -0800152 bool last_auto_running = auto_running_;
153 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
Brian Silvermane1103e62015-02-15 02:03:38 -0500154 data.GetControlBit(ControlBit::kEnabled);
Austin Schuh6182f8d2015-02-14 22:15:04 -0800155 if (auto_running_ != last_auto_running) {
156 if (auto_running_) {
157 StartAuto();
158 } else {
159 StopAuto();
Brian Silverman20141f92015-01-05 17:39:01 -0800160 }
Austin Schuh6182f8d2015-02-14 22:15:04 -0800161 }
162
163 if (!data.GetControlBit(ControlBit::kAutonomous)) {
Daniel Petti61896522015-02-15 18:01:43 -0800164 HandleDrivetrain(data);
Austin Schuhf14727e2015-03-08 18:49:12 -0700165 HandleTeleop(data);
Brian Silverman20141f92015-01-05 17:39:01 -0800166 }
167 }
168
169 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
Brian Silverman20141f92015-01-05 17:39:01 -0800170 const double wheel = -data.GetAxis(kSteeringWheel);
171 const double throttle = -data.GetAxis(kDriveThrottle);
Brian Silverman20141f92015-01-05 17:39:01 -0800172
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500173 if (!drivetrain_queue.goal.MakeWithBuilder()
Brian Silverman20141f92015-01-05 17:39:01 -0800174 .steering(wheel)
175 .throttle(throttle)
Brian Silverman20141f92015-01-05 17:39:01 -0800176 .quickturn(data.IsPressed(kQuickTurn))
Austin Schuh331e13d2015-02-15 00:16:51 -0800177 .control_loop_driving(false)
Brian Silverman20141f92015-01-05 17:39:01 -0800178 .Send()) {
179 LOG(WARNING, "sending stick values failed\n");
180 }
Brian Silverman20141f92015-01-05 17:39:01 -0800181 }
182
183 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
Austin Schuhf14727e2015-03-08 18:49:12 -0700184 double intake_power = 0.0;
Brian Silverman20141f92015-01-05 17:39:01 -0800185 if (!data.GetControlBit(ControlBit::kEnabled)) {
186 action_queue_.CancelAllActions();
Austin Schuh6182f8d2015-02-14 22:15:04 -0800187 LOG(DEBUG, "Canceling\n");
Brian Silverman20141f92015-01-05 17:39:01 -0800188 }
189
Austin Schuhf14727e2015-03-08 18:49:12 -0700190 if (data.IsPressed(kRollersIn)) {
191 intake_power = 10.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800192 claw_goal_ = 0.0;
Austin Schuhd8b2a242015-02-22 21:46:53 -0800193 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700194 if (data.IsPressed(kSpit)) {
195 intake_power = -12.0;
Austin Schuhd8b2a242015-02-22 21:46:53 -0800196 }
Austin Schuh994d42c2015-03-01 00:02:17 -0800197
Austin Schuhf14727e2015-03-08 18:49:12 -0700198 // Toggle button for the claw
199 if (data.PosEdge(kClawToggle)) {
200 claw_rollers_closed_ = !claw_rollers_closed_;
Austin Schuh994d42c2015-03-01 00:02:17 -0800201 }
202
Austin Schuhf14727e2015-03-08 18:49:12 -0700203 /*
204 if (data.IsPressed(kClawClosed)) {
205 claw_rollers_closed_ = true;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800206 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700207 */
Austin Schuh700b9222015-03-01 03:03:15 -0800208
Austin Schuhf14727e2015-03-08 18:49:12 -0700209 // Horizontal can pickup.
Austin Schuh700b9222015-03-01 03:03:15 -0800210 if (data.PosEdge(kElevatorCanUp)) {
211 actors::HorizontalCanPickupParams params;
212 params.elevator_height = 0.3;
Brian Silverman10043572015-03-21 23:43:50 -0700213 params.pickup_angle = 0.40;
214 params.suck_time = 0.08;
Austin Schuh700b9222015-03-01 03:03:15 -0800215 params.suck_power = 8.0;
216
217 params.claw_settle_time = 0.05;
218 params.claw_settle_power = 5.0;
219 params.claw_full_lift_angle = 1.35;
220 params.claw_end_angle = 0.5;
Austin Schuhf14727e2015-03-08 18:49:12 -0700221
Brian Silverman10043572015-03-21 23:43:50 -0700222 // End low so we don't drop it.
223 params.elevator_end_height = 0.3;
224 params.arm_end_angle = 0.0;
Austin Schuh700b9222015-03-01 03:03:15 -0800225 action_queue_.EnqueueAction(
226 actors::MakeHorizontalCanPickupAction(params));
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800227 fridge_closed_ = true;
228 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700229
230 // -0.942503 arm, 0.374752 elevator
231 // Vertical can pickup.
232 if (data.PosEdge(kCanPickup)) {
233 actors::CanPickupParams params;
234 params.pickup_angle = -0.93;
235 params.pickup_height = 0.265;
236 params.lift_height = 0.65;
Brian Silverman10043572015-03-21 23:43:50 -0700237 // End low so the can is supported.
238 params.end_height = 0.3;
239 params.end_angle = 0.0;
Austin Schuhf14727e2015-03-08 18:49:12 -0700240 action_queue_.EnqueueAction(actors::MakeCanPickupAction(params));
241 fridge_closed_ = true;
242 }
243
244 // Tote chute pull in when button is pressed, pack when done.
245 if (data.IsPressed(kToteChute)) {
246 claw_goal_ = 0.8;
247 intake_power = 7.0;
248 }
249 if (data.NegEdge(kToteChute)) {
250 claw_goal_ = kClawTotePackAngle;
251 }
252
253 if (data.PosEdge(kStackAndLift)) {
254 actors::StackAndLiftParams params;
255 params.stack_params.claw_out_angle = 0.6;
256 params.stack_params.bottom = 0.020;
257 params.stack_params.over_box_before_place_height = 0.39;
Brian Silverman10043572015-03-21 23:43:50 -0700258 params.stack_params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700259
260 params.grab_after_stack = true;
261 params.clamp_pause_time = 0.1;
262 params.lift_params.lift_height = 0.45;
263 params.lift_params.lift_arm = 0.3;
264 params.grab_after_lift = true;
265 fridge_closed_ = true;
266
267 action_queue_.EnqueueAction(actors::MakeStackAndLiftAction(params));
268 }
269
Brian Silverman10043572015-03-21 23:43:50 -0700270 if (data.PosEdge(kStackAndHold) || data.PosEdge(kSetStackDownAndHold)) {
Austin Schuhf14727e2015-03-08 18:49:12 -0700271 actors::StackAndHoldParams params;
272 params.bottom = 0.020;
273 params.over_box_before_place_height = 0.39;
274
Brian Silverman10043572015-03-21 23:43:50 -0700275 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700276 params.clamp_pause_time = 0.25;
Brian Silverman10043572015-03-21 23:43:50 -0700277 params.claw_clamp_angle = kClawTotePackAngle;
Austin Schuhf14727e2015-03-08 18:49:12 -0700278
279 params.hold_height = 0.68;
Brian Silverman10043572015-03-21 23:43:50 -0700280 params.claw_out_angle = 0.6;
281
282 if (data.PosEdge(kSetStackDownAndHold)) {
283 params.place_not_stack = true;
284 params.clamp_pause_time = 0.1;
285 //params.claw_clamp_angle = kClawTotePackAngle - 0.5;
286 } else {
287 params.place_not_stack = false;
288 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700289
290 action_queue_.EnqueueAction(actors::MakeStackAndHoldAction(params));
291 fridge_closed_ = true;
292 }
293
294 // TODO(austin): Figure out what action needed to pull the 6th tote into the
295 // claw.
296
297 // Lower the fridge from holding the stack, grab the stack, and then lift.
298 if (data.PosEdge(kHeldToLift)) {
299 actors::HeldToLiftParams params;
Brian Silverman10043572015-03-21 23:43:50 -0700300 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700301 params.clamp_pause_time = 0.1;
Brian Silverman10043572015-03-21 23:43:50 -0700302 params.before_lift_settle_time = 0.1;
Austin Schuhf14727e2015-03-08 18:49:12 -0700303 params.bottom_height = 0.020;
304 params.claw_out_angle = 0.6;
305 params.lift_params.lift_height = 0.45;
306 params.lift_params.lift_arm = 0.3;
307 fridge_closed_ = true;
308
309 action_queue_.EnqueueAction(actors::MakeHeldToLiftAction(params));
310 }
311
Brian Silverman10043572015-03-21 23:43:50 -0700312 // Lift the can up.
313 if (data.PosEdge(kCanUp)) {
314 actors::LiftParams params;
315 params.lift_height = 0.68;
316 params.lift_arm = 0.3;
317 fridge_closed_ = true;
318
319 action_queue_.EnqueueAction(actors::MakeLiftAction(params));
320 }
321
Austin Schuhf14727e2015-03-08 18:49:12 -0700322 // Pick up a tote from the ground and put it in the bottom of the bot.
323 if (data.PosEdge(kPickup)) {
324 actors::PickupParams params;
325 // Lift to here initially.
326 params.pickup_angle = 0.9;
327 // Start sucking here
328 params.suck_angle = 0.8;
329 // Go back down to here to finish sucking.
330 params.suck_angle_finish = 0.4;
331 // Pack the box back in here.
332 params.pickup_finish_angle = kClawTotePackAngle;
333 params.intake_time = 0.8;
334 params.intake_voltage = 7.0;
335 action_queue_.EnqueueAction(actors::MakePickupAction(params));
336 }
337
338 // Place stack on a tote in the tray, and grab it.
339 if (data.PosEdge(kStack)) {
340 actors::StackParams params;
341 params.claw_out_angle = 0.6;
342 params.bottom = 0.020;
Brian Silverman10043572015-03-21 23:43:50 -0700343 params.only_place = false;
344 params.arm_clearance = kArmRaiseLowerClearance;
Austin Schuhf14727e2015-03-08 18:49:12 -0700345 params.over_box_before_place_height = 0.39;
346 action_queue_.EnqueueAction(actors::MakeStackAction(params));
347 claw_rollers_closed_ = true;
Brian Silverman10043572015-03-21 23:43:50 -0700348 fridge_closed_ = true;
Austin Schuhf14727e2015-03-08 18:49:12 -0700349 }
350
Brian Silverman10043572015-03-21 23:43:50 -0700351 if (data.PosEdge(kScore)) {
Brian Silverman913eafa2015-03-19 23:42:16 -0700352 action_queue_.EnqueueAction(
Brian Silvermanb9811eb2015-03-20 16:54:41 -0700353 actors::MakeScoreAction(MakeScoreParams()));
Brian Silverman913eafa2015-03-19 23:42:16 -0700354 fridge_closed_ = false;
Brian Silverman10043572015-03-21 23:43:50 -0700355 }
Austin Schuhf14727e2015-03-08 18:49:12 -0700356
Brian Silverman913eafa2015-03-19 23:42:16 -0700357 if (data.PosEdge(kCoopTop)) {
358 action_queue_.EnqueueAction(
359 actors::MakeScoreAction(MakeCoopTopParams(false)));
360 }
361 if (data.PosEdge(kCoopTopRetract)) {
362 action_queue_.EnqueueAction(
363 actors::MakeScoreAction(MakeCoopTopParams(true)));
364 fridge_closed_ = false;
365 }
366
367 if (data.PosEdge(kCoopBottom)) {
368 action_queue_.EnqueueAction(
369 actors::MakeScoreAction(MakeCoopBottomParams(false)));
370 }
371 if (data.PosEdge(kCoopBottomRetract)) {
372 action_queue_.EnqueueAction(
373 actors::MakeScoreAction(MakeCoopBottomParams(true)));
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800374 fridge_closed_ = false;
375 }
376
Brian Silverman10043572015-03-21 23:43:50 -0700377 if (data.PosEdge(kFridgeToggle)) {
378 fridge_closed_ = !fridge_closed_;
379 }
380
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800381 if (data.PosEdge(ControlBit::kEnabled)) {
382 // If we got enabled, wait for everything to zero.
383 LOG(INFO, "Waiting for zero.\n");
384 waiting_for_zero_ = true;
385 }
386
Austin Schuh700b9222015-03-01 03:03:15 -0800387 claw_queue.status.FetchLatest();
388 fridge_queue.status.FetchLatest();
389 if (!claw_queue.status.get()) {
390 LOG(ERROR, "Got no claw status packet.\n");
391 // Not safe to continue.
392 return;
393 }
394 if (!fridge_queue.status.get()) {
395 LOG(ERROR, "Got no fridge status packet.\n");
396 return;
397 }
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800398
Austin Schuh700b9222015-03-01 03:03:15 -0800399 if (claw_queue.status->zeroed && fridge_queue.status->zeroed) {
400 if (waiting_for_zero_) {
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800401 LOG(INFO, "Zeroed! Starting teleop mode.\n");
402 waiting_for_zero_ = false;
403
404 // Set the initial goals to where we are now.
405 elevator_goal_ = fridge_queue.status->goal_height;
406 arm_goal_ = fridge_queue.status->goal_angle;
407 claw_goal_ = claw_queue.status->angle;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800408 }
409 } else {
Austin Schuh700b9222015-03-01 03:03:15 -0800410 waiting_for_zero_ = true;
411 return;
412 }
413
414 if (!waiting_for_zero_) {
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800415 if (!action_queue_.Running()) {
416 auto new_fridge_goal = fridge_queue.goal.MakeMessage();
Austin Schuh6e242ac2015-03-07 17:08:21 -0800417 new_fridge_goal->max_velocity = elevator_params_.velocity;
418 new_fridge_goal->max_acceleration = elevator_params_.acceleration;
Austin Schuh1d44bd42015-03-15 16:40:45 -0700419 new_fridge_goal->profiling_type = 0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800420 new_fridge_goal->height = elevator_goal_;
Austin Schuh6e242ac2015-03-07 17:08:21 -0800421 new_fridge_goal->velocity = 0.0;
422 new_fridge_goal->max_angular_velocity = arm_params_.velocity;
423 new_fridge_goal->max_angular_acceleration = arm_params_.acceleration;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800424 new_fridge_goal->angle = arm_goal_;
425 new_fridge_goal->angular_velocity = 0.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800426 new_fridge_goal->grabbers.top_front = fridge_closed_;
427 new_fridge_goal->grabbers.top_back = fridge_closed_;
428 new_fridge_goal->grabbers.bottom_front = fridge_closed_;
429 new_fridge_goal->grabbers.bottom_back = fridge_closed_;
430
431 if (!new_fridge_goal.Send()) {
432 LOG(ERROR, "Sending fridge goal failed.\n");
433 } else {
434 LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_,
435 arm_goal_);
436 }
437 if (!claw_queue.goal.MakeWithBuilder()
438 .angle(claw_goal_)
439 .rollers_closed(claw_rollers_closed_)
Brian Silverman10043572015-03-21 23:43:50 -0700440 .max_velocity(4.0)
441 .max_acceleration(6.0)
Austin Schuhf14727e2015-03-08 18:49:12 -0700442 .intake(intake_power)
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800443 .Send()) {
444 LOG(ERROR, "Sending claw goal failed.\n");
445 }
446 }
447 }
448
Austin Schuhd8b2a242015-02-22 21:46:53 -0800449 if (action_queue_.Running()) {
450 // If we are running an action, update our goals to the current goals.
451 control_loops::fridge_queue.status.FetchLatest();
452 if (control_loops::fridge_queue.status.get()) {
453 arm_goal_ = control_loops::fridge_queue.status->goal_angle;
454 elevator_goal_ = control_loops::fridge_queue.status->goal_height;
455 } else {
456 LOG(ERROR, "No fridge status!\n");
457 }
458
459 // If we are running an action, update our goals to the current goals.
460 control_loops::claw_queue.status.FetchLatest();
461 if (control_loops::claw_queue.status.get()) {
462 claw_goal_ = control_loops::claw_queue.status->goal_angle;
463 } else {
464 LOG(ERROR, "No fridge status!\n");
465 }
466 }
Brian Silverman20141f92015-01-05 17:39:01 -0800467 action_queue_.Tick();
468 was_running_ = action_queue_.Running();
469 }
470
471 private:
Austin Schuh6182f8d2015-02-14 22:15:04 -0800472 void StartAuto() {
473 LOG(INFO, "Starting auto mode\n");
474 ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(true).Send();
475 }
476
477 void StopAuto() {
478 LOG(INFO, "Stopping auto mode\n");
479 ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(false).Send();
480 }
481
Brian Silverman20141f92015-01-05 17:39:01 -0800482 bool was_running_;
Daniel Petti61896522015-02-15 18:01:43 -0800483
484 // Previous goals for systems.
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800485 double elevator_goal_ = 0.2;
Daniel Petti61896522015-02-15 18:01:43 -0800486 double arm_goal_ = 0.0;
487 double claw_goal_ = 0.0;
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800488 bool claw_rollers_closed_ = false;
489 bool fridge_closed_ = false;
Austin Schuh6e242ac2015-03-07 17:08:21 -0800490 actors::ProfileParams arm_params_ = kArmMove;
491 actors::ProfileParams elevator_params_ = kElevatorMove;
Daniel Petti61896522015-02-15 18:01:43 -0800492
493 // If we're waiting for the subsystems to zero.
Austin Schuhcde7ffe2015-02-20 22:10:41 -0800494 bool waiting_for_zero_ = true;
Daniel Petti61896522015-02-15 18:01:43 -0800495
Austin Schuh6182f8d2015-02-14 22:15:04 -0800496 bool auto_running_ = false;
497
Austin Schuh331e13d2015-02-15 00:16:51 -0800498 ::aos::common::actions::ActionQueue action_queue_;
Brian Silverman20141f92015-01-05 17:39:01 -0800499
500 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
501 ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING,
502 "no drivetrain status");
503};
504
505} // namespace joysticks
506} // namespace input
507} // namespace frc971
508
509int main() {
510 ::aos::Init();
511 ::frc971::input::joysticks::Reader reader;
512 reader.Run();
513 ::aos::Cleanup();
514}