Add Swerve drive solution#46
Conversation
|
🌐 Preview URL: https://pr-46.frcsoftware.pages.dev |
|
The file directory should probably be changed to |
| private final CANcoder cancoder; | ||
|
|
||
| /** Radius of module wheel in meters */ | ||
| private static final double wheelRadius = Units.inchesToMeters(2.0); |
There was a problem hiding this comment.
Static constants should probably be at the top of the class instead of nested between instance members
| * | ||
| * <p>3.5 m/s divided by radius gives radians per second | ||
| */ | ||
| private static final double maxSpeedRps = Units.radiansToRotations(SwerveDrivetrain.MAX_SPEED / wheelRadius); |
There was a problem hiding this comment.
It would be better to use methods from the DCMotor class, which allows you to access the max speed of a motor in rad/s via DCMotor.getKrakenX60(1).withReduction(reduction).freeSpeed. That can then be multiplied by the wheel radius instead of divided like here.
| */ | ||
| private final DCMotorSim driveSim = | ||
| new DCMotorSim( | ||
| Models.singleJointedArmFromPhysicalConstants(DCMotor.getKrakenX60(1), 0.01, 6.0), |
There was a problem hiding this comment.
The motor type and gear ratio arguments should probably be constants in SwerveDrivetrain
| * @param vy Velocity in the field-y direction | ||
| * @param omega Angular velocity about the z-axis. | ||
| */ | ||
| public void driveFieldCentric(double vx, double vy, double omega) { |
There was a problem hiding this comment.
I think calling this xThrottle, yThrottle, and rotationalThrottle would be more applicable since these aren't speeds.
Providing another overload that takes in a straight robot-relative ChassisVelocities would be a good idea too, to prepare them for path following and the like
| /** Called periodically while running in simulation */ | ||
| public void simulationPeriodic() { | ||
| // Get input from talonfx sim, and apply to mechanism | ||
| driveSim.setInputVoltage(driveMotor.getSimState().getMotorVoltage()); |
There was a problem hiding this comment.
Just a question - will the sim stuff be autofilled in the actual exercise, or are we expecting people to know how to work with sim by this point?
No description provided.