blob: 60ef6318e05f8f7c2b772c47ae9db50572712e3d [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"
Austin Schuh69792662015-02-22 21:39:52 -08007
8namespace frc971 {
9namespace actors {
10namespace {
Austin Schuh95eb1622015-03-14 21:11:22 -070011constexpr ProfileParams kArmMove{0.6, 1.0};
Austin Schuh6e242ac2015-03-07 17:08:21 -080012constexpr ProfileParams kElevatorMove{0.9, 3.0};
Austin Schuh69792662015-02-22 21:39:52 -080013} // namespace
14
15LiftActor::LiftActor(LiftActionQueueGroup *queues)
Austin Schuh6e242ac2015-03-07 17:08:21 -080016 : FridgeActorBase<LiftActionQueueGroup>(queues) {}
Austin Schuh69792662015-02-22 21:39:52 -080017
18bool LiftActor::RunAction(const LiftParams &params) {
Austin Schuh813b9af2015-03-08 18:46:58 -070019 control_loops::fridge_queue.status.FetchLatest();
20 if (!control_loops::fridge_queue.status.get()) {
21 return false;
22 }
23
Austin Schuh95eb1622015-03-14 21:11:22 -070024 double goal_height = params.lift_height;
25 double goal_angle = 0.0;
Austin Schuh813b9af2015-03-08 18:46:58 -070026
Austin Schuh95eb1622015-03-14 21:11:22 -070027 if (!StartFridgeProfile(
28 params.lift_height, 0.0, kElevatorMove, kArmMove,
29 control_loops::fridge_queue.status->grabbers.top_front,
30 control_loops::fridge_queue.status->grabbers.bottom_front,
31 control_loops::fridge_queue.status->grabbers.bottom_back)) {
32 return true;
33 }
34
35 bool has_started_back = false;
36 while (true) {
37 if (control_loops::fridge_queue.status->goal_height > 0.1) {
38 if (!has_started_back) {
39 if (!StartFridgeProfile(
40 params.lift_height, params.lift_arm, kElevatorMove, kArmMove,
41 control_loops::fridge_queue.status->grabbers.top_front,
42 control_loops::fridge_queue.status->grabbers.bottom_front,
43 control_loops::fridge_queue.status->grabbers.bottom_back)) {
44 return true;
45 }
46 goal_angle = params.lift_arm;
47 has_started_back = true;
48 }
49 }
50
51 ProfileStatus status = IterateProfile(
52 goal_height, goal_angle, kElevatorMove, kArmMove,
53 control_loops::fridge_queue.status->grabbers.top_front,
54 control_loops::fridge_queue.status->grabbers.bottom_front,
55 control_loops::fridge_queue.status->grabbers.bottom_back);
56 if (status == DONE || status == CANCELED) {
57 return true;
58 }
59 }
Austin Schuh69792662015-02-22 21:39:52 -080060 return true;
61}
62
63::std::unique_ptr<LiftAction> MakeLiftAction(const LiftParams &params) {
64 return ::std::unique_ptr<LiftAction>(
65 new LiftAction(&::frc971::actors::lift_action, params));
66}
67
68} // namespace actors
69} // namespace frc971