blob: 6f350d307249178f4f6972579491c3bb70e90ea7 [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();
Daniel Pettidfc90ba2015-02-17 21:42:15 -080027
28 // Set the current stack down on top of the bottom box.
Austin Schuh813b9af2015-03-08 18:46:58 -070029 DoFridgeProfile(params.over_box_before_place_height, 0.0, kSlowArmMove,
30 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.
Austin Schuh813b9af2015-03-08 18:46:58 -070033 DoFridgeProfile(params.bottom + values.tote_height, 0.0, kSlowArmMove,
Austin Schuh6e242ac2015-03-07 17:08:21 -080034 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 {
Austin Schuh813b9af2015-03-08 18:46:58 -070038 bool send_goal = true;
39 control_loops::claw_queue.status.FetchLatest();
40 if (control_loops::claw_queue.status.get()) {
41 if (control_loops::claw_queue.status->goal_angle <
42 params.claw_out_angle) {
43 send_goal = false;
44 }
45 }
46 if (send_goal) {
47 auto message = control_loops::claw_queue.goal.MakeMessage();
48 message->angle = params.claw_out_angle;
49 message->angular_velocity = 0.0;
50 message->intake = 0.0;
51 message->rollers_closed = true;
52 message->max_velocity = 6.0;
53 message->max_acceleration = 10.0;
Austin Schuhdc171012015-02-22 21:36:55 -080054
Austin Schuh813b9af2015-03-08 18:46:58 -070055 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
56 message.Send();
57 }
Austin Schuhdc171012015-02-22 21:36:55 -080058 }
Austin Schuh813b9af2015-03-08 18:46:58 -070059 DoFridgeProfile(params.bottom, -0.05, kFastArmMove, kFastElevatorMove, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080060 if (ShouldCancel()) return true;
Austin Schuh813b9af2015-03-08 18:46:58 -070061 DoFridgeProfile(params.bottom, 0.0, kFastArmMove, kFastElevatorMove, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080062 if (ShouldCancel()) return true;
Austin Schuhdc171012015-02-22 21:36:55 -080063 aos::time::SleepFor(aos::time::Time::InMS(100));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080064
65 return true;
66}
67
Austin Schuhdc171012015-02-22 21:36:55 -080068::std::unique_ptr<StackAction> MakeStackAction(const StackParams &params) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080069 return ::std::unique_ptr<StackAction>(
Austin Schuhdc171012015-02-22 21:36:55 -080070 new StackAction(&::frc971::actors::stack_action, params));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080071}
72
73} // namespace actors
74} // namespace frc971