blob: efa6ccbb60161cfda50fab073e0df66142688b0d [file] [log] [blame]
Tyler Chatowe51334a2019-01-20 16:58:16 -08001#include "y2019/control_loops/superstructure/superstructure.h"
2
3#include "aos/controls/control_loops.q.h"
4#include "frc971/control_loops/control_loops.q.h"
Theo Bafrali00e42272019-02-12 01:07:46 -08005#include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
Tyler Chatowe51334a2019-01-20 16:58:16 -08006
7namespace y2019 {
8namespace control_loops {
9namespace superstructure {
10
Austin Schuh55a13dc2019-01-27 22:39:03 -080011Superstructure::Superstructure(::aos::EventLoop *event_loop,
12 const ::std::string &name)
Theo Bafrali00e42272019-02-12 01:07:46 -080013 : aos::controls::ControlLoop<SuperstructureQueue>(event_loop, name),
14 elevator_(constants::GetValues().elevator.subsystem_params),
15 wrist_(constants::GetValues().wrist.subsystem_params),
16 intake_(constants::GetValues().intake),
17 stilts_(constants::GetValues().stilts.subsystem_params) {}
Tyler Chatowe51334a2019-01-20 16:58:16 -080018
Theo Bafrali00e42272019-02-12 01:07:46 -080019void Superstructure::RunIteration(const SuperstructureQueue::Goal *unsafe_goal,
20 const SuperstructureQueue::Position *position,
21 SuperstructureQueue::Output *output,
22 SuperstructureQueue::Status *status) {
Tyler Chatowe51334a2019-01-20 16:58:16 -080023 if (WasReset()) {
24 LOG(ERROR, "WPILib reset, restarting\n");
Theo Bafrali00e42272019-02-12 01:07:46 -080025 elevator_.Reset();
26 wrist_.Reset();
27 intake_.Reset();
28 stilts_.Reset();
Tyler Chatowe51334a2019-01-20 16:58:16 -080029 }
Theo Bafrali00e42272019-02-12 01:07:46 -080030
31 elevator_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->elevator) : nullptr,
32 &(position->elevator),
33 output != nullptr ? &(output->elevator_voltage) : nullptr,
34 &(status->elevator));
35
36 wrist_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->wrist) : nullptr,
37 &(position->wrist),
38 output != nullptr ? &(output->wrist_voltage) : nullptr,
39 &(status->wrist));
40
41 intake_.Iterate(
42 unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr,
43 &(position->intake_joint),
44 output != nullptr ? &(output->intake_joint_voltage) : nullptr,
45 &(status->intake));
46
47 stilts_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->stilts) : nullptr,
48 &(position->stilts),
49 output != nullptr ? &(output->stilts_voltage) : nullptr,
50 &(status->stilts));
51
52 status->zeroed = status->elevator.zeroed && status->wrist.zeroed &&
53 status->intake.zeroed && status->stilts.zeroed;
54
55 status->estopped = status->elevator.estopped || status->wrist.estopped ||
56 status->intake.estopped || status->stilts.estopped;
57
58 // TODO(theo) move these up when Iterate() is split
59 // update the goals
60 collision_avoidance_.UpdateGoal(status, unsafe_goal);
61
62 elevator_.set_min_position(collision_avoidance_.min_elevator_goal());
63 wrist_.set_min_position(collision_avoidance_.min_wrist_goal());
64 wrist_.set_max_position(collision_avoidance_.max_wrist_goal());
65 intake_.set_min_position(collision_avoidance_.min_intake_goal());
66 intake_.set_max_position(collision_avoidance_.max_intake_goal());
Tyler Chatowe51334a2019-01-20 16:58:16 -080067}
68
69} // namespace superstructure
70} // namespace control_loops
Austin Schuh55a13dc2019-01-27 22:39:03 -080071} // namespace y2019