blob: 877754930210e0ed811371e56fac8f331a50f20c [file] [log] [blame]
Daniel Petticbc41122014-11-15 10:27:41 -08001#include "bot3/control_loops/rollers/rollers.h"
2#include "bot3/control_loops/rollers/rollers.q.h"
3
4namespace bot3 {
5namespace control_loops {
6
7void RollersLoop::RunIteration(const Rollers::Goal *goal,
8 const Rollers::Position * /*position*/,
9 Rollers::Output *output,
10 Rollers::Status * /*status*/) {
11 constexpr double kBot3IntakeForwardVoltage = 12.0;
12 constexpr double kBot3IntakeBackwardVoltage = -12.0;
13 constexpr double kBot3LowGoalForwardVoltage = 6.0;
14 constexpr double kBot3LowGoalBackwardVoltage = -6.0;
15
16 const int intake = goal->intake;
17 const int low_spit = goal->low_spit;
18 const bool human_player = goal->human_player;
19
20 if (!output) {
21 return;
22 }
23
24 output->Zero();
25
26 switch (low_spit) {
27 case 1:
28 // Spit towards front
29 output->low_goal_voltage = kBot3LowGoalBackwardVoltage;
30 output->front_intake_voltage = kBot3IntakeBackwardVoltage;
31 output->back_intake_voltage = -kBot3IntakeForwardVoltage;
32 break;
33 case -1:
34 // Spit towards back
35 output->low_goal_voltage = kBot3LowGoalForwardVoltage;
36 output->back_intake_voltage = -kBot3IntakeBackwardVoltage;
37 output->front_intake_voltage = kBot3IntakeForwardVoltage;
38 break;
39 default:
40 // Stationary
41 break;
42 }
43
44 switch (intake) {
45 case 1:
46 // Front intake.
47 output->front_extended = true;
48 output->back_extended = false;
49 output->front_intake_voltage = kBot3IntakeForwardVoltage;
50 output->back_intake_voltage = 0.0;
51 break;
52 case -1:
53 // Back intake.
54 output->back_extended = true;
55 output->front_extended = false;
56 output->back_intake_voltage = -kBot3IntakeForwardVoltage;
57 output->front_intake_voltage = 0.0;
58 break;
59 default:
60 // Stationary
61 break;
62 }
63
64 if (human_player) {
65 // Intake for human player.
66 output->front_extended = false;
67 output->back_extended = false;
68 output->front_intake_voltage = kBot3IntakeForwardVoltage;
69 output->back_intake_voltage = -kBot3IntakeForwardVoltage;
70 }
71}
72
73} // namespace control_loops
74} // namespace bot3