blob: 77781527b906667515935c7d8b0cbe6b5372e5d2 [file] [log] [blame]
Austin Schuh87c10632017-02-05 19:02:17 -08001#ifndef Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_
2#define Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_
3
4#include "frc971/control_loops/profiled_subsystem.h"
Adam Snaider3f5c1e92017-03-24 21:06:03 -07005#include "y2017/constants.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07006#include "y2017/control_loops/superstructure/superstructure_goal_generated.h"
Austin Schuh87c10632017-02-05 19:02:17 -08007
8namespace y2017 {
9namespace control_loops {
10namespace superstructure {
11namespace hood {
12
Austin Schuh6a90cd92017-02-19 20:55:33 -080013// Profiled subsystem class with significantly relaxed limits while zeroing. We
14// need relaxed limits, because if you start at the top of the range, you need
15// to go to -range, and if you start at the bottom of the range, you need to go
16// to +range. The standard subsystem doesn't support that.
17class IndexPulseProfiledSubsystem
18 : public ::frc971::control_loops::SingleDOFProfiledSubsystem<
19 ::frc971::zeroing::PulseIndexZeroingEstimator> {
20 public:
21 IndexPulseProfiledSubsystem();
22
23 private:
24 void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal) override;
25};
26
Austin Schuh87c10632017-02-05 19:02:17 -080027class Hood {
28 public:
Austin Schuh6a90cd92017-02-19 20:55:33 -080029 Hood();
30 double goal(int row, int col) const {
31 return profiled_subsystem_.goal(row, col);
32 }
Austin Schuh87c10632017-02-05 19:02:17 -080033
Austin Schuh6a90cd92017-02-19 20:55:33 -080034 // The zeroing and operating voltages.
Austin Schuh410e3812017-02-21 16:44:03 -080035 static constexpr double kZeroingVoltage = 2.0;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070036 static constexpr double kOperatingVoltage = 12.0;
37
38 // Constants needed when determining if the hood is in danger of breaking its
39 // own gears at the normal operating voltage.
40 static constexpr double kErrorOnPositionTillNotMoving =
41 2.5 * (::y2017::constants::Values::kHoodEncoderIndexDifference /
42 ::y2017::constants::Values::kHoodEncoderCountsPerRevolution);
43
44 static constexpr ::aos::monotonic_clock::duration kTimeTillNotMoving =
45 ::std::chrono::milliseconds(15);
46 static constexpr double kNotMovingVoltage = 2.0;
Austin Schuh87c10632017-02-05 19:02:17 -080047
Alex Perrycb7da4b2019-08-28 19:35:56 -070048 flatbuffers::Offset<frc971::control_loops::IndexProfiledJointStatus> Iterate(
49 ::aos::monotonic_clock::time_point monotonic_now,
50 const double *unsafe_goal,
51 const frc971::ProfileParameters *unsafe_goal_profile_parameters,
52 const ::frc971::IndexPosition *position, double *output,
53 flatbuffers::FlatBufferBuilder *fbb);
Austin Schuh87c10632017-02-05 19:02:17 -080054
Austin Schuh6a90cd92017-02-19 20:55:33 -080055 void Reset();
Austin Schuh87c10632017-02-05 19:02:17 -080056
Austin Schuh6a90cd92017-02-19 20:55:33 -080057 enum class State : int32_t {
58 UNINITIALIZED,
59 DISABLED_INITIALIZED,
60 ZEROING,
61 RUNNING,
62 ESTOP,
63 };
Austin Schuh87c10632017-02-05 19:02:17 -080064
Austin Schuh6a90cd92017-02-19 20:55:33 -080065 State state() const { return state_; }
Austin Schuh87c10632017-02-05 19:02:17 -080066
Austin Schuh6a90cd92017-02-19 20:55:33 -080067 private:
68 State state_;
Austin Schuh87c10632017-02-05 19:02:17 -080069
Austin Schuh6a90cd92017-02-19 20:55:33 -080070 IndexPulseProfiledSubsystem profiled_subsystem_;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070071 double last_position_ = 0;
72 ::aos::monotonic_clock::time_point last_move_time_ =
73 ::aos::monotonic_clock::min_time;
Austin Schuh87c10632017-02-05 19:02:17 -080074};
75
76} // namespace hood
77} // namespace superstructure
78} // namespace control_loops
79} // namespace y2017
80
81#endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_