Robot curves when its supposed to drive straight, hardware or mechanical solutions?

Hello All,

Our team just tested our KOP drivetrain w/ NEOs and found that it curves right over time (about 6 inches off center over 15 feet). The code is giving the same exact speed to both sides, nevertheless this happens. We dont see any hardware issues, but we will take a deep dive Saturday. Even unloaded the left drive runs a little faster then the right drive (10 rpm faster).

My question involves possible solutions. Should we try to program up closed loop velocity control on the Spark Max? Then our joysticks could set velocities. Or we could go simpler with an input offset? This way our autonomous isnt ever under threat of being messed up by code changes.

However, I do not see many teams needing this for a KOP tank drive. I assumed the internal encoders could take care of everything needed to get an accurate speed from just the .set() method. Could anyone lend some wisdom on where to start on solving this issue?

When you call the “set” method, you are just setting the relative power to the motors - there is no built in feedback, any change in load affects motor speed. So any tiny difference in friction between the halves of your drivetrain will add up quickly. You don’t necessarily the closed loop control to be on the drive motors; the easiest way to drive consistently in auto is to use a gyro to monitor the robot’s heading and a PID controller to steer the robot straight. You will also need some way of monitoring your encoders to make the robot drive the right distance - timing based autos have major problems with changes in battery voltage and mechanical wear.


Slight nitpick, but PID is closed-loop. But i would agree that it shouldn’t be on the individual drive motors.


I am pretty sure the auto wpilib implementation takes care of that by basing speed on distance traveled. So really this issue is a problem in teleop getting joystick input. There is no set distance/velocity so I really dont know how to approach closed loop without creating a whole scale just for translating joystick to velocities.

Edit: I realize my original post didnt clarify that so far our auto seems to cope with the curve. We are using a RamseteCommand. I am primarily asking for teleop as I am unsure if PID loops for velocity are needed instead of set().

In all the times I’ve seen a robot curve to the right majorly, it was because something wasn’t exactly put together right. There might be a collision, or rubbing, or something. In the long run, pulling it apart and inspecting to make sure both sides are even is much less of a bandage fix than software. You have time, see if you can figure out what’s wrong.

Yeah even if this is compensated for in software, you should check the transmission on the slower side for over tightening, lack of lubrication, etc.

OH i’m sorry I didn’t understand! As @UnofficialForth said, start by figuring out hardware issues. But just in case you still were to decide you want velocity-based driving, you can certainly do it. Here’s what it looks like:

SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(kS, kV, kA);
PIDController leftController = new PIDController(kP, kI, kD);
PIDController rightController = new PIDController(kP, kI, kD);
public void velocityDrive(DifferentialDriveWheelSpeeds speeds, DifferentialDriveWheelSpeeds previousSpeeds, double dt){
    double leftFeedforward, rightFeedforward, left, right;

    leftFeedforward = feedforward.calculate(
      (speeds.leftMetersPerSecond - previousSpeeds.leftMetersPerSecond) / dt

    rightFeedforward = feedforward.calculate(
      (speeds.rightMetersPerSecond - previousSpeeds.rightMetersPerSecond) / dt

    left = leftFeedforward + leftController.calculate(
            getWheelSpeeds().leftMetersPerSecond, speeds.leftMetersPerSecond
    right = rightFeedforward + rightController.calculate(
            getWheelSpeeds().rightMetersPerSecond, speeds.rightMetersPerSecond

    tankDriveVolts(left, right);

(I wrote a velocity drive mode so I could test how well our velocity gains were working without needing to worry about issues with path following) If you do decide you want this, then I’d recommend putting some filters on your joystick input to because it is very sensitive. I’d recommend getting your drivetrain assembled as perfectly as possible first, though. You really don’t need this.

Do the following tests.

With the battery disconnected and the chassis propped up so that the wheels don’t touch the ground, spin the wheels to see if one side has more resistance than the other.

Disconnect one motor on each side and run it. Reconnect the motors then disconnect the second motor on each side and run it.

Swap the connections so that the controllers for the right side are driving the motors on the left and the controllers for the left side are driving the motors on the right.

Remove the motors and check that the gears installed on them all have the same number of teeth.

1 Like

I would also recommend calibrating the speed controllers and your joysticks. Sometimes that can fix any discrepancy between the two sides.

A couple seasons ago, we fought this same thing for months. Long story short, one of the pinions on our drive motor was 16T while all the others were 15T.
Hope this helps!

1 Like

Definitely recommend following the advice of everyone else and checking for mechanical issues.

I have also seen this problem from a robot with their PDP mounted all the way to one side so the power wires to the drive motors were significantly shorter to one side than the other. The difference in resistances made the far side motors see less voltage and move a bit slower. If this sounds like your robot, that could also be the problem.

1 Like

Thank you all for the suggestions and code examples. I will try all of this and report back what the problem was and what debugging method worked.

Hello All,

The mechanical group just re-assembled the bad side of the drivetrain and it now drives straight!

The problem could have lied in the pulley. On the right side center wheel we used pulleys from a chassis kit from past years, which have a flange that is slightly bent outwards. The most recent kit has a completely flat pulley. This may have led the pulley to be misaligned compared to the flat pulleyed wheels.

We also replaced a bearing and axle that had a burr on it damaging the shaft.

Either or the problem is fixed. Thanks all for your recommendations!


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.