Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 1 | #include "frc971/actors/stack_actor.h" |
| 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 | |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 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 { |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 14 | constexpr ProfileParams kSlowArmMove{0.8, 1.4}; |
| 15 | constexpr ProfileParams kSlowElevatorMove{0.5, 3.0}; |
| 16 | constexpr ProfileParams kReallySlowElevatorMove{0.10, 1.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}; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 20 | } // namespace |
| 21 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 22 | StackActor::StackActor(StackActionQueueGroup *queues) |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 23 | : FridgeActorBase<StackActionQueueGroup>(queues) {} |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 24 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 25 | bool StackActor::RunAction(const StackParams ¶ms) { |
| 26 | const auto &values = constants::GetValues(); |
| 27 | const double bottom = 0.020; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 28 | |
| 29 | // Set the current stack down on top of the bottom box. |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 30 | DoFridgeProfile(0.39, 0.0, kSlowArmMove, kReallySlowElevatorMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 31 | if (ShouldCancel()) return true; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 32 | // Set down on the box. |
| 33 | DoFridgeProfile(bottom + values.tote_height, 0.0, kSlowArmMove, |
| 34 | kSlowElevatorMove, true); |
Ben Fredrickson | 32e6c25 | 2015-02-21 23:53:38 -0800 | [diff] [blame] | 35 | if (ShouldCancel()) return true; |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 36 | // Clamp. |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 37 | { |
| 38 | auto message = control_loops::claw_queue.goal.MakeMessage(); |
| 39 | message->angle = params.claw_out_angle; |
| 40 | message->angular_velocity = 0.0; |
| 41 | message->intake = 0.0; |
| 42 | message->rollers_closed = true; |
| 43 | |
| 44 | LOG_STRUCT(DEBUG, "Sending claw goal", *message); |
| 45 | message.Send(); |
| 46 | } |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 47 | DoFridgeProfile(bottom, -0.05, kFastArmMove, kFastElevatorMove, false); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 48 | if (ShouldCancel()) return true; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame^] | 49 | DoFridgeProfile(bottom, 0.0, kFastArmMove, kFastElevatorMove, false); |
Austin Schuh | d2f47fc | 2015-03-01 00:06:27 -0800 | [diff] [blame] | 50 | if (ShouldCancel()) return true; |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 51 | aos::time::SleepFor(aos::time::Time::InMS(100)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 52 | |
| 53 | return true; |
| 54 | } |
| 55 | |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 56 | ::std::unique_ptr<StackAction> MakeStackAction(const StackParams ¶ms) { |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 57 | return ::std::unique_ptr<StackAction>( |
Austin Schuh | dc17101 | 2015-02-22 21:36:55 -0800 | [diff] [blame] | 58 | new StackAction(&::frc971::actors::stack_action, params)); |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } // namespace actors |
| 62 | } // namespace frc971 |