# Generalized Swerve Math: How to do swerve for any configuration of wheels?

Over the summer, I was given the challenge of create a more generalized swerve algorithm for any configuration of wheels:

Also right back at you with a challenge problem:
How do you generalize the solution for swerve I proposed to a non-rectangular robot? Specifically, how do you solve swerve for a drivebase with n wheels randomly scattered in the x-y plane such that the robot translates and rotates about the geometric center of the convex polygon defined by the wheel arrangement without any wheels skidding or slipping?

Here is my shot at the problem. I used Processing.

Let me know if you have any feedback. Not much applicability in FRC but maybe another kind of robot. I challenge all of you to this problem.

The new WPILib kinematics classes actually support forward (module states to chassis state) and inverse (chassis state to module states) kinematics for an arbitrary number of swerve modules at arbitrary locations.

In general, the wheel velocity vectors are as follows:
v_wheel = v_robot + w_centerofrotation x r_centerofrotation2wheel
What the WPILib classes do is split up that equation into the individual x and y components and then they are put into a matrix. The matrix can be multiplied by the desired chassis speeds to get the individual module states. The pseudoinverse of the matrix can be multiplied by the individual module states to get the chassis speeds.

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