Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 1 | #ifndef Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_ARM_H_ |
| 2 | #define Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_ARM_H_ |
| 3 | |
| 4 | #include "frc971/zeroing/zeroing.h" |
| 5 | #include "y2018/constants.h" |
| 6 | #include "y2018/control_loops/superstructure/arm/dynamics.h" |
| 7 | #include "y2018/control_loops/superstructure/arm/ekf.h" |
| 8 | #include "y2018/control_loops/superstructure/arm/graph.h" |
| 9 | #include "y2018/control_loops/superstructure/arm/trajectory.h" |
| 10 | #include "y2018/control_loops/superstructure/superstructure.q.h" |
| 11 | |
| 12 | namespace y2018 { |
| 13 | namespace control_loops { |
| 14 | namespace superstructure { |
| 15 | namespace arm { |
| 16 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 17 | class Arm { |
| 18 | public: |
| 19 | Arm(); |
| 20 | |
Austin Schuh | 7a09040 | 2018-03-04 01:16:45 -0800 | [diff] [blame] | 21 | // If true, tune down all the constants for testing. |
| 22 | static constexpr bool kGrannyMode() { return true; } |
| 23 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 24 | // The operating voltage. |
Austin Schuh | 7a09040 | 2018-03-04 01:16:45 -0800 | [diff] [blame] | 25 | static constexpr double kOperatingVoltage() { |
| 26 | return kGrannyMode() ? 6.0 : 12.0; |
| 27 | } |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 28 | static constexpr double kDt() { return 0.00505; } |
Austin Schuh | 7a09040 | 2018-03-04 01:16:45 -0800 | [diff] [blame] | 29 | static constexpr double kAlpha0Max() { return kGrannyMode() ? 10.0 : 25.0; } |
| 30 | static constexpr double kAlpha1Max() { return kGrannyMode() ? 10.0 : 25.0; } |
| 31 | static constexpr double kVMax() { return kGrannyMode() ? 4.0 : 11.5; } |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 32 | static constexpr double kPathlessVMax() { return 4.0; } |
| 33 | |
| 34 | void Iterate(const uint32_t *unsafe_goal, |
| 35 | const control_loops::ArmPosition *position, |
| 36 | double *proximal_output, double *distal_output, |
Austin Schuh | 7a09040 | 2018-03-04 01:16:45 -0800 | [diff] [blame] | 37 | bool *release_arm_brake, control_loops::ArmStatus *status); |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 38 | |
| 39 | void Reset(); |
| 40 | |
| 41 | enum class State : int32_t { |
| 42 | UNINITIALIZED, |
| 43 | ZEROING, |
| 44 | RUNNING, |
| 45 | ESTOP, |
| 46 | }; |
| 47 | |
| 48 | State state() const { return state_; } |
| 49 | |
| 50 | private: |
| 51 | State state_ = State::UNINITIALIZED; |
| 52 | |
| 53 | ::aos::monotonic_clock::time_point last_time_ = |
| 54 | ::aos::monotonic_clock::min_time; |
| 55 | |
| 56 | ::frc971::zeroing::PotAndAbsEncoderZeroingEstimator proximal_zeroing_estimator_; |
| 57 | ::frc971::zeroing::PotAndAbsEncoderZeroingEstimator distal_zeroing_estimator_; |
| 58 | |
| 59 | double proximal_offset_ = 0.0; |
| 60 | double distal_offset_ = 0.0; |
| 61 | |
| 62 | const ::Eigen::Matrix<double, 2, 2> alpha_unitizer_; |
| 63 | |
Austin Schuh | 7dfccf6 | 2018-03-03 21:28:14 -0800 | [diff] [blame] | 64 | ::std::vector<Trajectory> trajectories_; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 65 | SearchGraph search_graph_; |
| 66 | |
| 67 | bool close_enough_for_full_power_ = false; |
| 68 | |
| 69 | EKF arm_ekf_; |
| 70 | TrajectoryFollower follower_; |
| 71 | |
| 72 | // Start at the 0th index. |
| 73 | uint32_t current_node_ = 0; |
| 74 | |
| 75 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 76 | }; |
| 77 | |
| 78 | } // namespace arm |
| 79 | } // namespace superstructure |
| 80 | } // namespace control_loops |
| 81 | } // namespace y2018 |
| 82 | |
| 83 | #endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_ARM_H_ |