blob: d62831a6f64b548899c3810322a35c8370b1760d [file] [log] [blame]
Comran Morshed41ed7c22015-11-04 21:03:37 +00001#include "y2014_bot3/control_loops/rollers/rollers.h"
Comran Morshede9b12922015-11-04 19:46:48 +00002
John Park33858a32018-09-28 23:05:48 -07003#include "aos/logging/logging.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07004#include "y2014_bot3/control_loops/rollers/rollers_goal_generated.h"
5#include "y2014_bot3/control_loops/rollers/rollers_output_generated.h"
6#include "y2014_bot3/control_loops/rollers/rollers_position_generated.h"
7#include "y2014_bot3/control_loops/rollers/rollers_status_generated.h"
Comran Morshed41ed7c22015-11-04 21:03:37 +00008
9namespace y2014_bot3 {
Comran Morshede9b12922015-11-04 19:46:48 +000010namespace control_loops {
Alex Perrycb7da4b2019-08-28 19:35:56 -070011namespace rollers {
Comran Morshede9b12922015-11-04 19:46:48 +000012
Austin Schuh55a13dc2019-01-27 22:39:03 -080013Rollers::Rollers(::aos::EventLoop *event_loop, const ::std::string &name)
Alex Perrycb7da4b2019-08-28 19:35:56 -070014 : aos::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
15 name) {}
Comran Morshed41ed7c22015-11-04 21:03:37 +000016
Alex Perrycb7da4b2019-08-28 19:35:56 -070017void Rollers::RunIteration(const Goal *goal, const Position * /*position*/,
18 aos::Sender<Output>::Builder *output,
19 aos::Sender<Status>::Builder *status) {
Comran Morshed41ed7c22015-11-04 21:03:37 +000020 constexpr double k2014Bot3IntakeForwardVoltage = 12.0;
21 constexpr double k2014Bot3IntakeBackwardVoltage = -12.0;
22 constexpr double k2014Bot3LowGoalForwardVoltage = 6.0;
23 constexpr double k2014Bot3LowGoalBackwardVoltage = -6.0;
24
Alex Perrycb7da4b2019-08-28 19:35:56 -070025 status->Send(status->MakeBuilder<Status>().Finish());
26
Comran Morshed41ed7c22015-11-04 21:03:37 +000027 if (!output || !goal) {
28 return;
29 }
Comran Morshede9b12922015-11-04 19:46:48 +000030
Alex Perrycb7da4b2019-08-28 19:35:56 -070031 const int intake = goal->intake();
32 const int low_spit = goal->low_spit();
33 const bool human_player = goal->human_player();
Comran Morshede9b12922015-11-04 19:46:48 +000034
Alex Perrycb7da4b2019-08-28 19:35:56 -070035 OutputT output_struct;
Comran Morshede9b12922015-11-04 19:46:48 +000036
37 switch (low_spit) {
38 case 1:
39 // Spit towards front
Alex Perrycb7da4b2019-08-28 19:35:56 -070040 output_struct.low_goal_voltage = k2014Bot3LowGoalBackwardVoltage;
41 output_struct.front_intake_voltage = k2014Bot3IntakeBackwardVoltage;
42 output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000043 break;
44 case -1:
45 // Spit towards back
Alex Perrycb7da4b2019-08-28 19:35:56 -070046 output_struct.low_goal_voltage = k2014Bot3LowGoalForwardVoltage;
47 output_struct.back_intake_voltage = -k2014Bot3IntakeBackwardVoltage;
48 output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000049 break;
50 default:
51 // Stationary
52 break;
53 }
54
55 switch (intake) {
56 case 1:
57 // Front intake.
Alex Perrycb7da4b2019-08-28 19:35:56 -070058 output_struct.front_extended = true;
59 output_struct.back_extended = false;
60 output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
61 output_struct.back_intake_voltage = 0.0;
Comran Morshede9b12922015-11-04 19:46:48 +000062 break;
63 case -1:
64 // Back intake.
Alex Perrycb7da4b2019-08-28 19:35:56 -070065 output_struct.back_extended = true;
66 output_struct.front_extended = false;
67 output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
68 output_struct.front_intake_voltage = 0.0;
Comran Morshede9b12922015-11-04 19:46:48 +000069 break;
70 default:
71 // Stationary
72 break;
73 }
74
75 if (human_player) {
76 // Intake for human player.
Alex Perrycb7da4b2019-08-28 19:35:56 -070077 output_struct.front_extended = false;
78 output_struct.back_extended = false;
79 output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
80 output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000081 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070082
83 output->Send(Output::Pack(*output->fbb(), &output_struct));
Comran Morshede9b12922015-11-04 19:46:48 +000084}
85
Alex Perrycb7da4b2019-08-28 19:35:56 -070086} // namespace rollers
Comran Morshede9b12922015-11-04 19:46:48 +000087} // namespace control_loops
Comran Morshed41ed7c22015-11-04 21:03:37 +000088} // namespace y2014_bot3