Built-In NEO encoder is not accurate? or is our code just bad?

Our team is doing a swerve drive using 4 Swerve X modules with 2 NEOs each. Originally, we were going to use SRX Mag Encoders connected to our SparkMAX’s but that was too difficult, and I couldn’t figure it out.

So for now, we’re going off of the built in encoder on the turning motors. However, after driving for a little bit, the turning motors don’t turn to the correct direction, which prevents us from driving properly.

We always manually align the wheels before turning the robot on, and enabling or disabling field-oriented drive doesn’t fix this issue.

Our code for swerve drive is broken into 3 parts: SwerveModule SwerveDrive and a command that drives the robot ControlSwerve

I would recommend using YAGSL, as this issue has been discovered (by democat and their maintained sds-swervelib). If you are determined to use your own however you should add a synchronization feature so your angle/steering/azimuth motor encoders are periodically synced with the absolute encoder while the module isn’t running.

Also this NEEDS to be the absolute encoder.

and in whatever units you are using after your conversion factor.

Apologies if I wasn’t being clear, we are not using any absolute encoders on our swerve drive, as I couldn’t figure out how to connect our SRX Mag Encoders to the SparkMAX, so we just manually align our wheels each time we boot the robot.

So we’re only using the turning encoder, no absolute encoder.

1 Like

That was not clear at all! The only way to “hack” this is by increasing your gear ratio so any slips aren’t as noticeable. Neo integrated encoders aren’t the very best (idk about vortex yet). You may want to include the coupling ratio and tune it with sysId to get better results over a long period but it will always be there.

Side note, have you considered cheaper options like thrifty encoders?

1 Like

You can also connect SRX Mag encoders to the roboRIO, if that’s easier (you’ll need to match this in your S/W). Either way, it’s three wires – the major issue is that the connectors on SRX Mag Encoder and SPARK MAX are small and it can be hard to work with the wires normally used with these (small and delicate).

If you search, you can find instructions here on CD, with suggested parts.

“connect pins 2 (+5V), 9 (PWM), and 10 (GND) from the SRX MAG ENCODER to a roboRIO digital input” – or to pins 2 (+5V), 6 (PWM), and 10 (GND) of the SPARK MAX data port.

Note that you can’t just use a cable to plug the two 10-pin connectors together.

2 Likes

My sincerest apologies for not being straightforward, and thanks for your swift reply!

We know that cheaper options exist, and we are looking into them, however we are vender-locked by the DOE, which means that we can only buy from certain vendors. It’s unfortunately out of our control.

For example: We can buy stuff from AndyMark/CTRE/VEX, but not TTB or Redux.

iirc we ordered some CANCoder’s from AndyMark a while ago, but were still waiting for them to arrive.

I think for now, we’ll try increasing the gear ratio. I’ll see if electrical group of our team can accomplish @nuttle 's idea

1 Like