Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 1 | #include "y2017/control_loops/superstructure/superstructure.h" |
| 2 | |
| 3 | #include "aos/common/controls/control_loops.q.h" |
| 4 | #include "aos/common/logging/logging.h" |
| 5 | #include "y2017/constants.h" |
| 6 | #include "y2017/control_loops/superstructure/hood/hood.h" |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 7 | #include "y2017/control_loops/superstructure/turret/turret.h" |
| 8 | #include "y2017/control_loops/superstructure/intake/intake.h" |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 9 | |
| 10 | namespace y2017 { |
| 11 | namespace control_loops { |
| 12 | namespace superstructure { |
| 13 | |
Campbell Crowley | 651c4b4 | 2017-02-17 22:30:50 -0800 | [diff] [blame] | 14 | namespace { |
| 15 | // The maximum voltage the intake roller will be allowed to use. |
| 16 | constexpr double kMaxIntakeRollerVoltage = 12.0; |
| 17 | constexpr double kMaxIndexerRollerVoltage = 12.0; |
| 18 | } // namespace |
| 19 | |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 20 | Superstructure::Superstructure( |
| 21 | control_loops::SuperstructureQueue *superstructure_queue) |
| 22 | : aos::controls::ControlLoop<control_loops::SuperstructureQueue>( |
| 23 | superstructure_queue) {} |
| 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 | hood_.Reset(); |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 33 | turret_.Reset(); |
| 34 | intake_.Reset(); |
Tyler Chatow | 2737d2a | 2017-02-08 21:20:51 -0800 | [diff] [blame] | 35 | shooter_.Reset(); |
Austin Schuh | cd3237a | 2017-02-18 14:19:26 -0800 | [diff] [blame] | 36 | indexer_.Reset(); |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | hood_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->hood) : nullptr, |
| 40 | &(position->hood), |
| 41 | output != nullptr ? &(output->voltage_hood) : nullptr, |
| 42 | &(status->hood)); |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 43 | turret_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->turret) : nullptr, |
Campbell Crowley | 651c4b4 | 2017-02-17 22:30:50 -0800 | [diff] [blame] | 44 | &(position->turret), |
| 45 | output != nullptr ? &(output->voltage_turret) : nullptr, |
| 46 | &(status->turret)); |
Adam Snaider | 79900c2 | 2017-02-08 20:23:15 -0800 | [diff] [blame] | 47 | |
| 48 | intake_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr, |
| 49 | &(position->intake), |
| 50 | output != nullptr ? &(output->voltage_intake) : nullptr, |
| 51 | &(status->intake)); |
Tyler Chatow | 2737d2a | 2017-02-08 21:20:51 -0800 | [diff] [blame] | 52 | shooter_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->shooter) : nullptr, |
Campbell Crowley | 651c4b4 | 2017-02-17 22:30:50 -0800 | [diff] [blame] | 53 | &(position->theta_shooter), |
| 54 | output != nullptr ? &(output->voltage_shooter) : nullptr, |
| 55 | &(status->shooter)); |
Austin Schuh | cd3237a | 2017-02-18 14:19:26 -0800 | [diff] [blame] | 56 | indexer_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->indexer) : nullptr, |
| 57 | &(position->theta_indexer), |
| 58 | output != nullptr ? &(output->voltage_indexer) : nullptr, |
| 59 | &(status->indexer)); |
Campbell Crowley | 651c4b4 | 2017-02-17 22:30:50 -0800 | [diff] [blame] | 60 | |
| 61 | if (output && unsafe_goal) { |
| 62 | output->voltage_intake_rollers = |
| 63 | ::std::max(-kMaxIntakeRollerVoltage, |
| 64 | ::std::min(unsafe_goal->intake.voltage_rollers, |
| 65 | kMaxIntakeRollerVoltage)); |
| 66 | output->voltage_indexer_rollers = |
| 67 | ::std::max(-kMaxIndexerRollerVoltage, |
| 68 | ::std::min(unsafe_goal->indexer.voltage_rollers, |
| 69 | kMaxIndexerRollerVoltage)); |
| 70 | } |
Austin Schuh | 87c1063 | 2017-02-05 19:02:17 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace superstructure |
| 74 | } // namespace control_loops |
| 75 | } // namespace y2017 |