blob: cdb5a613f133bfa845723c034af34f4225686f61 [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#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
12using ::frc971::control_loops::drivetrain::DownEstimatorConfig;
13using ::frc971::control_loops::drivetrain::DrivetrainConfig;
14
15namespace chrono = ::std::chrono;
16
17namespace y2023 {
18namespace control_loops {
19namespace drivetrain {
20
21using ::frc971::constants::ShifterHallEffect;
22
23const ShifterHallEffect kThreeStateDriveShifter{0.0, 0.0, 0.25, 0.75};
24
25const DrivetrainConfig<double> &GetDrivetrainConfig() {
26 // Yaw of the IMU relative to the robot frame.
27 static constexpr double kImuYaw = 0.0;
28 static DrivetrainConfig<double> kDrivetrainConfig{
29 ::frc971::control_loops::drivetrain::ShifterType::SIMPLE_SHIFTER,
30 ::frc971::control_loops::drivetrain::LoopType::CLOSED_LOOP,
31 ::frc971::control_loops::drivetrain::GyroType::SPARTAN_GYRO,
32 ::frc971::control_loops::drivetrain::IMUType::IMU_FLIPPED_X,
33
34 drivetrain::MakeDrivetrainLoop,
35 drivetrain::MakeVelocityDrivetrainLoop,
36 drivetrain::MakeKFDrivetrainLoop,
37 drivetrain::MakeHybridVelocityDrivetrainLoop,
38
39 chrono::duration_cast<chrono::nanoseconds>(
40 chrono::duration<double>(drivetrain::kDt)),
41 drivetrain::kRobotRadius,
42 drivetrain::kWheelRadius,
43 drivetrain::kV,
44
45 drivetrain::kHighGearRatio,
46 drivetrain::kLowGearRatio,
47 drivetrain::kJ,
48 drivetrain::kMass,
49 kThreeStateDriveShifter,
50 kThreeStateDriveShifter,
51 true /* default_high_gear */,
52 0 /* down_offset if using constants use
53 constants::GetValues().down_error */
54 ,
55 0.7 /* wheel_non_linearity */,
56 1.2 /* quickturn_wheel_multiplier */,
57 1.2 /* wheel_multiplier */,
58 true /*pistol_grip_shift_enables_line_follow*/,
59 (Eigen::Matrix<double, 3, 3>() << std::cos(kImuYaw), -std::sin(kImuYaw),
60 0.0, std::sin(kImuYaw), std::cos(kImuYaw), 0.0, 0.0, 0.0, 1.0)
61 .finished(),
62 false /*is_simulated*/,
63 DownEstimatorConfig{.gravity_threshold = 0.015,
64 .do_accel_corrections = 1000}};
65
66 return kDrivetrainConfig;
67};
68
69} // namespace drivetrain
70} // namespace control_loops
71} // namespace y2023