Our team is working with swerve this year and we wanted to know if there are any improvements to make to the code so that it can improve the speed or maneuverability of our robot.
We use the swerve module MK4i, L2, with spark max controllers, Pigeon 2.0 and the YAGSL library
I would recommend to only specify the conversionFactors in physicalproperties.json since module overrides this and it can get cumbersome to manage.
What is your wheel diameter too? I may have a different angle conversion factor.
Using the test script
// Angle conversion factor is 360 / (GEAR RATIO * ENCODER RESOLUTION)
// In this case the gear ratio is 12.8 motor revolutions per wheel rotation.
// The encoder resolution per motor revolution is 1 per motor revolution.
double angleConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(150.0/7.0, 1);
// Motor conversion factor is (PI * WHEEL DIAMETER IN METERS) / (GEAR RATIO * ENCODER RESOLUTION).
// In this case the wheel diameter is 4 inches, which must be converted to meters to get meters/second.
// The gear ratio is 6.75 motor revolutions per wheel rotation.
// The encoder resolution per motor revolution is 1 per motor revolution.
double driveConversionFactor = SwerveMath.calculateMetersPerRotation(Units.inchesToMeters(4), 6.75, 1);
System.out.println("\"conversionFactor\": {");
System.out.println("\t\"angle\": " + angleConversionFactor + ",");
System.out.println("\t\"drive\": " + driveConversionFactor);
System.out.println("}");
We’ve experimented with exponential as against linear joystick-to-motor-speed conversion. As both joystick output and motor input is 0 to 1, it’s a simple matter of raising the output to some power, I’d suggest something between 1.5 and 4. Experiment to see what is most comfortable or intuitive to your drivers. The effect is that smaller joystick movements result in more creep-like speeds for finer control while ramp-up occurs later in the joystick range.
We also have programmers working on PID control in the input-output loop as well.
You can just multiply the joysticks output, which is in robotContainer, by a number greater than 1.
For example () → -MathUtil.applyDeadband(controleDrive.getLeftY()*2, Controle.DEADBAND),
This will decrease the robot’s speed by half.