Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 3 | #include "aos/common/time.h" |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 4 | #include "aos/common/util/phased_loop.h" |
| 5 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 6 | #include "frc971/actors/stack_actor.h" |
| 7 | #include "frc971/actors/fridge_profile_actor.h" |
| 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 { |
| 14 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 15 | static constexpr double kArmVelocity = 0.40; |
| 16 | static constexpr double kArmAcceleration = 1.0; |
| 17 | static constexpr double kElevatorVelocity = 0.5; |
| 18 | static constexpr double kElevatorAcceleration = 2.2; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 19 | |
| 20 | } // namespace |
| 21 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 22 | StackActor::StackActor(StackActionQueueGroup *queues) |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 23 | : aos::common::actions::ActorBase<StackActionQueueGroup>(queues) {} |
| 24 | |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 25 | void StackActor::DoProfile(double height, double angle, bool grabbers) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 26 | FridgeProfileParams params; |
| 27 | |
| 28 | params.elevator_height = height; |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 29 | params.elevator_max_velocity = kElevatorVelocity; |
| 30 | params.elevator_max_acceleration = kElevatorAcceleration; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 31 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 32 | params.arm_angle = angle; |
| 33 | params.arm_max_velocity = kArmVelocity; |
| 34 | params.arm_max_acceleration = kArmAcceleration; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 35 | |
| 36 | params.top_front_grabber = grabbers; |
| 37 | params.top_back_grabber = grabbers; |
| 38 | params.bottom_front_grabber = grabbers; |
| 39 | params.bottom_back_grabber = grabbers; |
| 40 | |
| 41 | ::std::unique_ptr<FridgeAction> profile = MakeFridgeProfileAction(params); |
| 42 | profile->Start(); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 43 | while (!profile->CheckIteration()) { |
| 44 | // wait until next Xms tick |
| 45 | ::aos::time::PhasedLoopXMS(5, 2500); |
| 46 | if (ShouldCancel()) { |
| 47 | profile->Cancel(); |
| 48 | return; |
| 49 | } |
| 50 | } |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 53 | bool StackActor::RunAction(const StackParams ¶ms) { |
| 54 | const auto &values = constants::GetValues(); |
| 55 | const double bottom = 0.020; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 56 | |
| 57 | // Set the current stack down on top of the bottom box. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 58 | DoProfile(0.45, 0.0, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 59 | if (ShouldCancel()) return true; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 60 | // Move down to enclose bottom box. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 61 | DoProfile(bottom + values.tote_height, 0.0, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 62 | if (ShouldCancel()) return true; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 63 | // Clamp. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 64 | { |
| 65 | auto message = control_loops::claw_queue.goal.MakeMessage(); |
| 66 | message->angle = params.claw_out_angle; |
| 67 | message->angular_velocity = 0.0; |
| 68 | message->intake = 0.0; |
| 69 | message->rollers_closed = true; |
| 70 | |
| 71 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 72 | message.Send(); |
| 73 | } |
| 74 | DoProfile(bottom, -0.05, false); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame^] | 75 | if (ShouldCancel()) return true; |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 76 | DoProfile(bottom, 0.0, false); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame^] | 77 | if (ShouldCancel()) return true; |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 78 | aos::time::SleepFor(aos::time::Time::InMS(100)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 79 | |
| 80 | return true; |
| 81 | } |
| 82 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 83 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 84 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 85 | new StackAction(&::frc971::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | } // namespace actors |
| 89 | } // namespace frc971 |