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