Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 1 | #include "y2018/control_loops/superstructure/superstructure.h" |
| 2 | |
| 3 | #include "aos/common/controls/control_loops.q.h" |
| 4 | #include "aos/common/logging/logging.h" |
| 5 | #include "frc971/control_loops/control_loops.q.h" |
| 6 | #include "y2018/constants.h" |
| 7 | #include "y2018/control_loops/superstructure/intake/intake.h" |
| 8 | |
| 9 | namespace y2018 { |
| 10 | namespace control_loops { |
| 11 | namespace superstructure { |
| 12 | |
| 13 | namespace { |
| 14 | // The maximum voltage the intake roller will be allowed to use. |
| 15 | constexpr double kMaxIntakeRollerVoltage = 12.0; |
| 16 | } // namespace |
| 17 | |
| 18 | Superstructure::Superstructure( |
| 19 | control_loops::SuperstructureQueue *superstructure_queue) |
| 20 | : aos::controls::ControlLoop<control_loops::SuperstructureQueue>( |
| 21 | superstructure_queue), |
| 22 | intake_left_(constants::GetValues().left_intake.zeroing), |
| 23 | intake_right_(constants::GetValues().right_intake.zeroing) {} |
| 24 | |
| 25 | void Superstructure::RunIteration( |
| 26 | const control_loops::SuperstructureQueue::Goal *unsafe_goal, |
| 27 | const control_loops::SuperstructureQueue::Position *position, |
| 28 | control_loops::SuperstructureQueue::Output *output, |
| 29 | control_loops::SuperstructureQueue::Status *status) { |
| 30 | if (WasReset()) { |
| 31 | LOG(ERROR, "WPILib reset, restarting\n"); |
| 32 | intake_left_.Reset(); |
| 33 | intake_right_.Reset(); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame^] | 34 | arm_.Reset(); |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | intake_left_.Iterate(unsafe_goal != nullptr |
| 38 | ? &(unsafe_goal->intake.left_intake_angle) |
| 39 | : nullptr, |
| 40 | &(position->intake.left), |
| 41 | output != nullptr ? &(output->intake.left) : nullptr, |
| 42 | &(status->left_intake)); |
| 43 | |
| 44 | intake_right_.Iterate(unsafe_goal != nullptr |
| 45 | ? &(unsafe_goal->intake.right_intake_angle) |
| 46 | : nullptr, |
| 47 | &(position->intake.right), |
| 48 | output != nullptr ? &(output->intake.right) : nullptr, |
| 49 | &(status->right_intake)); |
| 50 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame^] | 51 | intake_right_.Iterate(unsafe_goal != nullptr |
| 52 | ? &(unsafe_goal->intake.right_intake_angle) |
| 53 | : nullptr, |
| 54 | &(position->intake.right), |
| 55 | output != nullptr ? &(output->intake.right) : nullptr, |
| 56 | &(status->left_intake)); |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 57 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame^] | 58 | arm_.Iterate( |
| 59 | unsafe_goal != nullptr ? &(unsafe_goal->arm_goal_position) : nullptr, |
| 60 | &(position->arm), |
| 61 | output != nullptr ? &(output->voltage_proximal) : nullptr, |
| 62 | output != nullptr ? &(output->voltage_distal) : nullptr, |
| 63 | output != nullptr ? &(output->release_arm_brake) : nullptr, |
| 64 | &(status->arm)); |
| 65 | |
| 66 | status->estopped = status->left_intake.estopped || |
| 67 | status->right_intake.estopped || status->arm.estopped; |
| 68 | |
| 69 | status->zeroed = status->left_intake.zeroed && status->right_intake.zeroed && |
| 70 | status->arm.zeroed; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 71 | |
| 72 | if (output && unsafe_goal) { |
| 73 | output->intake.left.voltage_rollers = ::std::max( |
| 74 | -kMaxIntakeRollerVoltage, ::std::min(unsafe_goal->intake.roller_voltage, |
| 75 | kMaxIntakeRollerVoltage)); |
| 76 | output->intake.right.voltage_rollers = ::std::max( |
| 77 | -kMaxIntakeRollerVoltage, ::std::min(unsafe_goal->intake.roller_voltage, |
| 78 | kMaxIntakeRollerVoltage)); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | } // namespace superstructure |
| 83 | } // namespace control_loops |
| 84 | } // namespace y2018 |