Tyler Chatow | e51334a | 2019-01-20 16:58:16 -0800 | [diff] [blame] | 1 | #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 Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 5 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
Tyler Chatow | e51334a | 2019-01-20 16:58:16 -0800 | [diff] [blame] | 6 | |
| 7 | namespace y2019 { |
| 8 | namespace control_loops { |
| 9 | namespace superstructure { |
| 10 | |
John Park | bdc8612 | 2019-02-10 12:35:25 -0800 | [diff] [blame^] | 11 | void 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 Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 23 | Superstructure::Superstructure(::aos::EventLoop *event_loop, |
| 24 | const ::std::string &name) |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 25 | : 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 Chatow | e51334a | 2019-01-20 16:58:16 -0800 | [diff] [blame] | 30 | |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 31 | void Superstructure::RunIteration(const SuperstructureQueue::Goal *unsafe_goal, |
| 32 | const SuperstructureQueue::Position *position, |
| 33 | SuperstructureQueue::Output *output, |
| 34 | SuperstructureQueue::Status *status) { |
Tyler Chatow | e51334a | 2019-01-20 16:58:16 -0800 | [diff] [blame] | 35 | if (WasReset()) { |
| 36 | LOG(ERROR, "WPILib reset, restarting\n"); |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 37 | elevator_.Reset(); |
| 38 | wrist_.Reset(); |
| 39 | intake_.Reset(); |
| 40 | stilts_.Reset(); |
Tyler Chatow | e51334a | 2019-01-20 16:58:16 -0800 | [diff] [blame] | 41 | } |
Theo Bafrali | 00e4227 | 2019-02-12 01:07:46 -0800 | [diff] [blame] | 42 | |
| 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 Chatow | e51334a | 2019-01-20 16:58:16 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } // namespace superstructure |
| 82 | } // namespace control_loops |
Austin Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 83 | } // namespace y2019 |