blob: ff9c73946ae73e633f742cde2fe8abaa5bdc47e6 [file] [log] [blame]
Daniel Pettidfc90ba2015-02-17 21:42:15 -08001#include <math.h>
2
3#include "frc971/actors/stack_actor.h"
4#include "frc971/actors/fridge_profile_actor.h"
5#include "frc971/constants.h"
6
7namespace frc971 {
8namespace actors {
9namespace {
10
11// TODO(danielp): Real numbers!
12constexpr double kElevatorMaxVelocity = 0.5;
13constexpr double kArmMaxVelocity = 0.5;
14constexpr double kElevatorMaxAccel = 0.25;
15constexpr double kArmMaxAccel = 0.25;
16
17} // namespace
18
19StackActor::StackActor(StackActionQueueGroup* queues)
20 : aos::common::actions::ActorBase<StackActionQueueGroup>(queues) {}
21
22namespace {
23
24void DoProfile(double height, bool grabbers) {
25 FridgeProfileParams params;
26
27 params.elevator_height = height;
28 params.elevator_max_velocity = kElevatorMaxVelocity;
29 params.elevator_max_acceleration = kElevatorMaxAccel;
30
31 params.arm_angle = M_PI / 2.0;
32 params.arm_max_velocity = kArmMaxVelocity;
33 params.arm_max_acceleration = kArmMaxAccel;
34
35 params.top_front_grabber = grabbers;
36 params.top_back_grabber = grabbers;
37 params.bottom_front_grabber = grabbers;
38 params.bottom_back_grabber = grabbers;
39
40 ::std::unique_ptr<FridgeAction> profile = MakeFridgeProfileAction(params);
41 profile->Start();
42 profile->WaitUntilDone();
43}
44
45} // namespace
46
47bool StackActor::RunAction(const uint32_t&) {
48 const auto& values = constants::GetValues();
49 const double bottom = values.fridge.elevator.lower_limit;
50
51 // Set the current stack down on top of the bottom box.
52 DoProfile(bottom + values.tote_height, true);
53 // Move down to enclose bottom box.
54 DoProfile(bottom, false);
55 // Clamp.
56 DoProfile(bottom, true);
57
58 return true;
59}
60
61::std::unique_ptr<StackAction> MakeStackAction() {
62 return ::std::unique_ptr<StackAction>(
63 new StackAction(&::frc971::actors::stack_action, 0));
64}
65
66} // namespace actors
67} // namespace frc971