Austin Schuh | 6979266 | 2015-02-22 21:39:52 -0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | |
| 3 | #include "aos/common/time.h" |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame] | 4 | #include "y2015/actors/lift_actor.h" |
| 5 | #include "y2015/constants.h" |
| 6 | #include "y2015/actors/fridge_profile_lib.h" |
| 7 | #include "y2015/control_loops/claw/claw.q.h" |
Austin Schuh | 6979266 | 2015-02-22 21:39:52 -0800 | [diff] [blame] | 8 | |
| 9 | namespace frc971 { |
| 10 | namespace actors { |
| 11 | namespace { |
Austin Schuh | 95eb162 | 2015-03-14 21:11:22 -0700 | [diff] [blame] | 12 | constexpr ProfileParams kArmMove{0.6, 1.0}; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 13 | constexpr ProfileParams kElevatorMove{0.9, 3.0}; |
Austin Schuh | 3cba379 | 2015-04-19 20:01:22 -0700 | [diff] [blame] | 14 | constexpr ProfileParams kElevatorFixMove{0.9, 2.0}; |
Austin Schuh | 6979266 | 2015-02-22 21:39:52 -0800 | [diff] [blame] | 15 | } // namespace |
| 16 | |
| 17 | LiftActor::LiftActor(LiftActionQueueGroup *queues) |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 18 | : FridgeActorBase<LiftActionQueueGroup>(queues) {} |
Austin Schuh | 6979266 | 2015-02-22 21:39:52 -0800 | [diff] [blame] | 19 | |
| 20 | bool LiftActor::RunAction(const LiftParams ¶ms) { |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 21 | control_loops::fridge_queue.status.FetchLatest(); |
| 22 | if (!control_loops::fridge_queue.status.get()) { |
| 23 | return false; |
| 24 | } |
| 25 | |
Austin Schuh | 95eb162 | 2015-03-14 21:11:22 -0700 | [diff] [blame] | 26 | double goal_height = params.lift_height; |
| 27 | double goal_angle = 0.0; |
Austin Schuh | 813b9af | 2015-03-08 18:46:58 -0700 | [diff] [blame] | 28 | |
Austin Schuh | 3cba379 | 2015-04-19 20:01:22 -0700 | [diff] [blame] | 29 | if (params.second_lift) { |
| 30 | DoFridgeProfile(params.intermediate_lift_height, 0.0, kElevatorFixMove, |
| 31 | kArmMove, |
| 32 | control_loops::fridge_queue.status->grabbers.top_front, |
| 33 | control_loops::fridge_queue.status->grabbers.bottom_front, |
| 34 | control_loops::fridge_queue.status->grabbers.bottom_back); |
| 35 | if (ShouldCancel()) return true; |
| 36 | } |
| 37 | |
Austin Schuh | 95eb162 | 2015-03-14 21:11:22 -0700 | [diff] [blame] | 38 | if (!StartFridgeProfile( |
| 39 | params.lift_height, 0.0, kElevatorMove, kArmMove, |
| 40 | control_loops::fridge_queue.status->grabbers.top_front, |
| 41 | control_loops::fridge_queue.status->grabbers.bottom_front, |
| 42 | control_loops::fridge_queue.status->grabbers.bottom_back)) { |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | bool has_started_back = false; |
| 47 | while (true) { |
| 48 | if (control_loops::fridge_queue.status->goal_height > 0.1) { |
| 49 | if (!has_started_back) { |
| 50 | if (!StartFridgeProfile( |
| 51 | params.lift_height, params.lift_arm, kElevatorMove, kArmMove, |
| 52 | control_loops::fridge_queue.status->grabbers.top_front, |
| 53 | control_loops::fridge_queue.status->grabbers.bottom_front, |
| 54 | control_loops::fridge_queue.status->grabbers.bottom_back)) { |
| 55 | return true; |
| 56 | } |
| 57 | goal_angle = params.lift_arm; |
| 58 | has_started_back = true; |
Brian Silverman | 697d07b | 2015-03-19 23:41:11 -0700 | [diff] [blame] | 59 | if (params.pack_claw) { |
| 60 | auto message = control_loops::claw_queue.goal.MakeMessage(); |
| 61 | message->angle = params.pack_claw_angle; |
| 62 | message->angular_velocity = 0.0; |
| 63 | message->intake = 0.0; |
| 64 | message->rollers_closed = true; |
| 65 | message->max_velocity = 6.0; |
| 66 | message->max_acceleration = 10.0; |
| 67 | |
| 68 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 69 | message.Send(); |
| 70 | } |
Austin Schuh | 95eb162 | 2015-03-14 21:11:22 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | ProfileStatus status = IterateProfile( |
| 75 | goal_height, goal_angle, kElevatorMove, kArmMove, |
| 76 | control_loops::fridge_queue.status->grabbers.top_front, |
| 77 | control_loops::fridge_queue.status->grabbers.bottom_front, |
| 78 | control_loops::fridge_queue.status->grabbers.bottom_back); |
| 79 | if (status == DONE || status == CANCELED) { |
| 80 | return true; |
| 81 | } |
| 82 | } |
Austin Schuh | 6979266 | 2015-02-22 21:39:52 -0800 | [diff] [blame] | 83 | return true; |
| 84 | } |
| 85 | |
| 86 | ::std::unique_ptr<LiftAction> MakeLiftAction(const LiftParams ¶ms) { |
| 87 | return ::std::unique_ptr<LiftAction>( |
| 88 | new LiftAction(&::frc971::actors::lift_action, params)); |
| 89 | } |
| 90 | |
| 91 | } // namespace actors |
| 92 | } // namespace frc971 |