Austin Schuh | a3c148e | 2018-03-09 21:04:05 -0800 | [diff] [blame] | 1 | #ifndef Y2018_ACTORS_AUTONOMOUS_ACTOR_H_ |
| 2 | #define Y2018_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" |
| 9 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 10 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
| 12 | #include "y2018/control_loops/superstructure/arm/generated_graph.h" |
| 13 | #include "y2018/control_loops/superstructure/superstructure.q.h" |
| 14 | |
| 15 | namespace y2018 { |
| 16 | namespace actors { |
| 17 | using ::y2018::control_loops::superstructure_queue; |
| 18 | |
| 19 | namespace arm = ::y2018::control_loops::superstructure::arm; |
| 20 | |
| 21 | class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor { |
| 22 | public: |
| 23 | explicit AutonomousActor(::frc971::autonomous::AutonomousActionQueueGroup *s); |
| 24 | |
| 25 | bool RunAction( |
| 26 | const ::frc971::autonomous::AutonomousActionParams ¶ms) override; |
| 27 | private: |
| 28 | void Reset() { |
| 29 | roller_voltage_ = 0.0; |
| 30 | left_intake_angle_ = -3.3; |
| 31 | right_intake_angle_ = -3.3; |
| 32 | arm_goal_position_ = arm::NeutralIndex(); |
| 33 | grab_box_ = false; |
| 34 | open_claw_ = false; |
| 35 | deploy_fork_ = false; |
| 36 | InitializeEncoders(); |
| 37 | ResetDrivetrain(); |
| 38 | SendSuperstructureGoal(); |
| 39 | } |
| 40 | |
| 41 | double roller_voltage_ = 0.0; |
| 42 | double left_intake_angle_ = -3.3; |
| 43 | double right_intake_angle_ = -3.3; |
| 44 | uint32_t arm_goal_position_ = arm::NeutralIndex(); |
| 45 | bool grab_box_ = false; |
| 46 | bool open_claw_ = false; |
| 47 | bool deploy_fork_ = false; |
| 48 | |
| 49 | void set_roller_voltage(double roller_voltage) { |
| 50 | roller_voltage_ = roller_voltage; |
| 51 | } |
| 52 | void set_left_intake_angle(double left_intake_angle) { |
| 53 | left_intake_angle_ = left_intake_angle; |
| 54 | } |
| 55 | void set_right_intake_angle(double right_intake_angle) { |
| 56 | right_intake_angle_ = right_intake_angle; |
| 57 | } |
| 58 | void set_arm_goal_position(uint32_t arm_goal_position) { |
| 59 | arm_goal_position_ = arm_goal_position; |
| 60 | } |
| 61 | void set_grab_box(bool grab_box) { grab_box_ = grab_box; } |
| 62 | void set_open_claw(bool open_claw) { open_claw_ = open_claw; } |
| 63 | void set_deploy_fork(bool deploy_fork) { deploy_fork_ = deploy_fork; } |
| 64 | |
| 65 | void SendSuperstructureGoal() { |
| 66 | auto new_superstructure_goal = superstructure_queue.goal.MakeMessage(); |
| 67 | new_superstructure_goal->intake.roller_voltage = roller_voltage_; |
| 68 | new_superstructure_goal->intake.left_intake_angle = left_intake_angle_; |
| 69 | new_superstructure_goal->intake.right_intake_angle = right_intake_angle_; |
| 70 | |
| 71 | new_superstructure_goal->arm_goal_position = arm_goal_position_; |
| 72 | new_superstructure_goal->grab_box = grab_box_; |
| 73 | new_superstructure_goal->open_claw = open_claw_; |
| 74 | new_superstructure_goal->deploy_fork = deploy_fork_; |
| 75 | |
| 76 | if (!new_superstructure_goal.Send()) { |
| 77 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 78 | } |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | } // namespace actors |
| 83 | } // namespace y2018 |
| 84 | |
| 85 | #endif // Y2018_ACTORS_AUTONOMOUS_ACTOR_H_ |