blob: 44222fd2e64ce6acaf45a7399d51939561c30459 [file] [log] [blame]
Austin Schuh69792662015-02-22 21:39:52 -08001#include <math.h>
2
3#include "aos/common/time.h"
4#include "frc971/actors/lift_actor.h"
Austin Schuh69792662015-02-22 21:39:52 -08005#include "frc971/constants.h"
Austin Schuh6e242ac2015-03-07 17:08:21 -08006#include "frc971/actors/fridge_profile_lib.h"
Brian Silverman697d07b2015-03-19 23:41:11 -07007#include "frc971/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 Schuh69792662015-02-22 21:39:52 -080014} // namespace
15
16LiftActor::LiftActor(LiftActionQueueGroup *queues)
Austin Schuh6e242ac2015-03-07 17:08:21 -080017 : FridgeActorBase<LiftActionQueueGroup>(queues) {}
Austin Schuh69792662015-02-22 21:39:52 -080018
19bool LiftActor::RunAction(const LiftParams &params) {
Austin Schuh813b9af2015-03-08 18:46:58 -070020 control_loops::fridge_queue.status.FetchLatest();
21 if (!control_loops::fridge_queue.status.get()) {
22 return false;
23 }
24
Austin Schuh95eb1622015-03-14 21:11:22 -070025 double goal_height = params.lift_height;
26 double goal_angle = 0.0;
Austin Schuh813b9af2015-03-08 18:46:58 -070027
Austin Schuh95eb1622015-03-14 21:11:22 -070028 if (!StartFridgeProfile(
29 params.lift_height, 0.0, kElevatorMove, kArmMove,
30 control_loops::fridge_queue.status->grabbers.top_front,
31 control_loops::fridge_queue.status->grabbers.bottom_front,
32 control_loops::fridge_queue.status->grabbers.bottom_back)) {
33 return true;
34 }
35
36 bool has_started_back = false;
37 while (true) {
38 if (control_loops::fridge_queue.status->goal_height > 0.1) {
39 if (!has_started_back) {
40 if (!StartFridgeProfile(
41 params.lift_height, params.lift_arm, kElevatorMove, kArmMove,
42 control_loops::fridge_queue.status->grabbers.top_front,
43 control_loops::fridge_queue.status->grabbers.bottom_front,
44 control_loops::fridge_queue.status->grabbers.bottom_back)) {
45 return true;
46 }
47 goal_angle = params.lift_arm;
48 has_started_back = true;
Brian Silverman697d07b2015-03-19 23:41:11 -070049 if (params.pack_claw) {
50 auto message = control_loops::claw_queue.goal.MakeMessage();
51 message->angle = params.pack_claw_angle;
52 message->angular_velocity = 0.0;
53 message->intake = 0.0;
54 message->rollers_closed = true;
55 message->max_velocity = 6.0;
56 message->max_acceleration = 10.0;
57
58 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
59 message.Send();
60 }
Austin Schuh95eb1622015-03-14 21:11:22 -070061 }
62 }
63
64 ProfileStatus status = IterateProfile(
65 goal_height, goal_angle, kElevatorMove, kArmMove,
66 control_loops::fridge_queue.status->grabbers.top_front,
67 control_loops::fridge_queue.status->grabbers.bottom_front,
68 control_loops::fridge_queue.status->grabbers.bottom_back);
69 if (status == DONE || status == CANCELED) {
70 return true;
71 }
72 }
Austin Schuh69792662015-02-22 21:39:52 -080073 return true;
74}
75
76::std::unique_ptr<LiftAction> MakeLiftAction(const LiftParams &params) {
77 return ::std::unique_ptr<LiftAction>(
78 new LiftAction(&::frc971::actors::lift_action, params));
79}
80
81} // namespace actors
82} // namespace frc971