blob: a820f77797f282a4be853d0670b89ea774a7e960 [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 Schuhb53df1a2015-03-15 00:57:08 -070014constexpr ProfileParams kReallySlowArmMove{0.75, 0.75};
15constexpr ProfileParams kSlowArmMove{1.3, 1.4};
Austin Schuh6e242ac2015-03-07 17:08:21 -080016constexpr ProfileParams kSlowElevatorMove{0.5, 3.0};
17constexpr ProfileParams kReallySlowElevatorMove{0.10, 1.0};
Daniel Pettidfc90ba2015-02-17 21:42:15 -080018
Austin Schuh6e242ac2015-03-07 17:08:21 -080019constexpr ProfileParams kFastArmMove{0.8, 4.0};
20constexpr ProfileParams kFastElevatorMove{1.2, 5.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
29 // Set the current stack down on top of the bottom box.
Austin Schuhb53df1a2015-03-15 00:57:08 -070030 DoFridgeProfile(params.over_box_before_place_height, 0.0, kSlowElevatorMove,
31 kReallySlowArmMove, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080032 if (ShouldCancel()) return true;
Austin Schuh6e242ac2015-03-07 17:08:21 -080033 // Set down on the box.
Austin Schuhb53df1a2015-03-15 00:57:08 -070034 DoFridgeProfile(params.bottom + values.tote_height, 0.0, kSlowElevatorMove,
35 kSlowArmMove, true);
Ben Fredrickson32e6c252015-02-21 23:53:38 -080036 if (ShouldCancel()) return true;
Daniel Pettidfc90ba2015-02-17 21:42:15 -080037 // Clamp.
Austin Schuhdc171012015-02-22 21:36:55 -080038 {
Austin Schuh813b9af2015-03-08 18:46:58 -070039 bool send_goal = true;
40 control_loops::claw_queue.status.FetchLatest();
41 if (control_loops::claw_queue.status.get()) {
42 if (control_loops::claw_queue.status->goal_angle <
43 params.claw_out_angle) {
44 send_goal = false;
45 }
46 }
47 if (send_goal) {
48 auto message = control_loops::claw_queue.goal.MakeMessage();
49 message->angle = params.claw_out_angle;
50 message->angular_velocity = 0.0;
51 message->intake = 0.0;
52 message->rollers_closed = true;
53 message->max_velocity = 6.0;
54 message->max_acceleration = 10.0;
Austin Schuhdc171012015-02-22 21:36:55 -080055
Austin Schuh813b9af2015-03-08 18:46:58 -070056 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
57 message.Send();
58 }
Austin Schuhdc171012015-02-22 21:36:55 -080059 }
Austin Schuhb53df1a2015-03-15 00:57:08 -070060 DoFridgeProfile(params.bottom, -0.05, kFastElevatorMove, kFastArmMove, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080061 if (ShouldCancel()) return true;
Austin Schuhb53df1a2015-03-15 00:57:08 -070062 DoFridgeProfile(params.bottom, 0.0, kFastElevatorMove, kFastArmMove, false);
Austin Schuhd2f47fc2015-03-01 00:06:27 -080063 if (ShouldCancel()) return true;
Austin Schuhb53df1a2015-03-15 00:57:08 -070064 aos::time::SleepFor(aos::time::Time::InMS(200));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080065
66 return true;
67}
68
Austin Schuhdc171012015-02-22 21:36:55 -080069::std::unique_ptr<StackAction> MakeStackAction(const StackParams &params) {
Daniel Pettidfc90ba2015-02-17 21:42:15 -080070 return ::std::unique_ptr<StackAction>(
Austin Schuhdc171012015-02-22 21:36:55 -080071 new StackAction(&::frc971::actors::stack_action, params));
Daniel Pettidfc90ba2015-02-17 21:42:15 -080072}
73
74} // namespace actors
75} // namespace frc971