blob: 14beff56566ea9d6129bca4f2730e72b882bcd1b [file] [log] [blame]
Austin Schuh87c10632017-02-05 19:02:17 -08001#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 Snaider79900c22017-02-08 20:23:15 -08007#include "y2017/control_loops/superstructure/turret/turret.h"
8#include "y2017/control_loops/superstructure/intake/intake.h"
Austin Schuh87c10632017-02-05 19:02:17 -08009
10namespace y2017 {
11namespace control_loops {
12namespace superstructure {
13
Campbell Crowley651c4b42017-02-17 22:30:50 -080014namespace {
15// The maximum voltage the intake roller will be allowed to use.
16constexpr double kMaxIntakeRollerVoltage = 12.0;
17constexpr double kMaxIndexerRollerVoltage = 12.0;
18} // namespace
19
Austin Schuh87c10632017-02-05 19:02:17 -080020Superstructure::Superstructure(
21 control_loops::SuperstructureQueue *superstructure_queue)
22 : aos::controls::ControlLoop<control_loops::SuperstructureQueue>(
23 superstructure_queue) {}
24
25void 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 Snaider79900c22017-02-08 20:23:15 -080033 turret_.Reset();
34 intake_.Reset();
Tyler Chatow2737d2a2017-02-08 21:20:51 -080035 shooter_.Reset();
Austin Schuhcd3237a2017-02-18 14:19:26 -080036 indexer_.Reset();
Austin Schuh87c10632017-02-05 19:02:17 -080037 }
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 Snaider79900c22017-02-08 20:23:15 -080043 turret_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->turret) : nullptr,
Campbell Crowley651c4b42017-02-17 22:30:50 -080044 &(position->turret),
45 output != nullptr ? &(output->voltage_turret) : nullptr,
46 &(status->turret));
Adam Snaider79900c22017-02-08 20:23:15 -080047 intake_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr,
48 &(position->intake),
49 output != nullptr ? &(output->voltage_intake) : nullptr,
50 &(status->intake));
Tyler Chatow2737d2a2017-02-08 21:20:51 -080051 shooter_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->shooter) : nullptr,
Austin Schuh932a5ce2017-03-05 01:04:18 -080052 &(position->theta_shooter), position->sent_time,
Campbell Crowley651c4b42017-02-17 22:30:50 -080053 output != nullptr ? &(output->voltage_shooter) : nullptr,
54 &(status->shooter));
Austin Schuhcd3237a2017-02-18 14:19:26 -080055 indexer_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->indexer) : nullptr,
Austin Schuh55934032017-03-11 12:45:27 -080056 &(position->theta_indexer),
57 output != nullptr ? &(output->voltage_indexer) : nullptr,
58 &(status->indexer));
Campbell Crowley651c4b42017-02-17 22:30:50 -080059
60 if (output && unsafe_goal) {
61 output->voltage_intake_rollers =
62 ::std::max(-kMaxIntakeRollerVoltage,
63 ::std::min(unsafe_goal->intake.voltage_rollers,
64 kMaxIntakeRollerVoltage));
65 output->voltage_indexer_rollers =
66 ::std::max(-kMaxIndexerRollerVoltage,
67 ::std::min(unsafe_goal->indexer.voltage_rollers,
68 kMaxIndexerRollerVoltage));
69 }
Austin Schuh87c10632017-02-05 19:02:17 -080070}
71
72} // namespace superstructure
73} // namespace control_loops
74} // namespace y2017