blob: 47ace6e23d58bd9236c253ab9584feed44779489 [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"
James Kuszmaulec635d22023-08-12 18:39:24 -07005#include "frc971/zeroing/pulse_index.h"
Adam Snaider3f5c1e92017-03-24 21:06:03 -07006#include "y2017/constants.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07007#include "y2017/control_loops/superstructure/superstructure_goal_generated.h"
Austin Schuh87c10632017-02-05 19:02:17 -08008
9namespace y2017 {
10namespace control_loops {
11namespace superstructure {
12namespace hood {
13
Austin Schuh6a90cd92017-02-19 20:55:33 -080014// Profiled subsystem class with significantly relaxed limits while zeroing. We
15// need relaxed limits, because if you start at the top of the range, you need
16// to go to -range, and if you start at the bottom of the range, you need to go
17// to +range. The standard subsystem doesn't support that.
18class IndexPulseProfiledSubsystem
19 : public ::frc971::control_loops::SingleDOFProfiledSubsystem<
20 ::frc971::zeroing::PulseIndexZeroingEstimator> {
21 public:
22 IndexPulseProfiledSubsystem();
23
24 private:
Sabina Davis0e484f92020-02-23 17:47:53 -080025 void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal,
26 bool print) override;
Austin Schuh6a90cd92017-02-19 20:55:33 -080027};
28
Austin Schuh87c10632017-02-05 19:02:17 -080029class Hood {
30 public:
Austin Schuh6a90cd92017-02-19 20:55:33 -080031 Hood();
32 double goal(int row, int col) const {
33 return profiled_subsystem_.goal(row, col);
34 }
Austin Schuh87c10632017-02-05 19:02:17 -080035
Austin Schuh6a90cd92017-02-19 20:55:33 -080036 // The zeroing and operating voltages.
Austin Schuh410e3812017-02-21 16:44:03 -080037 static constexpr double kZeroingVoltage = 2.0;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070038 static constexpr double kOperatingVoltage = 12.0;
39
40 // Constants needed when determining if the hood is in danger of breaking its
41 // own gears at the normal operating voltage.
42 static constexpr double kErrorOnPositionTillNotMoving =
43 2.5 * (::y2017::constants::Values::kHoodEncoderIndexDifference /
44 ::y2017::constants::Values::kHoodEncoderCountsPerRevolution);
45
46 static constexpr ::aos::monotonic_clock::duration kTimeTillNotMoving =
47 ::std::chrono::milliseconds(15);
48 static constexpr double kNotMovingVoltage = 2.0;
Austin Schuh87c10632017-02-05 19:02:17 -080049
Alex Perrycb7da4b2019-08-28 19:35:56 -070050 flatbuffers::Offset<frc971::control_loops::IndexProfiledJointStatus> Iterate(
51 ::aos::monotonic_clock::time_point monotonic_now,
52 const double *unsafe_goal,
53 const frc971::ProfileParameters *unsafe_goal_profile_parameters,
54 const ::frc971::IndexPosition *position, double *output,
55 flatbuffers::FlatBufferBuilder *fbb);
Austin Schuh87c10632017-02-05 19:02:17 -080056
Austin Schuh6a90cd92017-02-19 20:55:33 -080057 void Reset();
Austin Schuh87c10632017-02-05 19:02:17 -080058
Austin Schuh6a90cd92017-02-19 20:55:33 -080059 enum class State : int32_t {
60 UNINITIALIZED,
61 DISABLED_INITIALIZED,
62 ZEROING,
63 RUNNING,
64 ESTOP,
65 };
Austin Schuh87c10632017-02-05 19:02:17 -080066
Austin Schuh6a90cd92017-02-19 20:55:33 -080067 State state() const { return state_; }
Austin Schuh87c10632017-02-05 19:02:17 -080068
Austin Schuh6a90cd92017-02-19 20:55:33 -080069 private:
70 State state_;
Austin Schuh87c10632017-02-05 19:02:17 -080071
Austin Schuh6a90cd92017-02-19 20:55:33 -080072 IndexPulseProfiledSubsystem profiled_subsystem_;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070073 double last_position_ = 0;
74 ::aos::monotonic_clock::time_point last_move_time_ =
75 ::aos::monotonic_clock::min_time;
Austin Schuh87c10632017-02-05 19:02:17 -080076};
77
78} // namespace hood
79} // namespace superstructure
80} // namespace control_loops
81} // namespace y2017
82
83#endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_