 # A question about the derivation of swerve

l am a new to swerve and l am reading the Swerve Drive Manual by Ether.pdf. While l read this pdf , l have some question about it and my question is below.

just as what l have circled in the picture, l think that the calculation of V1y = Vy+wW/2 , but why it is “-” . Can anybody help me ?

1 Like

Deriving the inverse kinematics of swerve is basically finding the module velocity vectors that correspond to the robot state, which consists of the robot’s translation velocity, and its angular velocity. Those module velocity vectors are found by calculating the vector sum of velocity vectors resulting from only translation and only rotation. In your question, the circled part concerns rotation.

To rotate the swerve, each module will have to drive in a direction perpendicular to the center–or else, there would be wheel scrub. The vector r could be denoted by (W/2, L/2). The vector perpendicular to it would then be (L/2, -W/2). Multiply this vector by the rotation magnitude, and you would get what is shown in Ether’s derivation.

IIRC, omega should also be a vector, pointing outside the page, and the multiplication is actually a cross product, which would yield a vector perpendicular to both of the given vectors according to the right hand rule

1 Like

Wow , l get it . Thanks a lot.

2 Likes

In case you didn’t already know, WPILib has swerve drive kinematics built in: Swerve Drive Kinematics — FIRST Robotics Competition documentation. There’s some swerve drive example projects in vscode too.

1 Like

Thanks . l have found it , l do this because l just want to know the work principle of swerve. And when l read the WPILIB’s official swerve code , l have some questions , and that is below;

• In the code below , what 's the unit of 0.381
``````Translation2d m_frontLeftLocation = new Translation2d(0.381, 0.381);
``````

Meters. It works out to 1.25 feet.

For a lot of the examples, we started in imperial units then converted to SI units since WPILib is standardized on SI units. In C++, it’s clearer because the “meter” unit is part of the type system. We couldn’t do something similar in Java without incurring unacceptable performance overhead.

Is it the distance between the center of the robot and the swerve module? So, is it the “r” in the first picture ?

It’s most convenient to make it that, but it’s not required. The math lets you put the center of rotation wherever you want.

So, l don’t have to change the figure according to my own robot?

You should choose whatever origin you want, then plug in the distances from that origin to each wheel module as it pertains to your robot. The geometric center is an obvious choice. The kinematics class lets you move that origin on the fly, so it doesn’t really matter as long as you’re consistent.

``````  public SwerveModuleState[] toSwerveModuleStates(
ChassisSpeeds chassisSpeeds, Translation2d centerOfRotationMeters) {
``````

Ok and thanks a lot .So the two number are just like the value of x and y axis in the cartesian coordinates

Yes, where the coordinate axes consist of positive X forward and positive Y to the left (North-West-Up convention, same as math class).

Thanks a lot!

1 Like