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" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 4 | #include "y2014_bot3/control_loops/rollers/rollers_goal_generated.h" |
| 5 | #include "y2014_bot3/control_loops/rollers/rollers_output_generated.h" |
| 6 | #include "y2014_bot3/control_loops/rollers/rollers_position_generated.h" |
| 7 | #include "y2014_bot3/control_loops/rollers/rollers_status_generated.h" |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 8 | |
| 9 | namespace y2014_bot3 { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 10 | namespace control_loops { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 11 | namespace rollers { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 12 | |
Austin Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 13 | Rollers::Rollers(::aos::EventLoop *event_loop, const ::std::string &name) |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 14 | : aos::controls::ControlLoop<Goal, Position, Status, Output>(event_loop, |
| 15 | name) {} |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 16 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 17 | void Rollers::RunIteration(const Goal *goal, const Position * /*position*/, |
| 18 | aos::Sender<Output>::Builder *output, |
| 19 | aos::Sender<Status>::Builder *status) { |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 20 | constexpr double k2014Bot3IntakeForwardVoltage = 12.0; |
| 21 | constexpr double k2014Bot3IntakeBackwardVoltage = -12.0; |
| 22 | constexpr double k2014Bot3LowGoalForwardVoltage = 6.0; |
| 23 | constexpr double k2014Bot3LowGoalBackwardVoltage = -6.0; |
| 24 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 25 | status->Send(status->MakeBuilder<Status>().Finish()); |
| 26 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 27 | if (!output || !goal) { |
| 28 | return; |
| 29 | } |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 30 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 31 | const int intake = goal->intake(); |
| 32 | const int low_spit = goal->low_spit(); |
| 33 | const bool human_player = goal->human_player(); |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 34 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 35 | OutputT output_struct; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 36 | |
| 37 | switch (low_spit) { |
| 38 | case 1: |
| 39 | // Spit towards front |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 40 | output_struct.low_goal_voltage = k2014Bot3LowGoalBackwardVoltage; |
| 41 | output_struct.front_intake_voltage = k2014Bot3IntakeBackwardVoltage; |
| 42 | output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 43 | break; |
| 44 | case -1: |
| 45 | // Spit towards back |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 46 | output_struct.low_goal_voltage = k2014Bot3LowGoalForwardVoltage; |
| 47 | output_struct.back_intake_voltage = -k2014Bot3IntakeBackwardVoltage; |
| 48 | output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 49 | break; |
| 50 | default: |
| 51 | // Stationary |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | switch (intake) { |
| 56 | case 1: |
| 57 | // Front intake. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 58 | output_struct.front_extended = true; |
| 59 | output_struct.back_extended = false; |
| 60 | output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
| 61 | output_struct.back_intake_voltage = 0.0; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 62 | break; |
| 63 | case -1: |
| 64 | // Back intake. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 65 | output_struct.back_extended = true; |
| 66 | output_struct.front_extended = false; |
| 67 | output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
| 68 | output_struct.front_intake_voltage = 0.0; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 69 | break; |
| 70 | default: |
| 71 | // Stationary |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | if (human_player) { |
| 76 | // Intake for human player. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 77 | output_struct.front_extended = false; |
| 78 | output_struct.back_extended = false; |
| 79 | output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage; |
| 80 | output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage; |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 81 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 82 | |
| 83 | output->Send(Output::Pack(*output->fbb(), &output_struct)); |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 86 | } // namespace rollers |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 87 | } // namespace control_loops |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 88 | } // namespace y2014_bot3 |