blob: c62c639ade1a20a85de626a713e93d201e502ad9 [file] [log] [blame]
Austin Schuhd78ab542013-03-01 22:22:19 -08001#ifndef FRC971_CONTROL_LOOPS_WRIST_H_
2#define FRC971_CONTROL_LOOPS_WRIST_H_
3
4#include <memory>
5#include <deque>
6
7#include "aos/common/control_loop/ControlLoop.h"
8#include "aos/common/time.h"
9#include "frc971/control_loops/state_feedback_loop.h"
10#include "frc971/control_loops/index_motor.q.h"
11#include "frc971/control_loops/index_motor_plant.h"
12
13namespace frc971 {
14namespace control_loops {
15
16class IndexMotor
17 : public aos::control_loops::ControlLoop<control_loops::IndexLoop> {
18 public:
19 explicit IndexMotor(
20 control_loops::IndexLoop *my_index = &control_loops::index);
21
22 // Converts the angle of the indexer to the angle of the disc.
23 static double ConvertIndexToDiscAngle(const double angle);
24 // Converts the angle of the indexer to the position that the center of the
25 // disc has traveled.
26 static double ConvertIndexToDiscPosition(const double angle);
27
28 // Converts the angle around the indexer to the position of the index roller.
29 static double ConvertDiscAngleToIndex(const double angle);
30 // Converts the angle around the indexer to the position of the disc in the
31 // indexer.
32 static double ConvertDiscAngleToDiscPosition(const double angle);
33
34 // Disc radius in meters.
35 const static double kDiscRadius;
36 // Roller radius in meters.
37 const static double kRollerRadius;
38
39 class Frisbee {
40 public:
41 Frisbee()
42 : bottom_posedge_time_(0, 0),
43 bottom_negedge_time_(0, 0),
44 index_start_time_(0, 0) {
45 Reset();
46 }
47
48 void Reset() {
49 bottom_posedge_time_ = ::aos::time::Time(0, 0);
50 bottom_negedge_time_ = ::aos::time::Time(0, 0);
51 index_start_time_ = ::aos::time::Time(0, 0);
52 has_been_indexed_ = false;
53 index_start_position_ = 0.0;
54 }
55
56 ::aos::time::Time bottom_posedge_time_;
57 ::aos::time::Time bottom_negedge_time_;
58 ::aos::time::Time index_start_time_;
59 bool has_been_indexed_;
60 double index_start_position_;
61 };
62
63 protected:
64 virtual void RunIteration(
65 const control_loops::IndexLoop::Goal *goal,
66 const control_loops::IndexLoop::Position *position,
67 control_loops::IndexLoop::Output *output,
68 control_loops::IndexLoop::Status *status);
69
70 private:
71 // Fetches and locally caches the latest set of constants.
72 bool FetchConstants();
73
74 // The state feedback control loop to talk to for the index.
75 ::std::unique_ptr<StateFeedbackLoop<2, 1, 1>> wrist_loop_;
76
77 // Local cache of the index geometry constants.
78 double horizontal_lower_limit_;
79 double horizontal_upper_limit_;
80 double horizontal_hall_effect_start_angle_;
81 double horizontal_zeroing_speed_;
82
83 // Count of the number of discs that we have collected.
84 uint32_t hopper_disc_count_;
85 uint32_t total_disc_count_;
86
87 enum Goal {
88 // Hold position, in a low power state.
89 HOLD = 0,
90 // Get ready to load discs by shifting the discs down.
91 READY_LOWER = 1,
92 // Ready the discs, spin up the transfer roller, and accept discs.
93 INTAKE = 2,
94 // Get ready to shoot, and place a disc in the loader.
95 READY_SHOOTER = 3,
96 // Shoot at will.
97 SHOOT = 4
98 };
99
100 // The current goal
101 Goal safe_goal_;
102
103 // Current state of the pistons.
104 bool loader_up_;
105 bool disc_clamped_;
106 bool disc_ejected_;
107
108 //::aos::time::Time disc_bottom_posedge_time_;
109 //::aos::time::Time disc_bottom_negedge_time_;
110 // The frisbee that is flying through the transfer rollers.
111 Frisbee transfer_frisbee_;
112
113 bool last_bottom_disc_detect_;
114
115 // Frisbees are in order such that the newest frisbee is on the front.
116 ::std::deque<Frisbee> frisbees_;
117 // std::array ?
118
119 DISALLOW_COPY_AND_ASSIGN(IndexMotor);
120};
121
122} // namespace control_loops
123} // namespace frc971
124
125#endif // FRC971_CONTROL_LOOPS_WRIST_H_