Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 1 | #include "y2014_bot3/control_loops/rollers/rollers.h" |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 2 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 3 | #include "aos/logging/logging.h" |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 4 | |
| 5 | namespace y2014_bot3 { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 6 | namespace control_loops { |
| 7 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 8 | Rollers::Rollers(control_loops::RollersQueue *rollers) |
| 9 | : aos::controls::ControlLoop<control_loops::RollersQueue>(rollers) {} |
| 10 | |
| 11 | void 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 Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 24 | |
| 25 | const int intake = goal->intake; |
| 26 | const int low_spit = goal->low_spit; |
| 27 | const bool human_player = goal->human_player; |
| 28 | |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 29 | output->Zero(); |
| 30 | |
| 31 | switch (low_spit) { |
| 32 | case 1: |
| 33 | // Spit towards front |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 34 | output->low_goal_voltage = k2014Bot3LowGoalBackwardVoltage; |
| 35 | output->front_intake_voltage = k2014Bot3IntakeBackwardVoltage; |
| 36 | output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 37 | break; |
| 38 | case -1: |
| 39 | // Spit towards back |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 40 | output->low_goal_voltage = k2014Bot3LowGoalForwardVoltage; |
| 41 | output->back_intake_voltage = -k2014Bot3IntakeBackwardVoltage; |
| 42 | output->front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 43 | 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 Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 54 | output->front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 55 | 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 Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 61 | output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 62 | 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 Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 73 | output->front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
| 74 | output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | } // namespace control_loops |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 79 | } // namespace y2014_bot3 |