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 | |
Austin Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 8 | Rollers::Rollers(::aos::EventLoop *event_loop, const ::std::string &name) |
| 9 | : aos::controls::ControlLoop<control_loops::RollersQueue>(event_loop, |
| 10 | name) {} |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 11 | |
| 12 | void 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 Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 25 | |
| 26 | const int intake = goal->intake; |
| 27 | const int low_spit = goal->low_spit; |
| 28 | const bool human_player = goal->human_player; |
| 29 | |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 30 | output->Zero(); |
| 31 | |
| 32 | switch (low_spit) { |
| 33 | case 1: |
| 34 | // Spit towards front |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 35 | output->low_goal_voltage = k2014Bot3LowGoalBackwardVoltage; |
| 36 | output->front_intake_voltage = k2014Bot3IntakeBackwardVoltage; |
| 37 | output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 38 | break; |
| 39 | case -1: |
| 40 | // Spit towards back |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 41 | output->low_goal_voltage = k2014Bot3LowGoalForwardVoltage; |
| 42 | output->back_intake_voltage = -k2014Bot3IntakeBackwardVoltage; |
| 43 | output->front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 44 | 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 Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 55 | output->front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 56 | 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 Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 62 | output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 63 | 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 Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 74 | output->front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
| 75 | output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | } // namespace control_loops |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 80 | } // namespace y2014_bot3 |