blob: faf1c9af19eac355a5fd4d864d62cb13362a7006 [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
51 status->zeroed = status->elevator.zeroed && status->wrist.zeroed &&
52 status->intake.zeroed && status->stilts.zeroed;
53
54 status->estopped = status->elevator.estopped || status->wrist.estopped ||
55 status->intake.estopped || status->stilts.estopped;
56
Theo Bafrali09517b92019-02-16 15:59:17 -080057 if (output) {
58 if (status->intake.position > kMinIntakeAngleForRollers) {
59 output->intake_roller_voltage =
60 (unsafe_goal != nullptr) ? unsafe_goal->roller_voltage : 0.0;
61
62 } else {
63 output->intake_roller_voltage = 0.0;
64 }
65 }
66
Theo Bafrali00e42272019-02-12 01:07:46 -080067 // TODO(theo) move these up when Iterate() is split
68 // update the goals
69 collision_avoidance_.UpdateGoal(status, unsafe_goal);
70
71 elevator_.set_min_position(collision_avoidance_.min_elevator_goal());
72 wrist_.set_min_position(collision_avoidance_.min_wrist_goal());
73 wrist_.set_max_position(collision_avoidance_.max_wrist_goal());
74 intake_.set_min_position(collision_avoidance_.min_intake_goal());
75 intake_.set_max_position(collision_avoidance_.max_intake_goal());
Tyler Chatowe51334a2019-01-20 16:58:16 -080076}
77
78} // namespace superstructure
79} // namespace control_loops
Austin Schuh55a13dc2019-01-27 22:39:03 -080080} // namespace y2019