blob: ac79eb92f9f491e90d71779c6a21c3c8b2f6473e [file] [log] [blame]
Tyler Chatowf31da682017-01-22 01:39:40 +00001#ifndef Y2017_ACTORS_AUTONOMOUS_ACTOR_H_
2#define Y2017_ACTORS_AUTONOMOUS_ACTOR_H_
3
4#include <chrono>
5#include <memory>
6
John Park33858a32018-09-28 23:05:48 -07007#include "aos/actions/actions.h"
8#include "aos/actions/actor.h"
Philipp Schrader996a2a22017-02-22 05:02:48 +00009#include "frc971/autonomous/base_autonomous_actor.h"
Tyler Chatowf31da682017-01-22 01:39:40 +000010#include "frc971/control_loops/drivetrain/drivetrain.q.h"
11#include "frc971/control_loops/drivetrain/drivetrain_config.h"
Austin Schuh624088a2017-03-22 22:36:16 -070012#include "y2017/control_loops/superstructure/superstructure.q.h"
Tyler Chatowf31da682017-01-22 01:39:40 +000013
14namespace y2017 {
15namespace actors {
16using ::frc971::ProfileParameters;
17
Austin Schuh624088a2017-03-22 22:36:16 -070018using ::y2017::control_loops::superstructure_queue;
19
Philipp Schrader996a2a22017-02-22 05:02:48 +000020class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
Tyler Chatowf31da682017-01-22 01:39:40 +000021 public:
Austin Schuh1bf8a212019-05-26 22:13:14 -070022 explicit AutonomousActor(::aos::EventLoop *event_loop);
Tyler Chatowf31da682017-01-22 01:39:40 +000023
Philipp Schrader996a2a22017-02-22 05:02:48 +000024 bool RunAction(
25 const ::frc971::autonomous::AutonomousActionParams &params) override;
Austin Schuhbfb04122019-05-22 21:16:51 -070026
Tyler Chatowf31da682017-01-22 01:39:40 +000027 private:
Austin Schuh624088a2017-03-22 22:36:16 -070028 void Reset() {
29 intake_goal_ = 0.0;
30 turret_goal_ = 0.0;
31 vision_track_ = false;
32 hood_goal_ = 0.6;
33 shooter_velocity_ = 0.0;
34 indexer_angular_velocity_ = 0.0;
35 intake_max_velocity_ = 0.5;
Austin Schuh10475d72017-04-16 19:17:48 -070036 gear_servo_ = 0.66;
37 use_vision_for_shots_ = false;
Austin Schuh624088a2017-03-22 22:36:16 -070038 InitializeEncoders();
39 ResetDrivetrain();
40 SendSuperstructureGoal();
41 }
42
43 double intake_goal_ = 0.0;
44 double turret_goal_ = 0.0;
45 bool vision_track_ = false;
46 double hood_goal_ = 0.6;
47 double shooter_velocity_ = 0.0;
48 double indexer_angular_velocity_ = 0.0;
49 double intake_max_velocity_ = 0.5;
Austin Schuh10475d72017-04-16 19:17:48 -070050 double gear_servo_ = 0.66;
51 bool use_vision_for_shots_ = false;
Austin Schuh624088a2017-03-22 22:36:16 -070052
53 void set_intake_goal(double intake_goal) { intake_goal_ = intake_goal; }
54 void set_turret_goal(double turret_goal) { turret_goal_ = turret_goal; }
55 void set_vision_track(bool vision_track) { vision_track_ = vision_track; }
56 void set_hood_goal(double hood_goal) { hood_goal_ = hood_goal; }
57 void set_shooter_velocity(double shooter_velocity) {
58 shooter_velocity_ = shooter_velocity;
59 }
60 void set_indexer_angular_velocity(double indexer_angular_velocity) {
61 indexer_angular_velocity_ = indexer_angular_velocity;
62 }
63 void set_intake_max_velocity(double intake_max_velocity) {
64 intake_max_velocity_ = intake_max_velocity;
65 }
Austin Schuh10475d72017-04-16 19:17:48 -070066 void set_gear_servo(double gear_servo) {
67 gear_servo_ = gear_servo;
68 }
69 void set_use_vision_for_shots(bool use_vision_for_shots) {
70 use_vision_for_shots_ = use_vision_for_shots;
71 }
Austin Schuh624088a2017-03-22 22:36:16 -070072
Austin Schuh19e15d72017-06-24 13:34:47 -070073 void WaitForHoodZeroed() {
74 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
Austin Schuhd32b3622019-06-23 18:49:06 -070075 event_loop()->monotonic_now(),
Austin Schuh19e15d72017-06-24 13:34:47 -070076 ::std::chrono::milliseconds(5) / 2);
77 while (true) {
78 if (ShouldCancel()) return;
79
80 superstructure_queue.status.FetchLatest();
81 if (superstructure_queue.status.get()) {
82 if (superstructure_queue.status->hood.zeroed) {
83 return;
84 }
85 }
86 phased_loop.SleepUntilNext();
87 }
88 }
89
Austin Schuh624088a2017-03-22 22:36:16 -070090 void SendSuperstructureGoal() {
91 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
92 new_superstructure_goal->intake.distance = intake_goal_;
93 new_superstructure_goal->intake.disable_intake = false;
94 new_superstructure_goal->turret.angle = turret_goal_;
95 new_superstructure_goal->turret.track = vision_track_;
96 new_superstructure_goal->hood.angle = hood_goal_;
97 new_superstructure_goal->shooter.angular_velocity = shooter_velocity_;
98
99 new_superstructure_goal->intake.profile_params.max_velocity =
100 intake_max_velocity_;
101 new_superstructure_goal->turret.profile_params.max_velocity = 6.0;
102 new_superstructure_goal->hood.profile_params.max_velocity = 5.0;
103
104 new_superstructure_goal->intake.profile_params.max_acceleration = 5.0;
105 new_superstructure_goal->turret.profile_params.max_acceleration = 15.0;
106 new_superstructure_goal->hood.profile_params.max_acceleration = 25.0;
107
108 new_superstructure_goal->intake.voltage_rollers = 0.0;
109 new_superstructure_goal->lights_on = true;
110 new_superstructure_goal->intake.disable_intake = false;
Austin Schuh10475d72017-04-16 19:17:48 -0700111 new_superstructure_goal->intake.gear_servo = gear_servo_;
112 new_superstructure_goal->use_vision_for_shots = use_vision_for_shots_;
Austin Schuh624088a2017-03-22 22:36:16 -0700113
114 new_superstructure_goal->indexer.angular_velocity =
115 indexer_angular_velocity_;
116
117 if (indexer_angular_velocity_ < -0.1) {
118 new_superstructure_goal->indexer.voltage_rollers = 12.0;
119 new_superstructure_goal->intake.voltage_rollers = 6.0;
120 } else {
121 new_superstructure_goal->indexer.voltage_rollers = 0.0;
122 }
123
124 if (!new_superstructure_goal.Send()) {
125 LOG(ERROR, "Sending superstructure goal failed.\n");
126 }
127 }
Tyler Chatowf31da682017-01-22 01:39:40 +0000128};
129
Tyler Chatowf31da682017-01-22 01:39:40 +0000130} // namespace actors
131} // namespace y2017
132
133#endif // Y2017_ACTORS_AUTONOMOUS_ACTOR_H_