blob: 573a41ff302ad64f757757c2e3278165f21d3062 [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"
Comran Morshed41ed7c22015-11-04 21:03:37 +00004
5namespace y2014_bot3 {
Comran Morshede9b12922015-11-04 19:46:48 +00006namespace control_loops {
7
Comran Morshed41ed7c22015-11-04 21:03:37 +00008Rollers::Rollers(control_loops::RollersQueue *rollers)
9 : aos::controls::ControlLoop<control_loops::RollersQueue>(rollers) {}
10
11void Rollers::RunIteration(
12 const control_loops::RollersQueue::Goal *goal,
13 const control_loops::RollersQueue::Position * /*position*/,
14 control_loops::RollersQueue::Output *output,
15 control_loops::RollersQueue::Status * /*status*/) {
16 constexpr double k2014Bot3IntakeForwardVoltage = 12.0;
17 constexpr double k2014Bot3IntakeBackwardVoltage = -12.0;
18 constexpr double k2014Bot3LowGoalForwardVoltage = 6.0;
19 constexpr double k2014Bot3LowGoalBackwardVoltage = -6.0;
20
21 if (!output || !goal) {
22 return;
23 }
Comran Morshede9b12922015-11-04 19:46:48 +000024
25 const int intake = goal->intake;
26 const int low_spit = goal->low_spit;
27 const bool human_player = goal->human_player;
28
Comran Morshede9b12922015-11-04 19:46:48 +000029 output->Zero();
30
31 switch (low_spit) {
32 case 1:
33 // Spit towards front
Comran Morshed41ed7c22015-11-04 21:03:37 +000034 output->low_goal_voltage = k2014Bot3LowGoalBackwardVoltage;
35 output->front_intake_voltage = k2014Bot3IntakeBackwardVoltage;
36 output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000037 break;
38 case -1:
39 // Spit towards back
Comran Morshed41ed7c22015-11-04 21:03:37 +000040 output->low_goal_voltage = k2014Bot3LowGoalForwardVoltage;
41 output->back_intake_voltage = -k2014Bot3IntakeBackwardVoltage;
42 output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000043 break;
44 default:
45 // Stationary
46 break;
47 }
48
49 switch (intake) {
50 case 1:
51 // Front intake.
52 output->front_extended = true;
53 output->back_extended = false;
Comran Morshed41ed7c22015-11-04 21:03:37 +000054 output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000055 output->back_intake_voltage = 0.0;
56 break;
57 case -1:
58 // Back intake.
59 output->back_extended = true;
60 output->front_extended = false;
Comran Morshed41ed7c22015-11-04 21:03:37 +000061 output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000062 output->front_intake_voltage = 0.0;
63 break;
64 default:
65 // Stationary
66 break;
67 }
68
69 if (human_player) {
70 // Intake for human player.
71 output->front_extended = false;
72 output->back_extended = false;
Comran Morshed41ed7c22015-11-04 21:03:37 +000073 output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
74 output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000075 }
76}
77
78} // namespace control_loops
Comran Morshed41ed7c22015-11-04 21:03:37 +000079} // namespace y2014_bot3