How to have clean strafing

Currently i have a drive function which consists of 3 PID loops, one for x, one for y and one for orientation. (i also have position tracking). But even after having 3 PID loops, i am still having trouble getting the strafing to be clean, By that I mean, for it to be strafing smoothly and in a straight line. And i know it isnt a build problem since it strafes in a smooth line in opcontrol.

So does anyone have any ideas and or suggestions for me to make my strafing as clean and accurate as possible?

1 Like

Could you post your code? A video of the robot would also be helpful, so we can see the issue. If the strafing is clean in driver but not in auto, I’d suspect there’s an issue in your code.

1 Like

I am unable to post a video rn but here is the code

1 Like

Strafing via 3 PID controllers isn’t really clean, as you said. However, using mecanum/x-drive math (google it) you can write a function that accepts a direction and a power and it distributes that power across the wheels so that the robot strafes in the proper direction.

That way, you just need two PID controllers (distance and heading). The distance controller is based on the distance to the point, and you just point the output of the pid controller towards the target point using holonomic math (which is pretty simple btw).


do you mean something like this ?

1 Like

Yep, that explains exactly what math you need to use.

1 Like

ok cool thanks i will have a look through

I was looking through it, and that is for joysticks, could it also be adapted for auto?

I’m not going to tell you how to do it, I just said that it’s possible and suggested you do some research. That paper explains the math behind a holonomic drive, if you read closely and understand it you should be able to figure out how to apply it to both auton and driving (there is little use for driving btw).

1 Like

ok got it thanks for the help

I’m just going to ask if you search the vexform for holonomic or x-drive. There is a non-trivial amount of discussion about this.

1 Like

So i gave the document a thorough read and made the code from my understanding and this is what i made (Ubuntu Pastebin) but its am still having trouble strafing in a straight line, it tends to sway backwards and it doesnt end up near its target. If you see any mistakes please let me know or if you have any other suggestions

Aside from needing more general abstraction, one thing I noticed right away is that 1/4 results in 0, as you are doing integer division.

Same with abs, depending on the header you are using it will accept and return an integer, meaning / abs(largestVal) might be doing integer division as well. Use fabs or std::abs.

1 Like

Disclaimer: I am not the primary coder for my team.

With that said, perhaps the problem could be something to do with your robot’s center of gravity, greater friction on one wheel, or some other physical aspect of the robot.

this shouldnt be an issue since the robot can strafe straight in driver control, so if it were to be the wheels, then it would show in the driver control as well