Swerve drive

Need help programming a swerve drive!!

Is there a specific issue you need help with?

If you have more general questions about swerve drive software, I’d suggest checking out Team 1640’s website or searching Chief Delphi.

I want to program it as an offseason project, but I have no idea where to begin

I did it this season… you should start with only one wheel, with its position (360 degrees)

if you have specific questions, PM me! :smiley:

*There are at least 8 aspects of swerve programming

  1. position control of wheel steering angle

  2. velocity control of wheel speed

  3. driver interface

  4. inverse kinematics

  5. special handling of large wheel angle changes

  6. limiting total steering angle

  7. field-centric control

  8. programmed maneuvers and/or special modes

As Antoine suggested, position control of wheel steering angle is a good place to start. It will require an angle sensor and some sort of closed-loop control.

Velocity control of wheel speed should also be closed-loop for best results, but you may be able to get away with just controlling voltage to the drive motors.

Driver interface requires some soul-searching. Do you want to give the driver low-level direct control of the 3 degrees of freedom of the vehicle (forward/reverse speed, left/right speed, spin CW/CCW speed)? Or do you want to make the driver interface more abstract (e.g. turning radius and arc speed).

Inverse kinematics is the name for the computation you need to do to convert the driver commands to 4 pairs of wheelspeed/wheelangle commands. This computation is well understood and documented in many papers and published software. Make sure you code this properly so that all changes in steering angle are coerced to the range +/-180 degrees: You don’t want to rotate the wheel 359 degrees clockwise when rotating 1 degree counterclockwise would achieve the same result.

Depending on the design of your swerve hardware, you may also need/want to do some special handling of changes in steering angle command between 90 and 180 degrees. For example, if there’s a sudden command to increase the steering angle of a wheel by 135 degrees, you might instead decrease the angle by 45 degrees and reverse the speed of the wheel.

Depending on the design of your swerve hardware, you may also need to do some special handling to limit the total steering angle to whatever the wires can tolerate. You’ll have to program the software to keep track of the total steering angle of each wheel, and have the software look for opportunities to “unwind” a wheel when its wheel speed is zero (or nearly zero).

Field-centric control is optional (driver preference) but should be straightforward to implement once everything else is working. But make sure your gyro is working properly first. The gyro “zero” position should align with your wheel steering encoder “zero” position (typically “zero” is straight forward), and both the gyro and wheel steering encoder should have the same direction of rotation (e.g. both are positive in the clockwise direction).

Finally,you may want to add some programmed maneuvers to the driver interface. For example, the driver presses a button and the robot quickly backs up and rotates 180 degrees. You may also want to add buttons to allow the driver to select different modes.

In addition to all the above, you may need/want to add acceleration limiting (both linear and centripetal) if the game involves top-heavy robots carrying unsteady loads.