blob: c18da1551e324891c027f892df63c287b98750dd [file] [log] [blame]
James (Peilun) Lia70e5752024-09-18 20:43:00 -07001#include "y2024_bot3/control_loops/superstructure/superstructure.h"
2
3#include <chrono>
4
5#include "aos/events/event_loop.h"
6#include "aos/flatbuffer_merge.h"
7#include "aos/network/team_number.h"
8#include "aos/time/time.h"
9#include "frc971/zeroing/wrap.h"
10
11ABSL_FLAG(bool, ignore_distance, false,
12 "If true, ignore distance when shooting and obey joystick_reader");
13
14namespace y2024_bot3::control_loops::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 const ::std::string &name)
24 : frc971::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
25 name),
26 constants_fetcher_(event_loop),
27 robot_constants_(&constants_fetcher_.constants()),
28 joystick_state_fetcher_(
29 event_loop->MakeFetcher<aos::JoystickState>("/aos")) {
30 event_loop->SetRuntimeRealtimePriority(30);
31}
32
33bool PositionNear(double position, double goal, double threshold) {
34 return std::abs(position - goal) < threshold;
35}
36
37void Superstructure::RunIteration(const Goal *unsafe_goal,
38 const Position *position,
39 aos::Sender<Output>::Builder *output,
40 aos::Sender<Status>::Builder *status) {
41 (void)position;
42
43 if (WasReset()) {
44 AOS_LOG(ERROR, "WPILib reset, restarting\n");
45 }
46
47 OutputT output_struct;
48
49 if (unsafe_goal != nullptr) {
50 }
51
52 if (joystick_state_fetcher_.Fetch() &&
53 joystick_state_fetcher_->has_alliance()) {
54 alliance_ = joystick_state_fetcher_->alliance();
55 }
56
57 if (output) {
58 output->CheckOk(output->Send(Output::Pack(*output->fbb(), &output_struct)));
59 }
60
61 Status::Builder status_builder = status->MakeBuilder<Status>();
62
63 const bool zeroed = true;
64 const bool estopped = false;
65
66 status_builder.add_zeroed(zeroed);
67 status_builder.add_estopped(estopped);
68
69 (void)status->Send(status_builder.Finish());
70}
71} // namespace y2024_bot3::control_loops::superstructure