blob: ea77357394b850acc2de33d9ffb7220d97b0daff [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"
Alex Perrycb7da4b2019-08-28 19:35:56 -07004#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 Morshed41ed7c22015-11-04 21:03:37 +00008
Stephan Pleinesf63bde82024-01-13 15:59:33 -08009namespace y2014_bot3::control_loops::rollers {
Comran Morshede9b12922015-11-04 19:46:48 +000010
Austin Schuh55a13dc2019-01-27 22:39:03 -080011Rollers::Rollers(::aos::EventLoop *event_loop, const ::std::string &name)
James Kuszmaul61750662021-06-21 21:32:33 -070012 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
13 name) {}
Comran Morshed41ed7c22015-11-04 21:03:37 +000014
Alex Perrycb7da4b2019-08-28 19:35:56 -070015void Rollers::RunIteration(const Goal *goal, const Position * /*position*/,
16 aos::Sender<Output>::Builder *output,
17 aos::Sender<Status>::Builder *status) {
Comran Morshed41ed7c22015-11-04 21:03:37 +000018 constexpr double k2014Bot3IntakeForwardVoltage = 12.0;
19 constexpr double k2014Bot3IntakeBackwardVoltage = -12.0;
20 constexpr double k2014Bot3LowGoalForwardVoltage = 6.0;
21 constexpr double k2014Bot3LowGoalBackwardVoltage = -6.0;
22
milind1f1dca32021-07-03 13:50:07 -070023 status->CheckOk(status->Send(status->MakeBuilder<Status>().Finish()));
Alex Perrycb7da4b2019-08-28 19:35:56 -070024
Comran Morshed41ed7c22015-11-04 21:03:37 +000025 if (!output || !goal) {
26 return;
27 }
Comran Morshede9b12922015-11-04 19:46:48 +000028
Alex Perrycb7da4b2019-08-28 19:35:56 -070029 const int intake = goal->intake();
30 const int low_spit = goal->low_spit();
31 const bool human_player = goal->human_player();
Comran Morshede9b12922015-11-04 19:46:48 +000032
Alex Perrycb7da4b2019-08-28 19:35:56 -070033 OutputT output_struct;
Comran Morshede9b12922015-11-04 19:46:48 +000034
35 switch (low_spit) {
36 case 1:
37 // Spit towards front
Alex Perrycb7da4b2019-08-28 19:35:56 -070038 output_struct.low_goal_voltage = k2014Bot3LowGoalBackwardVoltage;
39 output_struct.front_intake_voltage = k2014Bot3IntakeBackwardVoltage;
40 output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000041 break;
42 case -1:
43 // Spit towards back
Alex Perrycb7da4b2019-08-28 19:35:56 -070044 output_struct.low_goal_voltage = k2014Bot3LowGoalForwardVoltage;
45 output_struct.back_intake_voltage = -k2014Bot3IntakeBackwardVoltage;
46 output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
Comran Morshede9b12922015-11-04 19:46:48 +000047 break;
48 default:
49 // Stationary
50 break;
51 }
52
53 switch (intake) {
54 case 1:
55 // Front intake.
Alex Perrycb7da4b2019-08-28 19:35:56 -070056 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 Morshede9b12922015-11-04 19:46:48 +000060 break;
61 case -1:
62 // Back intake.
Alex Perrycb7da4b2019-08-28 19:35:56 -070063 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 Morshede9b12922015-11-04 19:46:48 +000067 break;
68 default:
69 // Stationary
70 break;
71 }
72
73 if (human_player) {
74 // Intake for human player.
Alex Perrycb7da4b2019-08-28 19:35:56 -070075 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 Morshede9b12922015-11-04 19:46:48 +000079 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070080
milind1f1dca32021-07-03 13:50:07 -070081 output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct)));
Comran Morshede9b12922015-11-04 19:46:48 +000082}
83
Stephan Pleinesf63bde82024-01-13 15:59:33 -080084} // namespace y2014_bot3::control_loops::rollers