Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 1 | #include "frc971/actors/stack_actor.h" |
| 2 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 3 | #include <math.h> |
| 4 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 5 | #include "aos/common/time.h" |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 6 | #include "aos/common/util/phased_loop.h" |
| 7 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 8 | #include "frc971/constants.h" |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/claw/claw.q.h" |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 10 | |
| 11 | namespace frc971 { |
| 12 | namespace actors { |
| 13 | namespace { |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame^] | 14 | constexpr ProfileParams kReallySlowArmMove{0.75, 0.75}; |
| 15 | constexpr ProfileParams kSlowArmMove{1.3, 1.4}; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 16 | constexpr ProfileParams kSlowElevatorMove{0.5, 3.0}; |
| 17 | constexpr ProfileParams kReallySlowElevatorMove{0.10, 1.0}; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 18 | |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 19 | constexpr ProfileParams kFastArmMove{0.8, 4.0}; |
| 20 | constexpr ProfileParams kFastElevatorMove{1.2, 5.0}; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 21 | } // namespace |
| 22 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 23 | StackActor::StackActor(StackActionQueueGroup *queues) |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 24 | : FridgeActorBase<StackActionQueueGroup>(queues) {} |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 25 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 26 | bool StackActor::RunAction(const StackParams ¶ms) { |
| 27 | const auto &values = constants::GetValues(); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 28 | |
| 29 | // Set the current stack down on top of the bottom box. |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame^] | 30 | DoFridgeProfile(params.over_box_before_place_height, 0.0, kSlowElevatorMove, |
| 31 | kReallySlowArmMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 32 | if (ShouldCancel()) return true; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 33 | // Set down on the box. |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame^] | 34 | DoFridgeProfile(params.bottom + values.tote_height, 0.0, kSlowElevatorMove, |
| 35 | kSlowArmMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 36 | if (ShouldCancel()) return true; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 37 | // Clamp. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 38 | { |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 39 | 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 Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 55 | |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 56 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 57 | message.Send(); |
| 58 | } |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 59 | } |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame^] | 60 | DoFridgeProfile(params.bottom, -0.05, kFastElevatorMove, kFastArmMove, false); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 61 | if (ShouldCancel()) return true; |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame^] | 62 | DoFridgeProfile(params.bottom, 0.0, kFastElevatorMove, kFastArmMove, false); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 63 | if (ShouldCancel()) return true; |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame^] | 64 | aos::time::SleepFor(aos::time::Time::InMS(200)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 69 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 70 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 71 | new StackAction(&::frc971::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } // namespace actors |
| 75 | } // namespace frc971 |