blob: 4bc6a5dc1563806ffd97b3fdcad49964d4f1f532 [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
9DEFINE_bool(ignore_distance, false,
10 "If true, ignore distance when shooting and obay joystick_reader");
11
12namespace y2023_bot3 {
13namespace control_loops {
14namespace superstructure {
15
16using ::aos::monotonic_clock;
17
18using frc971::control_loops::AbsoluteEncoderProfiledJointStatus;
19using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus;
20using frc971::control_loops::RelativeEncoderProfiledJointStatus;
21
22Superstructure::Superstructure(::aos::EventLoop *event_loop,
23 std::shared_ptr<const constants::Values> values,
24 const ::std::string &name)
25 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
26 name),
Maxwell Hendersonf90bdb22023-11-08 11:37:27 -080027 values_(values) {
Ariv Diggi0af59c02023-10-07 13:15:39 -070028 event_loop->SetRuntimeRealtimePriority(30);
29}
30
31void Superstructure::RunIteration(const Goal *unsafe_goal,
32 const Position *position,
33 aos::Sender<Output>::Builder *output,
34 aos::Sender<Status>::Builder *status) {
Ariv Diggi0af59c02023-10-07 13:15:39 -070035 const monotonic_clock::time_point timestamp =
36 event_loop()->context().monotonic_event_time;
Ariv Diggi0af59c02023-10-07 13:15:39 -070037
38 if (WasReset()) {
39 AOS_LOG(ERROR, "WPILib reset, restarting\n");
Maxwell Henderson3772d282023-11-06 11:07:49 -080040 end_effector_.Reset();
Ariv Diggi0af59c02023-10-07 13:15:39 -070041 }
42
43 OutputT output_struct;
44
Maxwell Henderson3772d282023-11-06 11:07:49 -080045 end_effector_.RunIteration(
46 timestamp,
47 unsafe_goal != nullptr ? unsafe_goal->roller_goal() : RollerGoal::IDLE,
48 position->end_effector_cube_beam_break(), &output_struct.roller_voltage,
49 unsafe_goal != nullptr ? unsafe_goal->preloaded_with_cube() : false);
50
Ariv Diggi0af59c02023-10-07 13:15:39 -070051 if (output) {
52 output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct)));
53 }
54
55 Status::Builder status_builder = status->MakeBuilder<Status>();
56 status_builder.add_zeroed(true);
Maxwell Henderson3772d282023-11-06 11:07:49 -080057 status_builder.add_end_effector_state(end_effector_.state());
Ariv Diggi0af59c02023-10-07 13:15:39 -070058
59 (void)status->Send(status_builder.Finish());
60}
61
62} // namespace superstructure
63} // namespace control_loops
64} // namespace y2023_bot3