blob: 6646f96b9fc8f8f3c2bc70ec0a39d9655e23df3f [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
John Parkbdc86122019-02-10 12:35:25 -080011void suction_cups(
12 const SuperstructureQueue::Goal *unsafe_goal,
13 SuperstructureQueue::Output *output) {
14 const double on_voltage = 12.0;
15
16 if(unsafe_goal && output) {
17 if(unsafe_goal->suction.top || unsafe_goal->suction.bottom) {
18 output->pump_voltage = on_voltage;
19 }
20 }
21}
22
Austin Schuh55a13dc2019-01-27 22:39:03 -080023Superstructure::Superstructure(::aos::EventLoop *event_loop,
24 const ::std::string &name)
Theo Bafrali00e42272019-02-12 01:07:46 -080025 : aos::controls::ControlLoop<SuperstructureQueue>(event_loop, name),
26 elevator_(constants::GetValues().elevator.subsystem_params),
27 wrist_(constants::GetValues().wrist.subsystem_params),
28 intake_(constants::GetValues().intake),
29 stilts_(constants::GetValues().stilts.subsystem_params) {}
Tyler Chatowe51334a2019-01-20 16:58:16 -080030
Theo Bafrali00e42272019-02-12 01:07:46 -080031void Superstructure::RunIteration(const SuperstructureQueue::Goal *unsafe_goal,
32 const SuperstructureQueue::Position *position,
33 SuperstructureQueue::Output *output,
34 SuperstructureQueue::Status *status) {
Tyler Chatowe51334a2019-01-20 16:58:16 -080035 if (WasReset()) {
36 LOG(ERROR, "WPILib reset, restarting\n");
Theo Bafrali00e42272019-02-12 01:07:46 -080037 elevator_.Reset();
38 wrist_.Reset();
39 intake_.Reset();
40 stilts_.Reset();
Tyler Chatowe51334a2019-01-20 16:58:16 -080041 }
Theo Bafrali00e42272019-02-12 01:07:46 -080042
43 elevator_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->elevator) : nullptr,
44 &(position->elevator),
45 output != nullptr ? &(output->elevator_voltage) : nullptr,
46 &(status->elevator));
47
48 wrist_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->wrist) : nullptr,
49 &(position->wrist),
50 output != nullptr ? &(output->wrist_voltage) : nullptr,
51 &(status->wrist));
52
53 intake_.Iterate(
54 unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr,
55 &(position->intake_joint),
56 output != nullptr ? &(output->intake_joint_voltage) : nullptr,
57 &(status->intake));
58
59 stilts_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->stilts) : nullptr,
60 &(position->stilts),
61 output != nullptr ? &(output->stilts_voltage) : nullptr,
62 &(status->stilts));
63
64 status->zeroed = status->elevator.zeroed && status->wrist.zeroed &&
65 status->intake.zeroed && status->stilts.zeroed;
66
67 status->estopped = status->elevator.estopped || status->wrist.estopped ||
68 status->intake.estopped || status->stilts.estopped;
69
70 // TODO(theo) move these up when Iterate() is split
71 // update the goals
72 collision_avoidance_.UpdateGoal(status, unsafe_goal);
73
74 elevator_.set_min_position(collision_avoidance_.min_elevator_goal());
75 wrist_.set_min_position(collision_avoidance_.min_wrist_goal());
76 wrist_.set_max_position(collision_avoidance_.max_wrist_goal());
77 intake_.set_min_position(collision_avoidance_.min_intake_goal());
78 intake_.set_max_position(collision_avoidance_.max_intake_goal());
Tyler Chatowe51334a2019-01-20 16:58:16 -080079}
80
81} // namespace superstructure
82} // namespace control_loops
Austin Schuh55a13dc2019-01-27 22:39:03 -080083} // namespace y2019