2 wheel swerve drive

So my team decided to work on a swerve drive system this summer, and we are very close to being done, but we are having trouble getting code that would allow it to spin and translate at the same time. The problem arises because we are only using 2 modules to save money. This means that when the wheels are aligned with the direction of translation, only a difference in angle can cause rotation, this leads to us having to try and figure out which angle and what speed we need to put the wheels at which gets into a system of equations with 4 variables and some extremely difficult math. Was wondering if anyone had any experience with this sort of thing, or any suggestions on what to do. Thanks in advance.

The new kinematics PR (https://github.com/wpilibsuite/allwpilib/pull/1787) to WPILib contains classes that can perform swerve drive kinematics for a swerve with an arbitrary number of modules.

https://github.com/wpilibsuite/allwpilib/blob/d4f40055241af2fbab1e4eb7951e423e89bccf37/wpilibj/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematics.java is the Java version. There is also a C++ version in that same PR if you are interested.

Generally, the swerve inverse kinematics (desired chassis speeds to individual module speeds) works out as follows:

\vec{v}_{\mathrm{wheel}} = \vec{v}_{\mathrm{robot}} + \vec{\omega}_{\mathrm{centerofrotation}} \times \vec{r}_{\mathrm{centerofrotation to wheel}}

It is the same for 2 as if you had 4. the two modules you have need to be aimed to be orthogonal to the center of rotation for pure rotation of the robot.

For instance in 2015 we started out with 4 modules in the four corners - but later on to save weight, in order to add can grabbers, we went down to only 2 modules - using the same code. The driving felt essentially the same - and was adequate for a year with no defense. We also down graded to only 2 drive motors last year at an offseason as our experiment with 775 drive went horribly wrong and we ran out of spares. We ended up winning the event anyway!.

1 Like

Thanks for the link to the git page. I’m actually a mechanical lead, and have little to know idea what I’m doing. Our lead (and pretty much only) coder is unavailable, so I’m trying to figure this out. How do I get the classes into vscode?