blob: 9f6f120e49cd11f2a0ffff31fbd8053c4123a8ca [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
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -08009namespace y2017::control_loops::superstructure::hood {
Austin Schuh87c10632017-02-05 19:02:17 -080010
Austin Schuh6a90cd92017-02-19 20:55:33 -080011// Profiled subsystem class with significantly relaxed limits while zeroing. We
12// need relaxed limits, because if you start at the top of the range, you need
13// to go to -range, and if you start at the bottom of the range, you need to go
14// to +range. The standard subsystem doesn't support that.
15class IndexPulseProfiledSubsystem
16 : public ::frc971::control_loops::SingleDOFProfiledSubsystem<
17 ::frc971::zeroing::PulseIndexZeroingEstimator> {
18 public:
19 IndexPulseProfiledSubsystem();
20
21 private:
Sabina Davis0e484f92020-02-23 17:47:53 -080022 void CapGoal(const char *name, Eigen::Matrix<double, 3, 1> *goal,
23 bool print) override;
Austin Schuh6a90cd92017-02-19 20:55:33 -080024};
25
Austin Schuh87c10632017-02-05 19:02:17 -080026class Hood {
27 public:
Austin Schuh6a90cd92017-02-19 20:55:33 -080028 Hood();
29 double goal(int row, int col) const {
30 return profiled_subsystem_.goal(row, col);
31 }
Austin Schuh87c10632017-02-05 19:02:17 -080032
Austin Schuh6a90cd92017-02-19 20:55:33 -080033 // The zeroing and operating voltages.
Austin Schuh410e3812017-02-21 16:44:03 -080034 static constexpr double kZeroingVoltage = 2.0;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070035 static constexpr double kOperatingVoltage = 12.0;
36
37 // Constants needed when determining if the hood is in danger of breaking its
38 // own gears at the normal operating voltage.
39 static constexpr double kErrorOnPositionTillNotMoving =
40 2.5 * (::y2017::constants::Values::kHoodEncoderIndexDifference /
41 ::y2017::constants::Values::kHoodEncoderCountsPerRevolution);
42
43 static constexpr ::aos::monotonic_clock::duration kTimeTillNotMoving =
44 ::std::chrono::milliseconds(15);
45 static constexpr double kNotMovingVoltage = 2.0;
Austin Schuh87c10632017-02-05 19:02:17 -080046
Alex Perrycb7da4b2019-08-28 19:35:56 -070047 flatbuffers::Offset<frc971::control_loops::IndexProfiledJointStatus> Iterate(
48 ::aos::monotonic_clock::time_point monotonic_now,
49 const double *unsafe_goal,
50 const frc971::ProfileParameters *unsafe_goal_profile_parameters,
51 const ::frc971::IndexPosition *position, double *output,
52 flatbuffers::FlatBufferBuilder *fbb);
Austin Schuh87c10632017-02-05 19:02:17 -080053
Austin Schuh6a90cd92017-02-19 20:55:33 -080054 void Reset();
Austin Schuh87c10632017-02-05 19:02:17 -080055
Austin Schuh6a90cd92017-02-19 20:55:33 -080056 enum class State : int32_t {
57 UNINITIALIZED,
58 DISABLED_INITIALIZED,
59 ZEROING,
60 RUNNING,
61 ESTOP,
62 };
Austin Schuh87c10632017-02-05 19:02:17 -080063
Austin Schuh6a90cd92017-02-19 20:55:33 -080064 State state() const { return state_; }
Austin Schuh87c10632017-02-05 19:02:17 -080065
Austin Schuh6a90cd92017-02-19 20:55:33 -080066 private:
67 State state_;
Austin Schuh87c10632017-02-05 19:02:17 -080068
Austin Schuh6a90cd92017-02-19 20:55:33 -080069 IndexPulseProfiledSubsystem profiled_subsystem_;
Adam Snaider3f5c1e92017-03-24 21:06:03 -070070 double last_position_ = 0;
71 ::aos::monotonic_clock::time_point last_move_time_ =
72 ::aos::monotonic_clock::min_time;
Austin Schuh87c10632017-02-05 19:02:17 -080073};
74
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080075} // namespace y2017::control_loops::superstructure::hood
Austin Schuh87c10632017-02-05 19:02:17 -080076
77#endif // Y2017_CONTROL_LOOPS_SUPERSTRUCTURE_HOOD_HOOD_H_