blob: c9622c2f4b7b70794b9d2fe758b5088ff8abdca1 [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 Schuh67efa4c2015-03-29 13:43:32 -070014constexpr ProfileParams kArmWithStackMove{1.75, 4.20};
Austin Schuhb53df1a2015-03-15 00:57:08 -070015constexpr ProfileParams kSlowArmMove{1.3, 1.4};
Austin Schuh67efa4c2015-03-29 13:43:32 -070016constexpr ProfileParams kSlowElevatorMove{1.0, 3.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};
Austin Schuh67efa4c2015-03-29 13:43:32 -070020constexpr ProfileParams kReallyFastElevatorMove{1.2, 6.0};
Daniel Pettidfc90ba2015-02-17 21:42:15 -080021} // namespace
22
Austin Schuhdc171012015-02-22 21:36:55 -080023StackActor::StackActor(StackActionQueueGroup *queues)
Austin Schuh6e242ac2015-03-07 17:08:21 -080024 : FridgeActorBase<StackActionQueueGroup>(queues) {}
Daniel Pettidfc90ba2015-02-17 21:42:15 -080025
Austin Schuhdc171012015-02-22 21:36:55 -080026bool StackActor::RunAction(const StackParams &params) {
27 const auto &values = constants::GetValues();
Daniel Pettidfc90ba2015-02-17 21:42:15 -080028
Austin Schuh85bda502015-03-15 19:57:27 -070029 control_loops::fridge_queue.status.FetchLatest();
30 if (!control_loops::fridge_queue.status.get()) {
31 LOG(ERROR, "Got no fridge status packet.\n");
32 return false;
33 }
34
35 // If we are really high, probably have a can. Move over before down.
36 if (control_loops::fridge_queue.status->goal_height >
37 params.over_box_before_place_height + 0.1) {
38 // Set the current stack down on top of the bottom box.
39 DoFridgeProfile(control_loops::fridge_queue.status->goal_height, 0.0,
40 kSlowElevatorMove, kArmWithStackMove, true);
41 if (ShouldCancel()) return true;
42 }
43
Daniel Pettidfc90ba2015-02-17 21:42:15 -080044 // Set the current stack down on top of the bottom box.
Austin Schuhb53df1a2015-03-15 00:57:08 -070045 DoFridgeProfile(params.bottom + values.tote_height, 0.0, kSlowElevatorMove,
46 kSlowArmMove, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080047 if (ShouldCancel()) return true;
Austin Schuh85bda502015-03-15 19:57:27 -070048
Daniel Pettidfc90ba2015-02-17 21:42:15 -080049 // Clamp.
Austin Schuh85bda502015-03-15 19:57:27 -070050 if (!params.only_place) {
51 // Move the claw out of the way only if we are supposed to pick up.
Austin Schuh813b9af2015-03-08 18:46:58 -070052 bool send_goal = true;
53 control_loops::claw_queue.status.FetchLatest();
54 if (control_loops::claw_queue.status.get()) {
55 if (control_loops::claw_queue.status->goal_angle <
56 params.claw_out_angle) {
57 send_goal = false;
58 }
59 }
60 if (send_goal) {
61 auto message = control_loops::claw_queue.goal.MakeMessage();
62 message->angle = params.claw_out_angle;
63 message->angular_velocity = 0.0;
64 message->intake = 0.0;
65 message->rollers_closed = true;
66 message->max_velocity = 6.0;
67 message->max_acceleration = 10.0;
Austin Schuhdc171012015-02-22 21:36:55 -080068
Austin Schuh813b9af2015-03-08 18:46:58 -070069 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
70 message.Send();
71 }
Austin Schuhdc171012015-02-22 21:36:55 -080072 }
Austin Schuh85bda502015-03-15 19:57:27 -070073
74 if (params.only_place) {
Ben Fredricksone2b1dd12015-03-27 21:18:08 -070075 // open grabber for place only
Austin Schuh85bda502015-03-15 19:57:27 -070076 DoFridgeProfile(params.bottom + values.tote_height, 0.0, kFastElevatorMove,
77 kFastArmMove, false);
78 // Finish early if we aren't supposed to grab.
79 return true;
80 }
81
Austin Schuhd2f47fc2015-03-01 00:06:27 -080082 if (ShouldCancel()) return true;
Ben Fredricksone2b1dd12015-03-27 21:18:08 -070083 // grab can (if in fang mode the grabber stays closed)
Austin Schuh67efa4c2015-03-29 13:43:32 -070084 DoFridgeProfile(params.bottom, 0.0, kReallyFastElevatorMove, kFastArmMove, true,
Ben Fredricksone2b1dd12015-03-27 21:18:08 -070085 true, true);
Daniel Pettidfc90ba2015-02-17 21:42:15 -080086
87 return true;
88}
89
Austin Schuhdc171012015-02-22 21:36:55 -080090::std::unique_ptr<StackAction> MakeStackAction(const StackParams &params) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080091 return ::std::unique_ptr<StackAction>(
Austin Schuhdc171012015-02-22 21:36:55 -080092 new StackAction(&::frc971::actors::stack_action, params));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080093}
94
95} // namespace actors
96} // namespace frc971