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 | 67efa4c | 2015-03-29 13:43:32 -0700 | [diff] [blame^] | 14 | constexpr ProfileParams kArmWithStackMove{1.75, 4.20}; |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame] | 15 | constexpr ProfileParams kSlowArmMove{1.3, 1.4}; |
Austin Schuh | 67efa4c | 2015-03-29 13:43:32 -0700 | [diff] [blame^] | 16 | constexpr ProfileParams kSlowElevatorMove{1.0, 3.0}; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 17 | |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 18 | constexpr ProfileParams kFastArmMove{0.8, 4.0}; |
| 19 | constexpr ProfileParams kFastElevatorMove{1.2, 5.0}; |
Austin Schuh | 67efa4c | 2015-03-29 13:43:32 -0700 | [diff] [blame^] | 20 | constexpr ProfileParams kReallyFastElevatorMove{1.2, 6.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 | |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 29 | 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 Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 44 | // Set the current stack down on top of the bottom box. |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame] | 45 | DoFridgeProfile(params.bottom + values.tote_height, 0.0, kSlowElevatorMove, |
| 46 | kSlowArmMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 47 | if (ShouldCancel()) return true; |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 48 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 49 | // Clamp. |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 50 | if (!params.only_place) { |
| 51 | // Move the claw out of the way only if we are supposed to pick up. |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 52 | 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 Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 68 | |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 69 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 70 | message.Send(); |
| 71 | } |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 72 | } |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 73 | |
| 74 | if (params.only_place) { |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame] | 75 | // open grabber for place only |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 76 | 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 Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 82 | if (ShouldCancel()) return true; |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame] | 83 | // grab can (if in fang mode the grabber stays closed) |
Austin Schuh | 67efa4c | 2015-03-29 13:43:32 -0700 | [diff] [blame^] | 84 | DoFridgeProfile(params.bottom, 0.0, kReallyFastElevatorMove, kFastArmMove, true, |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame] | 85 | true, true); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 86 | |
| 87 | return true; |
| 88 | } |
| 89 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 90 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 91 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 92 | new StackAction(&::frc971::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | } // namespace actors |
| 96 | } // namespace frc971 |