Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame] | 1 | #include "y2015/actors/stack_actor.h" |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 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 | |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame] | 8 | #include "y2015/constants.h" |
| 9 | #include "y2015/control_loops/claw/claw.q.h" |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 10 | |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 11 | namespace y2015 { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 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 | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 23 | using ::y2015::control_loops::claw_queue; |
| 24 | using ::y2015::control_loops::fridge::fridge_queue; |
| 25 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 26 | StackActor::StackActor(StackActionQueueGroup *queues) |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 27 | : FridgeActorBase<StackActionQueueGroup>(queues) {} |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 28 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 29 | bool StackActor::RunAction(const StackParams ¶ms) { |
| 30 | const auto &values = constants::GetValues(); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 31 | |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 32 | fridge_queue.status.FetchLatest(); |
| 33 | if (!fridge_queue.status.get()) { |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 34 | LOG(ERROR, "Got no fridge status packet.\n"); |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | // If we are really high, probably have a can. Move over before down. |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 39 | if (fridge_queue.status->goal_height > |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 40 | params.over_box_before_place_height + 0.1) { |
| 41 | // Set the current stack down on top of the bottom box. |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 42 | DoFridgeProfile(fridge_queue.status->goal_height, 0.0, |
Austin Schuh | 85bda50 | 2015-03-15 19:57:27 -0700 | [diff] [blame] | 43 | kSlowElevatorMove, kArmWithStackMove, true); |
| 44 | if (ShouldCancel()) return true; |
| 45 | } |
| 46 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 47 | // Set the current stack down on top of the bottom 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; |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 56 | claw_queue.status.FetchLatest(); |
| 57 | if (claw_queue.status.get()) { |
| 58 | if (claw_queue.status->goal_angle < |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 59 | params.claw_out_angle) { |
| 60 | send_goal = false; |
| 61 | } |
| 62 | } |
| 63 | if (send_goal) { |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 64 | auto message = claw_queue.goal.MakeMessage(); |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 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 | |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 85 | if (ShouldCancel()) return true; |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame] | 86 | // grab can (if in fang mode the grabber stays closed) |
Austin Schuh | 67efa4c | 2015-03-29 13:43:32 -0700 | [diff] [blame] | 87 | DoFridgeProfile(params.bottom, 0.0, kReallyFastElevatorMove, kFastArmMove, true, |
Ben Fredrickson | e2b1dd1 | 2015-03-27 21:18:08 -0700 | [diff] [blame] | 88 | true, true); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 89 | |
| 90 | return true; |
| 91 | } |
| 92 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 93 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 94 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 95 | new StackAction(&::y2015::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } // namespace actors |
Austin Schuh | 88af085 | 2016-12-04 20:31:32 -0800 | [diff] [blame] | 99 | } // namespace y2015 |