blob: 3443d632e654d885375218c7d5720f56ac453602 [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
Theo Bafrali09517b92019-02-16 15:59:17 -080041 intake_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr,
42 &(position->intake_joint),
43 output != nullptr ? &(output->intake_joint_voltage) : nullptr,
44 &(status->intake));
Theo Bafrali00e42272019-02-12 01:07:46 -080045
46 stilts_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->stilts) : nullptr,
47 &(position->stilts),
48 output != nullptr ? &(output->stilts_voltage) : nullptr,
49 &(status->stilts));
50
Theo Bafrali3274a182019-02-17 20:01:38 -080051 vacuum_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->suction) : nullptr,
52 position->suction_pressure, output, &(status->has_piece),
53 event_loop());
Austin Schuhe8354752019-02-17 14:59:05 -080054
Theo Bafrali00e42272019-02-12 01:07:46 -080055 status->zeroed = status->elevator.zeroed && status->wrist.zeroed &&
56 status->intake.zeroed && status->stilts.zeroed;
57
58 status->estopped = status->elevator.estopped || status->wrist.estopped ||
59 status->intake.estopped || status->stilts.estopped;
60
Theo Bafrali09517b92019-02-16 15:59:17 -080061 if (output) {
Austin Schuh85e2e912019-02-17 15:04:29 -080062 if (unsafe_goal && status->intake.position > kMinIntakeAngleForRollers) {
63 output->intake_roller_voltage = unsafe_goal->roller_voltage;
Theo Bafrali09517b92019-02-16 15:59:17 -080064 } else {
65 output->intake_roller_voltage = 0.0;
66 }
67 }
68
Theo Bafrali00e42272019-02-12 01:07:46 -080069 // TODO(theo) move these up when Iterate() is split
70 // update the goals
71 collision_avoidance_.UpdateGoal(status, unsafe_goal);
72
73 elevator_.set_min_position(collision_avoidance_.min_elevator_goal());
74 wrist_.set_min_position(collision_avoidance_.min_wrist_goal());
75 wrist_.set_max_position(collision_avoidance_.max_wrist_goal());
76 intake_.set_min_position(collision_avoidance_.min_intake_goal());
77 intake_.set_max_position(collision_avoidance_.max_intake_goal());
Tyler Chatowe51334a2019-01-20 16:58:16 -080078}
79
80} // namespace superstructure
81} // namespace control_loops
Austin Schuh55a13dc2019-01-27 22:39:03 -080082} // namespace y2019