Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 1 | #ifndef Y2017_ACTORS_AUTONOMOUS_ACTOR_H_ |
| 2 | #define Y2017_ACTORS_AUTONOMOUS_ACTOR_H_ |
| 3 | |
| 4 | #include <chrono> |
| 5 | #include <memory> |
| 6 | |
| 7 | #include "aos/common/actions/actions.h" |
| 8 | #include "aos/common/actions/actor.h" |
Philipp Schrader | 996a2a2 | 2017-02-22 05:02:48 +0000 | [diff] [blame] | 9 | #include "frc971/autonomous/base_autonomous_actor.h" |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 10 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 12 | #include "y2017/control_loops/superstructure/superstructure.q.h" |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 13 | |
| 14 | namespace y2017 { |
| 15 | namespace actors { |
| 16 | using ::frc971::ProfileParameters; |
| 17 | |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 18 | using ::y2017::control_loops::superstructure_queue; |
| 19 | |
Philipp Schrader | 996a2a2 | 2017-02-22 05:02:48 +0000 | [diff] [blame] | 20 | class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor { |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 21 | public: |
Philipp Schrader | 996a2a2 | 2017-02-22 05:02:48 +0000 | [diff] [blame] | 22 | explicit AutonomousActor(::frc971::autonomous::AutonomousActionQueueGroup *s); |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 23 | |
Philipp Schrader | 996a2a2 | 2017-02-22 05:02:48 +0000 | [diff] [blame] | 24 | bool RunAction( |
| 25 | const ::frc971::autonomous::AutonomousActionParams ¶ms) override; |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 26 | private: |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 27 | void Reset() { |
| 28 | intake_goal_ = 0.0; |
| 29 | turret_goal_ = 0.0; |
| 30 | vision_track_ = false; |
| 31 | hood_goal_ = 0.6; |
| 32 | shooter_velocity_ = 0.0; |
| 33 | indexer_angular_velocity_ = 0.0; |
| 34 | intake_max_velocity_ = 0.5; |
Austin Schuh | 10475d7 | 2017-04-16 19:17:48 -0700 | [diff] [blame] | 35 | gear_servo_ = 0.66; |
| 36 | use_vision_for_shots_ = false; |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 37 | InitializeEncoders(); |
| 38 | ResetDrivetrain(); |
| 39 | SendSuperstructureGoal(); |
| 40 | } |
| 41 | |
| 42 | double intake_goal_ = 0.0; |
| 43 | double turret_goal_ = 0.0; |
| 44 | bool vision_track_ = false; |
| 45 | double hood_goal_ = 0.6; |
| 46 | double shooter_velocity_ = 0.0; |
| 47 | double indexer_angular_velocity_ = 0.0; |
| 48 | double intake_max_velocity_ = 0.5; |
Austin Schuh | 10475d7 | 2017-04-16 19:17:48 -0700 | [diff] [blame] | 49 | double gear_servo_ = 0.66; |
| 50 | bool use_vision_for_shots_ = false; |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 51 | |
| 52 | void set_intake_goal(double intake_goal) { intake_goal_ = intake_goal; } |
| 53 | void set_turret_goal(double turret_goal) { turret_goal_ = turret_goal; } |
| 54 | void set_vision_track(bool vision_track) { vision_track_ = vision_track; } |
| 55 | void set_hood_goal(double hood_goal) { hood_goal_ = hood_goal; } |
| 56 | void set_shooter_velocity(double shooter_velocity) { |
| 57 | shooter_velocity_ = shooter_velocity; |
| 58 | } |
| 59 | void set_indexer_angular_velocity(double indexer_angular_velocity) { |
| 60 | indexer_angular_velocity_ = indexer_angular_velocity; |
| 61 | } |
| 62 | void set_intake_max_velocity(double intake_max_velocity) { |
| 63 | intake_max_velocity_ = intake_max_velocity; |
| 64 | } |
Austin Schuh | 10475d7 | 2017-04-16 19:17:48 -0700 | [diff] [blame] | 65 | void set_gear_servo(double gear_servo) { |
| 66 | gear_servo_ = gear_servo; |
| 67 | } |
| 68 | void set_use_vision_for_shots(bool use_vision_for_shots) { |
| 69 | use_vision_for_shots_ = use_vision_for_shots; |
| 70 | } |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 71 | |
Austin Schuh | 19e15d7 | 2017-06-24 13:34:47 -0700 | [diff] [blame^] | 72 | void WaitForHoodZeroed() { |
| 73 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
| 74 | ::std::chrono::milliseconds(5) / 2); |
| 75 | while (true) { |
| 76 | if (ShouldCancel()) return; |
| 77 | |
| 78 | superstructure_queue.status.FetchLatest(); |
| 79 | if (superstructure_queue.status.get()) { |
| 80 | if (superstructure_queue.status->hood.zeroed) { |
| 81 | return; |
| 82 | } |
| 83 | } |
| 84 | phased_loop.SleepUntilNext(); |
| 85 | } |
| 86 | } |
| 87 | |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 88 | void SendSuperstructureGoal() { |
| 89 | auto new_superstructure_goal = superstructure_queue.goal.MakeMessage(); |
| 90 | new_superstructure_goal->intake.distance = intake_goal_; |
| 91 | new_superstructure_goal->intake.disable_intake = false; |
| 92 | new_superstructure_goal->turret.angle = turret_goal_; |
| 93 | new_superstructure_goal->turret.track = vision_track_; |
| 94 | new_superstructure_goal->hood.angle = hood_goal_; |
| 95 | new_superstructure_goal->shooter.angular_velocity = shooter_velocity_; |
| 96 | |
| 97 | new_superstructure_goal->intake.profile_params.max_velocity = |
| 98 | intake_max_velocity_; |
| 99 | new_superstructure_goal->turret.profile_params.max_velocity = 6.0; |
| 100 | new_superstructure_goal->hood.profile_params.max_velocity = 5.0; |
| 101 | |
| 102 | new_superstructure_goal->intake.profile_params.max_acceleration = 5.0; |
| 103 | new_superstructure_goal->turret.profile_params.max_acceleration = 15.0; |
| 104 | new_superstructure_goal->hood.profile_params.max_acceleration = 25.0; |
| 105 | |
| 106 | new_superstructure_goal->intake.voltage_rollers = 0.0; |
| 107 | new_superstructure_goal->lights_on = true; |
| 108 | new_superstructure_goal->intake.disable_intake = false; |
Austin Schuh | 10475d7 | 2017-04-16 19:17:48 -0700 | [diff] [blame] | 109 | new_superstructure_goal->intake.gear_servo = gear_servo_; |
| 110 | new_superstructure_goal->use_vision_for_shots = use_vision_for_shots_; |
Austin Schuh | 624088a | 2017-03-22 22:36:16 -0700 | [diff] [blame] | 111 | |
| 112 | new_superstructure_goal->indexer.angular_velocity = |
| 113 | indexer_angular_velocity_; |
| 114 | |
| 115 | if (indexer_angular_velocity_ < -0.1) { |
| 116 | new_superstructure_goal->indexer.voltage_rollers = 12.0; |
| 117 | new_superstructure_goal->intake.voltage_rollers = 6.0; |
| 118 | } else { |
| 119 | new_superstructure_goal->indexer.voltage_rollers = 0.0; |
| 120 | } |
| 121 | |
| 122 | if (!new_superstructure_goal.Send()) { |
| 123 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 124 | } |
| 125 | } |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Tyler Chatow | f31da68 | 2017-01-22 01:39:40 +0000 | [diff] [blame] | 128 | } // namespace actors |
| 129 | } // namespace y2017 |
| 130 | |
| 131 | #endif // Y2017_ACTORS_AUTONOMOUS_ACTOR_H_ |