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 | |
| 21 | // The operating voltage. |
| 22 | static constexpr double kOperatingVoltage() { return 12.0; } |
| 23 | static constexpr double kDt() { return 0.00505; } |
| 24 | static constexpr double kAlpha0Max() { return 25.0; } |
| 25 | static constexpr double kAlpha1Max() { return 25.0; } |
| 26 | static constexpr double kVMax() { return 11.0; } |
| 27 | static constexpr double kPathlessVMax() { return 4.0; } |
| 28 | |
| 29 | void Iterate(const uint32_t *unsafe_goal, |
| 30 | const control_loops::ArmPosition *position, |
| 31 | double *proximal_output, double *distal_output, |
| 32 | bool *release_arm_brake, |
| 33 | control_loops::ArmStatus *status); |
| 34 | |
| 35 | void Reset(); |
| 36 | |
| 37 | enum class State : int32_t { |
| 38 | UNINITIALIZED, |
| 39 | ZEROING, |
| 40 | RUNNING, |
| 41 | ESTOP, |
| 42 | }; |
| 43 | |
| 44 | State state() const { return state_; } |
| 45 | |
| 46 | private: |
| 47 | State state_ = State::UNINITIALIZED; |
| 48 | |
| 49 | ::aos::monotonic_clock::time_point last_time_ = |
| 50 | ::aos::monotonic_clock::min_time; |
| 51 | |
| 52 | ::frc971::zeroing::PotAndAbsEncoderZeroingEstimator proximal_zeroing_estimator_; |
| 53 | ::frc971::zeroing::PotAndAbsEncoderZeroingEstimator distal_zeroing_estimator_; |
| 54 | |
| 55 | double proximal_offset_ = 0.0; |
| 56 | double distal_offset_ = 0.0; |
| 57 | |
| 58 | const ::Eigen::Matrix<double, 2, 2> alpha_unitizer_; |
| 59 | |
Austin Schuh | 7dfccf6 | 2018-03-03 21:28:14 -0800 | [diff] [blame] | 60 | ::std::vector<Trajectory> trajectories_; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 61 | SearchGraph search_graph_; |
| 62 | |
| 63 | bool close_enough_for_full_power_ = false; |
| 64 | |
| 65 | EKF arm_ekf_; |
| 66 | TrajectoryFollower follower_; |
| 67 | |
| 68 | // Start at the 0th index. |
| 69 | uint32_t current_node_ = 0; |
| 70 | |
| 71 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW; |
| 72 | }; |
| 73 | |
| 74 | } // namespace arm |
| 75 | } // namespace superstructure |
| 76 | } // namespace control_loops |
| 77 | } // namespace y2018 |
| 78 | |
| 79 | #endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_ARM_ARM_H_ |