blob: d2b4da975dc88ac0a968437be1d3125052e8c44d [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
Austin Schuh55a13dc2019-01-27 22:39:03 -08008Rollers::Rollers(::aos::EventLoop *event_loop, const ::std::string &name)
9 : aos::controls::ControlLoop<control_loops::RollersQueue>(event_loop,
10 name) {}
Comran Morshed41ed7c22015-11-04 21:03:37 +000011
12void Rollers::RunIteration(
13 const control_loops::RollersQueue::Goal *goal,
14 const control_loops::RollersQueue::Position * /*position*/,
15 control_loops::RollersQueue::Output *output,
16 control_loops::RollersQueue::Status * /*status*/) {
17 constexpr double k2014Bot3IntakeForwardVoltage = 12.0;
18 constexpr double k2014Bot3IntakeBackwardVoltage = -12.0;
19 constexpr double k2014Bot3LowGoalForwardVoltage = 6.0;
20 constexpr double k2014Bot3LowGoalBackwardVoltage = -6.0;
21
22 if (!output || !goal) {
23 return;
24 }
Comran Morshede9b12922015-11-04 19:46:48 +000025
26 const int intake = goal->intake;
27 const int low_spit = goal->low_spit;
28 const bool human_player = goal->human_player;
29
Comran Morshede9b12922015-11-04 19:46:48 +000030 output->Zero();
31
32 switch (low_spit) {
33 case 1:
34 // Spit towards front
Comran Morshed41ed7c22015-11-04 21:03:37 +000035 output->low_goal_voltage = k2014Bot3LowGoalBackwardVoltage;
36 output->front_intake_voltage = k2014Bot3IntakeBackwardVoltage;
37 output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000038 break;
39 case -1:
40 // Spit towards back
Comran Morshed41ed7c22015-11-04 21:03:37 +000041 output->low_goal_voltage = k2014Bot3LowGoalForwardVoltage;
42 output->back_intake_voltage = -k2014Bot3IntakeBackwardVoltage;
43 output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000044 break;
45 default:
46 // Stationary
47 break;
48 }
49
50 switch (intake) {
51 case 1:
52 // Front intake.
53 output->front_extended = true;
54 output->back_extended = false;
Comran Morshed41ed7c22015-11-04 21:03:37 +000055 output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000056 output->back_intake_voltage = 0.0;
57 break;
58 case -1:
59 // Back intake.
60 output->back_extended = true;
61 output->front_extended = false;
Comran Morshed41ed7c22015-11-04 21:03:37 +000062 output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000063 output->front_intake_voltage = 0.0;
64 break;
65 default:
66 // Stationary
67 break;
68 }
69
70 if (human_player) {
71 // Intake for human player.
72 output->front_extended = false;
73 output->back_extended = false;
Comran Morshed41ed7c22015-11-04 21:03:37 +000074 output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
75 output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000076 }
77}
78
79} // namespace control_loops
Comran Morshed41ed7c22015-11-04 21:03:37 +000080} // namespace y2014_bot3