Hello. Thanks to all for the help in the past. We are looking to more gradually accelerate the bot in autonomous rather than just immediately ramping to 80 or 90% speed.
Would someone be willing to look at my code (java) and give me some suggestions or point me in the right direction to allow for a more gradual acceleration in autonomous.
Here is a link to the code: GitHub - EricTheOtterBot/OtterBots-2023-code
The autonomous I’ve been working on is called balanceAuto, which uses a command called AutoBalance. Within AutoBalance, I set the speed to -0.8. Looking for a way to gradually speed up that number.
Thanks so much.
Adjusting the ramp rate of the motors will increase the time needed to reach top speed, thus producing more gradual acceleration.
1 Like
You could possibly try turning down the current limit on your drive motors for autonomous and then reset them for teleOp. It might be a little janky but it’s working well for our lift so far.
Where is this done in the code?
If you are using a SwerveControllerCommand, you are passing in a trajectory that has a config in which you specify the path’s velocity and acceleration. Have you tried lowering these values?
I have. The problem with this is that I can’t/don’t know how to use the code I put into my AutoBalance command. In that command I specify that it should go forward until the gyro’s pitch is less than -12 degrees. If there is a way I could put that gyro code into the SwerveControllerCommand, that would definitely be optimum.
Acceleration limiting is often down with Slewrate Limiters. By setting the power equal to filter.calculate(input);
you could gradually let the value increase from 0 to 90%
You also could choose to not run at 90% power and instead do 50%. A lot of people find that if you don’t need the time savings, this is a lot more consistent way to do an auto.
Please please ask me if you want any clarification on the above. Happy to help!
1 Like
Typically wherever you construct your drivetrain.
public DriveSystem() {
fieldOriented = true;
// Capitalized and underscored variable names are statically imported constants from Constants.java
frontLeft = new CANSparkMax(FRONT_LEFT_MOTOR, MotorType.kBrushless);
backLeft = new CANSparkMax(BACK_LEFT_MOTOR, MotorType.kBrushless);
frontRight = new CANSparkMax(FRONT_RIGHT_MOTOR, MotorType.kBrushless);
backRight = new CANSparkMax(BACK_RIGHT_MOTOR, MotorType.kBrushless);
if (Robot.checkType() == Robot.RobotType.A_BOT) {
frontLeft.setInverted(false);
backLeft.setInverted(false);
frontRight.setInverted(true);
backRight.setInverted(true);
} else {
frontLeft.setInverted(false);
backLeft.setInverted(false);
frontRight.setInverted(true);
backRight.setInverted(true);
}
// Current limits on breakers are set to 40 Amps
frontLeft.setSmartCurrentLimit(CURRENT_LIMIT);
backLeft.setSmartCurrentLimit(CURRENT_LIMIT);
frontRight.setSmartCurrentLimit(CURRENT_LIMIT);
backRight.setSmartCurrentLimit(CURRENT_LIMIT);
// Voltage compensation in volts
frontLeft.enableVoltageCompensation(NOMINAL_VOLTAGE);
backLeft.enableVoltageCompensation(NOMINAL_VOLTAGE);
frontRight.enableVoltageCompensation(NOMINAL_VOLTAGE);
backRight.enableVoltageCompensation(NOMINAL_VOLTAGE);
// Time in seconds to reach max velocity in open loop
frontLeft.setOpenLoopRampRate(RAMP_RATE);
backLeft.setOpenLoopRampRate(RAMP_RATE);
frontRight.setOpenLoopRampRate(RAMP_RATE);
backRight.setOpenLoopRampRate(RAMP_RATE);
This is our drivetrain constructor from 2022.
So what I ended up doing is making a ton of commands to simply set it to 10% more, then return it as true and move to the next command, which is 10% more than the last one. Sort of a pathetic fix because I didn’t set an acceleration, but it works anyway. Thanks for all of your help and advice! I appreciate your insight. Hopefully, I’ll get my github updated to the current code.
P.S: Does anyone know if the link at the top of this post will update to show the latest code, even if I don’t change the link itself? I don’t want people to click on that link and see old code.
Thanks again.
I guess I can answer myself. The link still works.