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