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