blob: fcb17e90c459417b070a18167c150b14c7771b1e [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
7#include "aos/common/actions/actions.h"
8#include "aos/common/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:
Philipp Schrader996a2a22017-02-22 05:02:48 +000022 explicit AutonomousActor(::frc971::autonomous::AutonomousActionQueueGroup *s);
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;
Tyler Chatowf31da682017-01-22 01:39:40 +000026 private:
Austin Schuh624088a2017-03-22 22:36:16 -070027 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;
35 InitializeEncoders();
36 ResetDrivetrain();
37 SendSuperstructureGoal();
38 }
39
40 double intake_goal_ = 0.0;
41 double turret_goal_ = 0.0;
42 bool vision_track_ = false;
43 double hood_goal_ = 0.6;
44 double shooter_velocity_ = 0.0;
45 double indexer_angular_velocity_ = 0.0;
46 double intake_max_velocity_ = 0.5;
47
48 void set_intake_goal(double intake_goal) { intake_goal_ = intake_goal; }
49 void set_turret_goal(double turret_goal) { turret_goal_ = turret_goal; }
50 void set_vision_track(bool vision_track) { vision_track_ = vision_track; }
51 void set_hood_goal(double hood_goal) { hood_goal_ = hood_goal; }
52 void set_shooter_velocity(double shooter_velocity) {
53 shooter_velocity_ = shooter_velocity;
54 }
55 void set_indexer_angular_velocity(double indexer_angular_velocity) {
56 indexer_angular_velocity_ = indexer_angular_velocity;
57 }
58 void set_intake_max_velocity(double intake_max_velocity) {
59 intake_max_velocity_ = intake_max_velocity;
60 }
61
62 void SendSuperstructureGoal() {
63 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
64 new_superstructure_goal->intake.distance = intake_goal_;
65 new_superstructure_goal->intake.disable_intake = false;
66 new_superstructure_goal->turret.angle = turret_goal_;
67 new_superstructure_goal->turret.track = vision_track_;
68 new_superstructure_goal->hood.angle = hood_goal_;
69 new_superstructure_goal->shooter.angular_velocity = shooter_velocity_;
70
71 new_superstructure_goal->intake.profile_params.max_velocity =
72 intake_max_velocity_;
73 new_superstructure_goal->turret.profile_params.max_velocity = 6.0;
74 new_superstructure_goal->hood.profile_params.max_velocity = 5.0;
75
76 new_superstructure_goal->intake.profile_params.max_acceleration = 5.0;
77 new_superstructure_goal->turret.profile_params.max_acceleration = 15.0;
78 new_superstructure_goal->hood.profile_params.max_acceleration = 25.0;
79
80 new_superstructure_goal->intake.voltage_rollers = 0.0;
81 new_superstructure_goal->lights_on = true;
82 new_superstructure_goal->intake.disable_intake = false;
83
84 new_superstructure_goal->indexer.angular_velocity =
85 indexer_angular_velocity_;
86
87 if (indexer_angular_velocity_ < -0.1) {
88 new_superstructure_goal->indexer.voltage_rollers = 12.0;
89 new_superstructure_goal->intake.voltage_rollers = 6.0;
90 } else {
91 new_superstructure_goal->indexer.voltage_rollers = 0.0;
92 }
93
94 if (!new_superstructure_goal.Send()) {
95 LOG(ERROR, "Sending superstructure goal failed.\n");
96 }
97 }
Tyler Chatowf31da682017-01-22 01:39:40 +000098};
99
Tyler Chatowf31da682017-01-22 01:39:40 +0000100} // namespace actors
101} // namespace y2017
102
103#endif // Y2017_ACTORS_AUTONOMOUS_ACTOR_H_