blob: 8284e6e73adbcaad704f9b1af26ca012db222b4c [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:
Sabina Davis0e484f92020-02-23 17:47:53 -080024 void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal,
25 bool print) override;
Austin Schuh6a90cd92017-02-19 20:55:33 -080026};
27
Austin Schuh87c10632017-02-05 19:02:17 -080028class Hood {
29 public:
Austin Schuh6a90cd92017-02-19 20:55:33 -080030 Hood();
31 double goal(int row, int col) const {
32 return profiled_subsystem_.goal(row, col);
33 }
Austin Schuh87c10632017-02-05 19:02:17 -080034
Austin Schuh6a90cd92017-02-19 20:55:33 -080035 // The zeroing and operating voltages.
Austin Schuh410e3812017-02-21 16:44:03 -080036 static constexpr double kZeroingVoltage = 2.0;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070037 static constexpr double kOperatingVoltage = 12.0;
38
39 // Constants needed when determining if the hood is in danger of breaking its
40 // own gears at the normal operating voltage.
41 static constexpr double kErrorOnPositionTillNotMoving =
42 2.5 * (::y2017::constants::Values::kHoodEncoderIndexDifference /
43 ::y2017::constants::Values::kHoodEncoderCountsPerRevolution);
44
45 static constexpr ::aos::monotonic_clock::duration kTimeTillNotMoving =
46 ::std::chrono::milliseconds(15);
47 static constexpr double kNotMovingVoltage = 2.0;
Austin Schuh87c10632017-02-05 19:02:17 -080048
Alex Perrycb7da4b2019-08-28 19:35:56 -070049 flatbuffers::Offset<frc971::control_loops::IndexProfiledJointStatus> Iterate(
50 ::aos::monotonic_clock::time_point monotonic_now,
51 const double *unsafe_goal,
52 const frc971::ProfileParameters *unsafe_goal_profile_parameters,
53 const ::frc971::IndexPosition *position, double *output,
54 flatbuffers::FlatBufferBuilder *fbb);
Austin Schuh87c10632017-02-05 19:02:17 -080055
Austin Schuh6a90cd92017-02-19 20:55:33 -080056 void Reset();
Austin Schuh87c10632017-02-05 19:02:17 -080057
Austin Schuh6a90cd92017-02-19 20:55:33 -080058 enum class State : int32_t {
59 UNINITIALIZED,
60 DISABLED_INITIALIZED,
61 ZEROING,
62 RUNNING,
63 ESTOP,
64 };
Austin Schuh87c10632017-02-05 19:02:17 -080065
Austin Schuh6a90cd92017-02-19 20:55:33 -080066 State state() const { return state_; }
Austin Schuh87c10632017-02-05 19:02:17 -080067
Austin Schuh6a90cd92017-02-19 20:55:33 -080068 private:
69 State state_;
Austin Schuh87c10632017-02-05 19:02:17 -080070
Austin Schuh6a90cd92017-02-19 20:55:33 -080071 IndexPulseProfiledSubsystem profiled_subsystem_;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070072 double last_position_ = 0;
73 ::aos::monotonic_clock::time_point last_move_time_ =
74 ::aos::monotonic_clock::min_time;
Austin Schuh87c10632017-02-05 19:02:17 -080075};
76
77} // namespace hood
78} // namespace superstructure
79} // namespace control_loops
80} // namespace y2017
81
82#endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_