Swerve Module Position

Hello,

Our team recently updated to 2023 WPILIB VSCode version and we tried to run our code and it threw us an error with the odometry command. The odometry command used to just require kinematics and gyroscope rotation but now it requires initial position of the motors as well. We tried to figure out how to get position of the swerve modules but found no success. Does anybody know how to get the initial position of the swerve modules for the odometry command?

For reference here is our code: BunnyBots_2022/DrivetrainSubsystem.java at main · FRC5549Robotics/BunnyBots_2022 · GitHub

This is how we get our position for the Swerve Modules. We are using the BaseFalconSwerve from 364 and this method came with that, but if you look through our repository it looks like you can apply it to your code as well.

1 Like

We use neos instead of falcons, do you know how the code would work for that?

Looks like the conversion only takes into account the position counts from the falcon, so you would only need to replace that with the NEO position counts.

how would we get the Neo Position counts?

The thing is we don’t have a separately declared drive motor in our code. It instantiates it when it creates the swerve module.

were you using the SDS code? yes. you are. you need to upgrade swervelib.

Easiest path… IMHO…

It added a getPosition method.

How do we upgrade to swerve lib? Is there a vendor dep library we could import?

In your code… you have a folder “frc/lib”. In there you have a copy of the old swerve-lib. You need to replace it with the code from github repo I posted above.

It looks like somebody made some code changes to your old version… really you should put the code at src/main/java/com/swervedrivespecialties/swervelib/ and delete frc/lib

The thing is we cant use the swerve library because we are using mag encoders. We have to just modify 254’s library because as far as I know its the only library that allows swerve to run with mag encoders

Exactly what encoder class are you using and then Hold my imaginary beverage of choice

1 Like

We are using SRX Mag Encoders

(deleted bc Peters Answer is better)

Use DutyCycleEncoder (and plug the PWM pin into a DIO input), not AnalogEncoder. It’s specifically designed for this and will give you a very precise reading (by digitally sampling the PWM pulse rather than relying on analog averaging). It also supports up to 8 encoders.

1 Like