blob: a75f9a16eadb51ccb8e70c36b4a95f560b4f321a [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
Theo Bafrali09517b92019-02-16 15:59:17 -080053 intake_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr,
54 &(position->intake_joint),
55 output != nullptr ? &(output->intake_joint_voltage) : nullptr,
56 &(status->intake));
Theo Bafrali00e42272019-02-12 01:07:46 -080057
58 stilts_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->stilts) : nullptr,
59 &(position->stilts),
60 output != nullptr ? &(output->stilts_voltage) : nullptr,
61 &(status->stilts));
62
63 status->zeroed = status->elevator.zeroed && status->wrist.zeroed &&
64 status->intake.zeroed && status->stilts.zeroed;
65
66 status->estopped = status->elevator.estopped || status->wrist.estopped ||
67 status->intake.estopped || status->stilts.estopped;
68
Theo Bafrali09517b92019-02-16 15:59:17 -080069 if (output) {
Austin Schuh85e2e912019-02-17 15:04:29 -080070 if (unsafe_goal && status->intake.position > kMinIntakeAngleForRollers) {
71 output->intake_roller_voltage = unsafe_goal->roller_voltage;
Theo Bafrali09517b92019-02-16 15:59:17 -080072 } else {
73 output->intake_roller_voltage = 0.0;
74 }
75 }
76
Theo Bafrali00e42272019-02-12 01:07:46 -080077 // TODO(theo) move these up when Iterate() is split
78 // update the goals
79 collision_avoidance_.UpdateGoal(status, unsafe_goal);
80
81 elevator_.set_min_position(collision_avoidance_.min_elevator_goal());
82 wrist_.set_min_position(collision_avoidance_.min_wrist_goal());
83 wrist_.set_max_position(collision_avoidance_.max_wrist_goal());
84 intake_.set_min_position(collision_avoidance_.min_intake_goal());
85 intake_.set_max_position(collision_avoidance_.max_intake_goal());
Tyler Chatowe51334a2019-01-20 16:58:16 -080086}
87
88} // namespace superstructure
89} // namespace control_loops
Austin Schuh55a13dc2019-01-27 22:39:03 -080090} // namespace y2019