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 | |
| 12 | using ::frc971::control_loops::drivetrain::DownEstimatorConfig; |
| 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 | |
| 18 | namespace y2023 { |
| 19 | namespace control_loops { |
| 20 | namespace drivetrain { |
| 21 | |
| 22 | using ::frc971::constants::ShifterHallEffect; |
| 23 | |
| 24 | const ShifterHallEffect kThreeStateDriveShifter{0.0, 0.0, 0.25, 0.75}; |
| 25 | |
| 26 | const DrivetrainConfig<double> &GetDrivetrainConfig() { |
| 27 | // Yaw of the IMU relative to the robot frame. |
| 28 | static constexpr double kImuYaw = 0.0; |
| 29 | static DrivetrainConfig<double> kDrivetrainConfig{ |
| 30 | ::frc971::control_loops::drivetrain::ShifterType::SIMPLE_SHIFTER, |
| 31 | ::frc971::control_loops::drivetrain::LoopType::CLOSED_LOOP, |
| 32 | ::frc971::control_loops::drivetrain::GyroType::SPARTAN_GYRO, |
| 33 | ::frc971::control_loops::drivetrain::IMUType::IMU_FLIPPED_X, |
| 34 | |
| 35 | drivetrain::MakeDrivetrainLoop, |
| 36 | drivetrain::MakeVelocityDrivetrainLoop, |
| 37 | drivetrain::MakeKFDrivetrainLoop, |
| 38 | drivetrain::MakeHybridVelocityDrivetrainLoop, |
| 39 | |
| 40 | chrono::duration_cast<chrono::nanoseconds>( |
| 41 | chrono::duration<double>(drivetrain::kDt)), |
| 42 | drivetrain::kRobotRadius, |
| 43 | drivetrain::kWheelRadius, |
| 44 | drivetrain::kV, |
| 45 | |
| 46 | drivetrain::kHighGearRatio, |
| 47 | drivetrain::kLowGearRatio, |
| 48 | drivetrain::kJ, |
| 49 | drivetrain::kMass, |
| 50 | kThreeStateDriveShifter, |
| 51 | kThreeStateDriveShifter, |
| 52 | true /* default_high_gear */, |
| 53 | 0 /* down_offset if using constants use |
| 54 | constants::GetValues().down_error */ |
| 55 | , |
| 56 | 0.7 /* wheel_non_linearity */, |
| 57 | 1.2 /* quickturn_wheel_multiplier */, |
| 58 | 1.2 /* wheel_multiplier */, |
| 59 | true /*pistol_grip_shift_enables_line_follow*/, |
| 60 | (Eigen::Matrix<double, 3, 3>() << std::cos(kImuYaw), -std::sin(kImuYaw), |
| 61 | 0.0, std::sin(kImuYaw), std::cos(kImuYaw), 0.0, 0.0, 0.0, 1.0) |
| 62 | .finished(), |
| 63 | false /*is_simulated*/, |
| 64 | DownEstimatorConfig{.gravity_threshold = 0.015, |
James Kuszmaul | c29f457 | 2023-02-25 17:02:33 -0800 | [diff] [blame] | 65 | .do_accel_corrections = 1000}, |
| 66 | LineFollowConfig{ |
| 67 | .Q = Eigen::Matrix3d((::Eigen::DiagonalMatrix<double, 3>().diagonal() |
| 68 | << 1.0 / ::std::pow(0.1, 2), |
| 69 | 1.0 / ::std::pow(1.0, 2), |
| 70 | 1.0 / ::std::pow(1.0, 2)) |
| 71 | .finished() |
| 72 | .asDiagonal()), |
| 73 | .R = Eigen::Matrix2d((::Eigen::DiagonalMatrix<double, 2>().diagonal() |
| 74 | << 10.0 / ::std::pow(12.0, 2), |
| 75 | 10.0 / ::std::pow(12.0, 2)) |
| 76 | .finished() |
| 77 | .asDiagonal()), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame^] | 78 | .max_controllable_offset = 0.5}, |
| 79 | }; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 80 | |
| 81 | return kDrivetrainConfig; |
| 82 | }; |
| 83 | |
| 84 | } // namespace drivetrain |
| 85 | } // namespace control_loops |
| 86 | } // namespace y2023 |