blob: ac2d74482683fb119e9e11dc0d46bfc1f990863e [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"
Ben Fredrickson32e6c252015-02-21 23:53:38 -08004#include "aos/common/util/phased_loop.h"
5
Daniel Pettidfc90ba2015-02-17 21:42:15 -08006#include "frc971/actors/stack_actor.h"
7#include "frc971/actors/fridge_profile_actor.h"
8#include "frc971/constants.h"
Austin Schuhdc171012015-02-22 21:36:55 -08009#include "frc971/control_loops/claw/claw.q.h"
Daniel Pettidfc90ba2015-02-17 21:42:15 -080010
11namespace frc971 {
12namespace actors {
13namespace {
14
Austin Schuhdc171012015-02-22 21:36:55 -080015static constexpr double kArmVelocity = 0.40;
16static constexpr double kArmAcceleration = 1.0;
17static constexpr double kElevatorVelocity = 0.5;
18static constexpr double kElevatorAcceleration = 2.2;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080019
20} // namespace
21
Austin Schuhdc171012015-02-22 21:36:55 -080022StackActor::StackActor(StackActionQueueGroup *queues)
Daniel Pettidfc90ba2015-02-17 21:42:15 -080023 : aos::common::actions::ActorBase<StackActionQueueGroup>(queues) {}
24
Ben Fredrickson32e6c252015-02-21 23:53:38 -080025void StackActor::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();
Ben Fredrickson32e6c252015-02-21 23:53:38 -080043 while (!profile->CheckIteration()) {
44 // wait until next Xms tick
45 ::aos::time::PhasedLoopXMS(5, 2500);
46 if (ShouldCancel()) {
47 profile->Cancel();
48 return;
49 }
50 }
Daniel Pettidfc90ba2015-02-17 21:42:15 -080051}
52
Austin Schuhdc171012015-02-22 21:36:55 -080053bool StackActor::RunAction(const StackParams &params) {
54 const auto &values = constants::GetValues();
55 const double bottom = 0.020;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080056
57 // Set the current stack down on top of the bottom box.
Austin Schuhdc171012015-02-22 21:36:55 -080058 DoProfile(0.45, 0.0, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080059 if (ShouldCancel()) return true;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080060 // Move down to enclose bottom box.
Austin Schuhdc171012015-02-22 21:36:55 -080061 DoProfile(bottom + values.tote_height, 0.0, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080062 if (ShouldCancel()) return true;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080063 // Clamp.
Austin Schuhdc171012015-02-22 21:36:55 -080064 {
65 auto message = control_loops::claw_queue.goal.MakeMessage();
66 message->angle = params.claw_out_angle;
67 message->angular_velocity = 0.0;
68 message->intake = 0.0;
69 message->rollers_closed = true;
70
71 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
72 message.Send();
73 }
74 DoProfile(bottom, -0.05, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080075 if (ShouldCancel()) return true;
Austin Schuhdc171012015-02-22 21:36:55 -080076 DoProfile(bottom, 0.0, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080077 if (ShouldCancel()) return true;
Austin Schuhdc171012015-02-22 21:36:55 -080078 aos::time::SleepFor(aos::time::Time::InMS(100));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080079
80 return true;
81}
82
Austin Schuhdc171012015-02-22 21:36:55 -080083::std::unique_ptr<StackAction> MakeStackAction(const StackParams &params) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080084 return ::std::unique_ptr<StackAction>(
Austin Schuhdc171012015-02-22 21:36:55 -080085 new StackAction(&::frc971::actors::stack_action, params));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080086}
87
88} // namespace actors
89} // namespace frc971