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" |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 4 | #include "frc971/actors/stack_actor.h" |
| 5 | #include "frc971/actors/fridge_profile_actor.h" |
| 6 | #include "frc971/constants.h" |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 7 | #include "frc971/control_loops/claw/claw.q.h" |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 8 | |
| 9 | namespace frc971 { |
| 10 | namespace actors { |
| 11 | namespace { |
| 12 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 13 | static constexpr double kArmVelocity = 0.40; |
| 14 | static constexpr double kArmAcceleration = 1.0; |
| 15 | static constexpr double kElevatorVelocity = 0.5; |
| 16 | static constexpr double kElevatorAcceleration = 2.2; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 17 | |
| 18 | } // namespace |
| 19 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 20 | StackActor::StackActor(StackActionQueueGroup *queues) |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 21 | : aos::common::actions::ActorBase<StackActionQueueGroup>(queues) {} |
| 22 | |
| 23 | namespace { |
| 24 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 25 | void 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(); |
| 43 | profile->WaitUntilDone(); |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 48 | bool StackActor::RunAction(const StackParams ¶ms) { |
| 49 | const auto &values = constants::GetValues(); |
| 50 | const double bottom = 0.020; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 51 | |
| 52 | // Set the current stack down on top of the bottom box. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 53 | DoProfile(0.45, 0.0, true); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 54 | // Move down to enclose bottom box. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 55 | DoProfile(bottom + values.tote_height, 0.0, true); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 56 | // Clamp. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 57 | { |
| 58 | auto message = control_loops::claw_queue.goal.MakeMessage(); |
| 59 | message->angle = params.claw_out_angle; |
| 60 | message->angular_velocity = 0.0; |
| 61 | message->intake = 0.0; |
| 62 | message->rollers_closed = true; |
| 63 | |
| 64 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 65 | message.Send(); |
| 66 | } |
| 67 | DoProfile(bottom, -0.05, false); |
| 68 | DoProfile(bottom, 0.0, false); |
| 69 | aos::time::SleepFor(aos::time::Time::InMS(100)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 74 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 75 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame^] | 76 | new StackAction(&::frc971::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } // namespace actors |
| 80 | } // namespace frc971 |