blob: 5d12880ef8aa0a7726800889a1b700b503638da7 [file] [log] [blame]
Henry Speiser354d2782022-07-22 13:56:48 -07001#include "y2022_bot3/control_loops/superstructure/superstructure.h"
2
3#include "aos/events/event_loop.h"
4#include "aos/flatbuffer_merge.h"
5#include "frc971/zeroing/wrap.h"
6
7namespace y2022_bot3 {
8namespace control_loops {
9namespace superstructure {
10
11using frc971::control_loops::AbsoluteEncoderProfiledJointStatus;
12using frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus;
13using frc971::control_loops::RelativeEncoderProfiledJointStatus;
14
15Superstructure::Superstructure(::aos::EventLoop *event_loop,
16 std::shared_ptr<const constants::Values> values,
17 const ::std::string &name)
18 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
19 name),
20 values_(values),
21 drivetrain_status_fetcher_(
22 event_loop->MakeFetcher<frc971::control_loops::drivetrain::Status>(
23 "/drivetrain")),
24 joystick_state_fetcher_(
25 event_loop->MakeFetcher<aos::JoystickState>("/aos")) {
26 event_loop->SetRuntimeRealtimePriority(30);
27}
28
29void Superstructure::RunIteration(const Goal *unsafe_goal,
30 const Position *position,
31 aos::Sender<Output>::Builder *output,
32 aos::Sender<Status>::Builder *status) {
33 (void)unsafe_goal;
34 (void)position;
35 if (WasReset()) {
36 AOS_LOG(ERROR, "WPILib reset, restarting\n");
37 }
38
39 OutputT output_struct;
40
41 if (joystick_state_fetcher_.Fetch() &&
42 joystick_state_fetcher_->has_alliance()) {
43 alliance_ = joystick_state_fetcher_->alliance();
44 }
45
46 drivetrain_status_fetcher_.Fetch();
47
48 output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct)));
49
50 Status::Builder status_builder = status->MakeBuilder<Status>();
51
52 status_builder.add_zeroed(true);
53 status_builder.add_estopped(false);
54
55 (void)status->Send(status_builder.Finish());
56}
57
58} // namespace superstructure
59} // namespace control_loops
60} // namespace y2022_bot3