Optimizing Drive Code

What are some ways to make driving smooth and easier? Right now we have a fast drive and the small joystick inputs in our code make the bot go from stand still to whipping around very fast with little in between. This makes it hard to drive into rollers/accurately pick up disks.

Can you post your drive code? Typically you set the drive power to the position of the joystick which allows for the robot to be controlled at multiple different speeds.

1 Like

the easiest solution would be to set drivetrain motor’s motor stopping to “coast”. Try it and see.

1 Like

One thing you can do is compare the commanded speed (joystick setting) against the motors’ current velocity, and if it’s too large a difference, limit what you’re sending as an increase. For instance, joystick in one direction is commanding 100%, each time it comes into the loop, add something like 5% to the velocity you’re sending to the motors until you get to the commanded velocity. This will decrease the ‘jerk’ of the robot trying to rapidly accelerate and give you a smoother feel. Play around with the value you add to get to what you’re trying to get to.

This is effectively adding a ‘P loop’ into your driver control, and there are advantages and disadvantages to this approach. It could also be the first step of going to a full PID driver control (again, pros and cons to everything).


This may not apply to you, but make sure the drivers are using some finesse on the joysticks. I see way too many people mash the joysticks to full deflection… basically romping on the brake and gas with no in between.

If they are using some finesse on the controls, then you could modify the signals sent to to motors so they are not linearly proportional to joystick deflection. A simple version of this for VEXcode might look like this…

Here is how it would modify the motor signals…

This gives you more precision for small joystick deflections, but lets you have full power too.

You might also want to look up slew rates and figure out how to limit the rate of change for the motor signals.


HERE IS THE CODE: VEX-1526A-2023/robot-config.cpp at main · sohamsolanki/VEX-1526A-2023 · GitHub

The code doesn’t drive unless the speed is more (or less) than 5 (or -5), meaning your deadband zone may be a small factor in causing the jumpiness

Usually if the robot is “whipping around very fast” it’s not only a problem with the code. What’s your RPM and wheel size?