Need some help with software on our new swerve drive

We are a bit late to the swerve game but are working on our SDS Mk4i base frame. And now comes the fun part … the software.

We are starting with the WPILIB examples and

Our swerve is a little bit different in that we are using Neo motors (not really that different), but are using a CTRE Mag encoder for the absolute encoder and wiring it into the Turning SparkMax. Now the mechanical and electrical components are working and the basis software is working. We can talk through the roboRIO to the modules motors and the absolute encoder and get the angle information. For the CTRE encoder we get a number from 0.0 to 1.0 for the full rotation.

Question 1: What is the ‘standard’ configuration for the starting point of the modules?
We understand that the wheels should be straight, however which orientation (ring gear out or in)? Also from the WPILIB documentation we understand the positive (+) direction is CCW. Correct?

Question 2: How to handle the ‘wrap’ of the analog encoder around the offset point?
When we mount the encoder the zero point is essentially random and there we have to incorporate and offset from the module zero point. However, we have a minor issue in dealing also with the encoder wrap from 359 degrees back to 0 degrees. When dealing with this type of encoder, how should we handle the offset and wrap?

We are just starting here and our first trials are to get basic PID running on the turning motor and then make sure we can move to a given position smoothly and repeatably.

Any help would be appreciated.

Thank You.

The recommended starting configuration for the modules, from which the encoder offsets will be measured, should be with the wheel pointing to the east or west, perpendicular to the robot, or in mathematical terms with a 0 degree angle from the X axis.

You should also make sure that the angle is CCW positive (counter clock-wise), invert the motor to make sure of that, and once that you have the angle motor ready, change the inversion of the drive motor accordingly.

Pretty much all of WPILIB’s coordinates consider the CCW direction as positive (as far as I know).

Regarding the encoder wrap, if I understood correctly, you should enable continous input for it to be able to move from the max and minimum points instead of rotating all the way

1 Like

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