blob: c057eef404a8ac062111a14c5f5e07e5128aa542 [file] [log] [blame]
Austin Schuh69792662015-02-22 21:39:52 -08001#include <math.h>
2
3#include "aos/common/time.h"
Brian Silvermanb691f5e2015-08-02 11:37:55 -07004#include "y2015/actors/lift_actor.h"
5#include "y2015/constants.h"
6#include "y2015/actors/fridge_profile_lib.h"
7#include "y2015/control_loops/claw/claw.q.h"
Austin Schuh69792662015-02-22 21:39:52 -08008
9namespace frc971 {
10namespace actors {
11namespace {
Austin Schuh95eb1622015-03-14 21:11:22 -070012constexpr ProfileParams kArmMove{0.6, 1.0};
Austin Schuh6e242ac2015-03-07 17:08:21 -080013constexpr ProfileParams kElevatorMove{0.9, 3.0};
Austin Schuh3cba3792015-04-19 20:01:22 -070014constexpr ProfileParams kElevatorFixMove{0.9, 2.0};
Austin Schuh69792662015-02-22 21:39:52 -080015} // namespace
16
17LiftActor::LiftActor(LiftActionQueueGroup *queues)
Austin Schuh6e242ac2015-03-07 17:08:21 -080018 : FridgeActorBase<LiftActionQueueGroup>(queues) {}
Austin Schuh69792662015-02-22 21:39:52 -080019
20bool LiftActor::RunAction(const LiftParams &params) {
Austin Schuh813b9af2015-03-08 18:46:58 -070021 control_loops::fridge_queue.status.FetchLatest();
22 if (!control_loops::fridge_queue.status.get()) {
23 return false;
24 }
25
Austin Schuh95eb1622015-03-14 21:11:22 -070026 double goal_height = params.lift_height;
27 double goal_angle = 0.0;
Austin Schuh813b9af2015-03-08 18:46:58 -070028
Austin Schuh3cba3792015-04-19 20:01:22 -070029 if (params.second_lift) {
30 DoFridgeProfile(params.intermediate_lift_height, 0.0, kElevatorFixMove,
31 kArmMove,
32 control_loops::fridge_queue.status->grabbers.top_front,
33 control_loops::fridge_queue.status->grabbers.bottom_front,
34 control_loops::fridge_queue.status->grabbers.bottom_back);
35 if (ShouldCancel()) return true;
36 }
37
Austin Schuh95eb1622015-03-14 21:11:22 -070038 if (!StartFridgeProfile(
39 params.lift_height, 0.0, kElevatorMove, kArmMove,
40 control_loops::fridge_queue.status->grabbers.top_front,
41 control_loops::fridge_queue.status->grabbers.bottom_front,
42 control_loops::fridge_queue.status->grabbers.bottom_back)) {
43 return true;
44 }
45
46 bool has_started_back = false;
47 while (true) {
48 if (control_loops::fridge_queue.status->goal_height > 0.1) {
49 if (!has_started_back) {
50 if (!StartFridgeProfile(
51 params.lift_height, params.lift_arm, kElevatorMove, kArmMove,
52 control_loops::fridge_queue.status->grabbers.top_front,
53 control_loops::fridge_queue.status->grabbers.bottom_front,
54 control_loops::fridge_queue.status->grabbers.bottom_back)) {
55 return true;
56 }
57 goal_angle = params.lift_arm;
58 has_started_back = true;
Brian Silverman697d07b2015-03-19 23:41:11 -070059 if (params.pack_claw) {
60 auto message = control_loops::claw_queue.goal.MakeMessage();
61 message->angle = params.pack_claw_angle;
62 message->angular_velocity = 0.0;
63 message->intake = 0.0;
64 message->rollers_closed = true;
65 message->max_velocity = 6.0;
66 message->max_acceleration = 10.0;
67
68 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
69 message.Send();
70 }
Austin Schuh95eb1622015-03-14 21:11:22 -070071 }
72 }
73
74 ProfileStatus status = IterateProfile(
75 goal_height, goal_angle, kElevatorMove, kArmMove,
76 control_loops::fridge_queue.status->grabbers.top_front,
77 control_loops::fridge_queue.status->grabbers.bottom_front,
78 control_loops::fridge_queue.status->grabbers.bottom_back);
79 if (status == DONE || status == CANCELED) {
80 return true;
81 }
82 }
Austin Schuh69792662015-02-22 21:39:52 -080083 return true;
84}
85
86::std::unique_ptr<LiftAction> MakeLiftAction(const LiftParams &params) {
87 return ::std::unique_ptr<LiftAction>(
88 new LiftAction(&::frc971::actors::lift_action, params));
89}
90
91} // namespace actors
92} // namespace frc971