blob: bf5a3e3137bd98a6dff1821c01f05f641f900e36 [file] [log] [blame]
Daniel Pettidfc90ba2015-02-17 21:42:15 -08001#include <math.h>
2
Austin Schuhdc171012015-02-22 21:36:55 -08003#include "aos/common/time.h"
Daniel Pettidfc90ba2015-02-17 21:42:15 -08004#include "frc971/actors/stack_actor.h"
5#include "frc971/actors/fridge_profile_actor.h"
6#include "frc971/constants.h"
Austin Schuhdc171012015-02-22 21:36:55 -08007#include "frc971/control_loops/claw/claw.q.h"
Daniel Pettidfc90ba2015-02-17 21:42:15 -08008
9namespace frc971 {
10namespace actors {
11namespace {
12
Austin Schuhdc171012015-02-22 21:36:55 -080013static constexpr double kArmVelocity = 0.40;
14static constexpr double kArmAcceleration = 1.0;
15static constexpr double kElevatorVelocity = 0.5;
16static constexpr double kElevatorAcceleration = 2.2;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080017
18} // namespace
19
Austin Schuhdc171012015-02-22 21:36:55 -080020StackActor::StackActor(StackActionQueueGroup *queues)
Daniel Pettidfc90ba2015-02-17 21:42:15 -080021 : aos::common::actions::ActorBase<StackActionQueueGroup>(queues) {}
22
23namespace {
24
Austin Schuhdc171012015-02-22 21:36:55 -080025void DoProfile(double height, double angle, bool grabbers) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080026 FridgeProfileParams params;
27
28 params.elevator_height = height;
Austin Schuhdc171012015-02-22 21:36:55 -080029 params.elevator_max_velocity = kElevatorVelocity;
30 params.elevator_max_acceleration = kElevatorAcceleration;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080031
Austin Schuhdc171012015-02-22 21:36:55 -080032 params.arm_angle = angle;
33 params.arm_max_velocity = kArmVelocity;
34 params.arm_max_acceleration = kArmAcceleration;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080035
36 params.top_front_grabber = grabbers;
37 params.top_back_grabber = grabbers;
38 params.bottom_front_grabber = grabbers;
39 params.bottom_back_grabber = grabbers;
40
41 ::std::unique_ptr<FridgeAction> profile = MakeFridgeProfileAction(params);
42 profile->Start();
43 profile->WaitUntilDone();
44}
45
46} // namespace
47
Austin Schuhdc171012015-02-22 21:36:55 -080048bool StackActor::RunAction(const StackParams &params) {
49 const auto &values = constants::GetValues();
50 const double bottom = 0.020;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080051
52 // Set the current stack down on top of the bottom box.
Austin Schuhdc171012015-02-22 21:36:55 -080053 DoProfile(0.45, 0.0, true);
Daniel Pettidfc90ba2015-02-17 21:42:15 -080054 // Move down to enclose bottom box.
Austin Schuhdc171012015-02-22 21:36:55 -080055 DoProfile(bottom + values.tote_height, 0.0, true);
Daniel Pettidfc90ba2015-02-17 21:42:15 -080056 // Clamp.
Austin Schuhdc171012015-02-22 21:36:55 -080057 {
58 auto message = control_loops::claw_queue.goal.MakeMessage();
59 message->angle = params.claw_out_angle;
60 message->angular_velocity = 0.0;
61 message->intake = 0.0;
62 message->rollers_closed = true;
63
64 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
65 message.Send();
66 }
67 DoProfile(bottom, -0.05, false);
68 DoProfile(bottom, 0.0, false);
69 aos::time::SleepFor(aos::time::Time::InMS(100));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080070
71 return true;
72}
73
Austin Schuhdc171012015-02-22 21:36:55 -080074::std::unique_ptr<StackAction> MakeStackAction(const StackParams &params) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080075 return ::std::unique_ptr<StackAction>(
Austin Schuhdc171012015-02-22 21:36:55 -080076 new StackAction(&::frc971::actors::stack_action, params));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080077}
78
79} // namespace actors
80} // namespace frc971