blob: 480715dafd0d2d18698ef84c2ff8854c6987489c [file] [log] [blame]
Austin Schuhcb091712018-02-21 20:01:55 -08001#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
12namespace y2018 {
13namespace control_loops {
14namespace superstructure {
15namespace arm {
16
Austin Schuhcb091712018-02-21 20:01:55 -080017class Arm {
18 public:
19 Arm();
20
Austin Schuh7a090402018-03-04 01:16:45 -080021 // If true, tune down all the constants for testing.
22 static constexpr bool kGrannyMode() { return true; }
23
Austin Schuhcb091712018-02-21 20:01:55 -080024 // The operating voltage.
Austin Schuh7a090402018-03-04 01:16:45 -080025 static constexpr double kOperatingVoltage() {
26 return kGrannyMode() ? 6.0 : 12.0;
27 }
Austin Schuhcb091712018-02-21 20:01:55 -080028 static constexpr double kDt() { return 0.00505; }
Austin Schuh7a090402018-03-04 01:16:45 -080029 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 Schuhcb091712018-02-21 20:01:55 -080032 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 Schuh7a090402018-03-04 01:16:45 -080037 bool *release_arm_brake, control_loops::ArmStatus *status);
Austin Schuhcb091712018-02-21 20:01:55 -080038
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 Schuh7dfccf62018-03-03 21:28:14 -080064 ::std::vector<Trajectory> trajectories_;
Austin Schuhcb091712018-02-21 20:01:55 -080065 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_