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