blob: 7f68ab9a9f2de4de38f07b4e9c515c9e2b709647 [file] [log] [blame]
Ariv Diggi0af59c02023-10-07 13:15:39 -07001#include "y2023_bot3/control_loops/superstructure/superstructure.h"
2
3#include "aos/events/event_loop.h"
4#include "aos/flatbuffer_merge.h"
5#include "aos/network/team_number.h"
6#include "frc971/shooter_interpolation/interpolation.h"
7#include "frc971/zeroing/wrap.h"
8
Austin Schuh99f7c6a2024-06-25 22:07:44 -07009ABSL_FLAG(bool, ignore_distance, false,
10 "If true, ignore distance when shooting and obay joystick_reader");
Ariv Diggi0af59c02023-10-07 13:15:39 -070011
Stephan Pleinesf63bde82024-01-13 15:59:33 -080012namespace y2023_bot3::control_loops::superstructure {
Ariv Diggi0af59c02023-10-07 13:15:39 -070013
14using ::aos::monotonic_clock;
15
Ariv Diggi0af59c02023-10-07 13:15:39 -070016using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus;
17using frc971::control_loops::RelativeEncoderProfiledJointStatus;
18
19Superstructure::Superstructure(::aos::EventLoop *event_loop,
20 std::shared_ptr<const constants::Values> values,
21 const ::std::string &name)
22 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
23 name),
Maxwell Henderson4d4be542023-11-29 18:26:13 -080024 values_(values) {
Ariv Diggi0af59c02023-10-07 13:15:39 -070025 event_loop->SetRuntimeRealtimePriority(30);
26}
27
28void Superstructure::RunIteration(const Goal *unsafe_goal,
29 const Position *position,
30 aos::Sender<Output>::Builder *output,
31 aos::Sender<Status>::Builder *status) {
Maxwell Henderson4d4be542023-11-29 18:26:13 -080032 (void)unsafe_goal;
33 (void)position;
Ariv Diggi0af59c02023-10-07 13:15:39 -070034
35 if (WasReset()) {
36 AOS_LOG(ERROR, "WPILib reset, restarting\n");
37 }
38
39 OutputT output_struct;
40
Ariv Diggi0af59c02023-10-07 13:15:39 -070041 Status::Builder status_builder = status->MakeBuilder<Status>();
Maxwell Henderson43684fa2023-11-06 11:08:06 -080042
Maxwell Henderson0d220772023-11-06 11:09:58 -080043 if (output) {
44 output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct)));
45 }
46
Maxwell Henderson4d4be542023-11-29 18:26:13 -080047 status_builder.add_zeroed(true);
48
Ariv Diggi0af59c02023-10-07 13:15:39 -070049 (void)status->Send(status_builder.Finish());
50}
51
Stephan Pleinesf63bde82024-01-13 15:59:33 -080052} // namespace y2023_bot3::control_loops::superstructure