Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #include "y2023/control_loops/drivetrain/drivetrain_base.h" |
| 2 | |
| 3 | #include <chrono> |
| 4 | |
| 5 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
| 6 | #include "frc971/control_loops/state_feedback_loop.h" |
| 7 | #include "y2023/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
| 8 | #include "y2023/control_loops/drivetrain/hybrid_velocity_drivetrain.h" |
| 9 | #include "y2023/control_loops/drivetrain/kalman_drivetrain_motor_plant.h" |
| 10 | #include "y2023/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h" |
| 11 | |
James Kuszmaul | 6802533 | 2024-01-20 17:06:02 -0800 | [diff] [blame] | 12 | using ::frc971::control_loops::drivetrain::DownEstimatorConfigT; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 13 | using ::frc971::control_loops::drivetrain::DrivetrainConfig; |
James Kuszmaul | c29f457 | 2023-02-25 17:02:33 -0800 | [diff] [blame] | 14 | using ::frc971::control_loops::drivetrain::LineFollowConfig; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 15 | |
| 16 | namespace chrono = ::std::chrono; |
| 17 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 18 | namespace y2023::control_loops::drivetrain { |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 19 | |
| 20 | using ::frc971::constants::ShifterHallEffect; |
| 21 | |
| 22 | const ShifterHallEffect kThreeStateDriveShifter{0.0, 0.0, 0.25, 0.75}; |
| 23 | |
| 24 | const DrivetrainConfig<double> &GetDrivetrainConfig() { |
| 25 | // Yaw of the IMU relative to the robot frame. |
| 26 | static constexpr double kImuYaw = 0.0; |
| 27 | static DrivetrainConfig<double> kDrivetrainConfig{ |
James Kuszmaul | 6802533 | 2024-01-20 17:06:02 -0800 | [diff] [blame] | 28 | ::frc971::control_loops::drivetrain::ShifterType::kSimpleShifter, |
| 29 | ::frc971::control_loops::drivetrain::LoopType::kClosedLoop, |
| 30 | ::frc971::control_loops::drivetrain::GyroType::kSpartanGyro, |
| 31 | ::frc971::control_loops::drivetrain::ImuType::kImuFlippedX, |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 32 | |
| 33 | drivetrain::MakeDrivetrainLoop, |
| 34 | drivetrain::MakeVelocityDrivetrainLoop, |
| 35 | drivetrain::MakeKFDrivetrainLoop, |
| 36 | drivetrain::MakeHybridVelocityDrivetrainLoop, |
| 37 | |
| 38 | chrono::duration_cast<chrono::nanoseconds>( |
| 39 | chrono::duration<double>(drivetrain::kDt)), |
| 40 | drivetrain::kRobotRadius, |
| 41 | drivetrain::kWheelRadius, |
| 42 | drivetrain::kV, |
| 43 | |
| 44 | drivetrain::kHighGearRatio, |
| 45 | drivetrain::kLowGearRatio, |
| 46 | drivetrain::kJ, |
| 47 | drivetrain::kMass, |
| 48 | kThreeStateDriveShifter, |
| 49 | kThreeStateDriveShifter, |
| 50 | true /* default_high_gear */, |
| 51 | 0 /* down_offset if using constants use |
| 52 | constants::GetValues().down_error */ |
| 53 | , |
| 54 | 0.7 /* wheel_non_linearity */, |
| 55 | 1.2 /* quickturn_wheel_multiplier */, |
| 56 | 1.2 /* wheel_multiplier */, |
| 57 | true /*pistol_grip_shift_enables_line_follow*/, |
| 58 | (Eigen::Matrix<double, 3, 3>() << std::cos(kImuYaw), -std::sin(kImuYaw), |
| 59 | 0.0, std::sin(kImuYaw), std::cos(kImuYaw), 0.0, 0.0, 0.0, 1.0) |
| 60 | .finished(), |
| 61 | false /*is_simulated*/, |
James Kuszmaul | 6802533 | 2024-01-20 17:06:02 -0800 | [diff] [blame] | 62 | DownEstimatorConfigT{{}, 0.015, 1000}, |
James Kuszmaul | c29f457 | 2023-02-25 17:02:33 -0800 | [diff] [blame] | 63 | LineFollowConfig{ |
| 64 | .Q = Eigen::Matrix3d((::Eigen::DiagonalMatrix<double, 3>().diagonal() |
| 65 | << 1.0 / ::std::pow(0.1, 2), |
| 66 | 1.0 / ::std::pow(1.0, 2), |
| 67 | 1.0 / ::std::pow(1.0, 2)) |
| 68 | .finished() |
| 69 | .asDiagonal()), |
| 70 | .R = Eigen::Matrix2d((::Eigen::DiagonalMatrix<double, 2>().diagonal() |
| 71 | << 10.0 / ::std::pow(12.0, 2), |
| 72 | 10.0 / ::std::pow(12.0, 2)) |
| 73 | .finished() |
| 74 | .asDiagonal()), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 75 | .max_controllable_offset = 0.5}, |
Maxwell Henderson | 24f89f3 | 2023-03-25 15:55:46 -0700 | [diff] [blame] | 76 | frc971::control_loops::drivetrain::PistolTopButtonUse::kNone, |
| 77 | frc971::control_loops::drivetrain::PistolSecondButtonUse::kTurn1, |
| 78 | frc971::control_loops::drivetrain::PistolBottomButtonUse:: |
| 79 | kControlLoopDriving, |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 80 | }; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 81 | |
| 82 | return kDrivetrainConfig; |
| 83 | }; |
| 84 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 85 | } // namespace y2023::control_loops::drivetrain |