blob: 7267a4bf6400496c83760dbb2686efadcaf15d9c [file] [log] [blame]
Austin Schuh6e242ac2015-03-07 17:08:21 -08001#include "frc971/actors/stack_actor.h"
2
Daniel Pettidfc90ba2015-02-17 21:42:15 -08003#include <math.h>
4
Austin Schuhdc171012015-02-22 21:36:55 -08005#include "aos/common/time.h"
Ben Fredrickson32e6c252015-02-21 23:53:38 -08006#include "aos/common/util/phased_loop.h"
7
Daniel Pettidfc90ba2015-02-17 21:42:15 -08008#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 {
Austin Schuh6e242ac2015-03-07 17:08:21 -080014constexpr ProfileParams kSlowArmMove{0.8, 1.4};
15constexpr ProfileParams kSlowElevatorMove{0.5, 3.0};
16constexpr ProfileParams kReallySlowElevatorMove{0.10, 1.0};
Daniel Pettidfc90ba2015-02-17 21:42:15 -080017
Austin Schuh6e242ac2015-03-07 17:08:21 -080018constexpr ProfileParams kFastArmMove{0.8, 4.0};
19constexpr ProfileParams kFastElevatorMove{1.2, 5.0};
Daniel Pettidfc90ba2015-02-17 21:42:15 -080020} // namespace
21
Austin Schuhdc171012015-02-22 21:36:55 -080022StackActor::StackActor(StackActionQueueGroup *queues)
Austin Schuh6e242ac2015-03-07 17:08:21 -080023 : FridgeActorBase<StackActionQueueGroup>(queues) {}
Daniel Pettidfc90ba2015-02-17 21:42:15 -080024
Austin Schuhdc171012015-02-22 21:36:55 -080025bool StackActor::RunAction(const StackParams &params) {
26 const auto &values = constants::GetValues();
27 const double bottom = 0.020;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080028
29 // Set the current stack down on top of the bottom box.
Austin Schuh6e242ac2015-03-07 17:08:21 -080030 DoFridgeProfile(0.39, 0.0, kSlowArmMove, kReallySlowElevatorMove, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080031 if (ShouldCancel()) return true;
Austin Schuh6e242ac2015-03-07 17:08:21 -080032 // Set down on the box.
33 DoFridgeProfile(bottom + values.tote_height, 0.0, kSlowArmMove,
34 kSlowElevatorMove, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080035 if (ShouldCancel()) return true;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080036 // Clamp.
Austin Schuhdc171012015-02-22 21:36:55 -080037 {
38 auto message = control_loops::claw_queue.goal.MakeMessage();
39 message->angle = params.claw_out_angle;
40 message->angular_velocity = 0.0;
41 message->intake = 0.0;
42 message->rollers_closed = true;
43
44 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
45 message.Send();
46 }
Austin Schuh6e242ac2015-03-07 17:08:21 -080047 DoFridgeProfile(bottom, -0.05, kFastArmMove, kFastElevatorMove, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080048 if (ShouldCancel()) return true;
Austin Schuh6e242ac2015-03-07 17:08:21 -080049 DoFridgeProfile(bottom, 0.0, kFastArmMove, kFastElevatorMove, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080050 if (ShouldCancel()) return true;
Austin Schuhdc171012015-02-22 21:36:55 -080051 aos::time::SleepFor(aos::time::Time::InMS(100));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080052
53 return true;
54}
55
Austin Schuhdc171012015-02-22 21:36:55 -080056::std::unique_ptr<StackAction> MakeStackAction(const StackParams &params) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080057 return ::std::unique_ptr<StackAction>(
Austin Schuhdc171012015-02-22 21:36:55 -080058 new StackAction(&::frc971::actors::stack_action, params));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080059}
60
61} // namespace actors
62} // namespace frc971