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 | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 14 | constexpr ProfileParams kArmWithStackMove{1.75, 0.60}; |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame] | 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}; |
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}; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 20 | } // namespace |
| 21 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 22 | StackActor::StackActor(StackActionQueueGroup *queues) |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 23 | : FridgeActorBase<StackActionQueueGroup>(queues) {} |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 24 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 25 | bool StackActor::RunAction(const StackParams ¶ms) { |
| 26 | const auto &values = constants::GetValues(); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 27 | |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 28 | control_loops::fridge_queue.status.FetchLatest(); |
| 29 | if (!control_loops::fridge_queue.status.get()) { |
| 30 | LOG(ERROR, "Got no fridge status packet.\n"); |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | // If we are really high, probably have a can. Move over before down. |
| 35 | if (control_loops::fridge_queue.status->goal_height > |
| 36 | params.over_box_before_place_height + 0.1) { |
| 37 | // Set the current stack down on top of the bottom box. |
| 38 | DoFridgeProfile(control_loops::fridge_queue.status->goal_height, 0.0, |
| 39 | kSlowElevatorMove, kArmWithStackMove, true); |
| 40 | if (ShouldCancel()) return true; |
| 41 | } |
| 42 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 43 | // Set the current stack down on top of the bottom box. |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame] | 44 | DoFridgeProfile(params.over_box_before_place_height, 0.0, kSlowElevatorMove, |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 45 | kArmWithStackMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 46 | if (ShouldCancel()) return true; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 47 | // Set down on the box. |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame] | 48 | DoFridgeProfile(params.bottom + values.tote_height, 0.0, kSlowElevatorMove, |
| 49 | kSlowArmMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 50 | if (ShouldCancel()) return true; |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 51 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 52 | // Clamp. |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 53 | if (!params.only_place) { |
| 54 | // 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] | 55 | bool send_goal = true; |
| 56 | control_loops::claw_queue.status.FetchLatest(); |
| 57 | if (control_loops::claw_queue.status.get()) { |
| 58 | if (control_loops::claw_queue.status->goal_angle < |
| 59 | params.claw_out_angle) { |
| 60 | send_goal = false; |
| 61 | } |
| 62 | } |
| 63 | if (send_goal) { |
| 64 | auto message = control_loops::claw_queue.goal.MakeMessage(); |
| 65 | message->angle = params.claw_out_angle; |
| 66 | message->angular_velocity = 0.0; |
| 67 | message->intake = 0.0; |
| 68 | message->rollers_closed = true; |
| 69 | message->max_velocity = 6.0; |
| 70 | message->max_acceleration = 10.0; |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 71 | |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 72 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 73 | message.Send(); |
| 74 | } |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 75 | } |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 76 | |
| 77 | if (params.only_place) { |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame^] | 78 | // open grabber for place only |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 79 | DoFridgeProfile(params.bottom + values.tote_height, 0.0, kFastElevatorMove, |
| 80 | kFastArmMove, false); |
| 81 | // Finish early if we aren't supposed to grab. |
| 82 | return true; |
| 83 | } |
| 84 | |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame^] | 85 | // TODO(ben): I'm not sure why this liitle jog is here. we are removing it for |
| 86 | // the fangs, but I want to keep the code here so austin can explain. |
| 87 | /*DoFridgeProfile(params.bottom + values.tote_height, params.arm_clearance, |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 88 | kFastElevatorMove, kFastArmMove, false); |
| 89 | |
| 90 | if (ShouldCancel()) return true; |
| 91 | DoFridgeProfile(params.bottom, params.arm_clearance, kFastElevatorMove, |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame^] | 92 | kFastArmMove, false);*/ |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 93 | if (ShouldCancel()) return true; |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame^] | 94 | // grab can (if in fang mode the grabber stays closed) |
| 95 | DoFridgeProfile(params.bottom, 0.0, kFastElevatorMove, kFastArmMove, false, |
| 96 | true, true); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 97 | if (ShouldCancel()) return true; |
Austin Schuh | b53df1a | 2015-03-15 00:57:08 -0700 | [diff] [blame] | 98 | aos::time::SleepFor(aos::time::Time::InMS(200)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 99 | |
| 100 | return true; |
| 101 | } |
| 102 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 103 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 104 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 105 | new StackAction(&::frc971::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | } // namespace actors |
| 109 | } // namespace frc971 |