blob: 3cad298fcbea1c2b073cc6c2738b10738b0e5637 [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
14Superstructure::Superstructure(
15 control_loops::SuperstructureQueue *superstructure_queue)
16 : aos::controls::ControlLoop<control_loops::SuperstructureQueue>(
17 superstructure_queue) {}
18
19void Superstructure::RunIteration(
20 const control_loops::SuperstructureQueue::Goal *unsafe_goal,
21 const control_loops::SuperstructureQueue::Position *position,
22 control_loops::SuperstructureQueue::Output *output,
23 control_loops::SuperstructureQueue::Status *status) {
24 if (WasReset()) {
25 LOG(ERROR, "WPILib reset, restarting\n");
26 hood_.Reset();
Adam Snaider79900c22017-02-08 20:23:15 -080027 turret_.Reset();
28 intake_.Reset();
Tyler Chatow2737d2a2017-02-08 21:20:51 -080029 shooter_.Reset();
Austin Schuhcd3237a2017-02-18 14:19:26 -080030 indexer_.Reset();
Austin Schuh87c10632017-02-05 19:02:17 -080031 }
32
33 hood_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->hood) : nullptr,
34 &(position->hood),
35 output != nullptr ? &(output->voltage_hood) : nullptr,
36 &(status->hood));
Adam Snaider79900c22017-02-08 20:23:15 -080037 turret_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->turret) : nullptr,
38 &(position->turret),
39 output != nullptr ? &(output->voltage_turret) : nullptr,
40 &(status->turret));
41
42 intake_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->intake) : nullptr,
43 &(position->intake),
44 output != nullptr ? &(output->voltage_intake) : nullptr,
45 &(status->intake));
Tyler Chatow2737d2a2017-02-08 21:20:51 -080046 shooter_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->shooter) : nullptr,
47 &(position->theta_shooter),
48 output != nullptr ? &(output->voltage_shooter) : nullptr,
49 &(status->shooter));
Austin Schuhcd3237a2017-02-18 14:19:26 -080050 indexer_.Iterate(unsafe_goal != nullptr ? &(unsafe_goal->indexer) : nullptr,
51 &(position->theta_indexer),
52 output != nullptr ? &(output->voltage_indexer) : nullptr,
53 &(status->indexer));
Austin Schuh87c10632017-02-05 19:02:17 -080054}
55
56} // namespace superstructure
57} // namespace control_loops
58} // namespace y2017