Our team has been trying to program the SDS MK4 swerve drive modules. Our current config just uses the built in encoders on the NEOs. The issue that we are having is basically that we can’t keep the modules synced up. They are all facing different directions, and whenever we enable and disable, or wait a few seconds, one randomly changes directions. We are using the SDS swerve libraries.
We also have 4 SRX Mag encoders, but we can’t figure out how to attach them to our Spark Max speed controllers. We tried enabling alternate encoder mode, but that didn’t seem to do anything.
The encoder built in to the Neos are relative, so every time you restart your robot the current position becomes zero. You need to use the absolute position from another encoder.
Are you sure you have SRX Mag encoders, not CANCoders? If they are truly SRX Mag encoders, how do you have them wired?
You can’t just plug them into the gadgeteer/data port on the Spark Max (unless you are using a brushed motor, which you are not). I’m not certain, but I think the Spark Max in alternate encoder mode is only able to read relative position from an alternate encoder, since it is not able to read index pulses.
With the newest update it is possible to interface the absolute encoder using the PWM output, however it is not plug and play. It’s going to take looking at both datasheets and making an adapter.
It’s also not super simple to wire the CTRE mag encoder into the Rio (but it could also be done with skill).
If I were in your situation, I would personally look to the thrifty encoder wired into the RIO, or the CTRECANcoder wired into your CAN bus. They are much easier to deal with.
Can you provide more detail? I see a note in the 1.6.0 release notes, but there isn’t much detail. All I see is that you can read index pulses from the Encoder Port when in brushed mode. In brushless mode, the encoder port has to be attached to the Neo’s encoder.
Maybe some of the docs are out of date, but the Data Port documentation says in multiple places that that alternate encoder cannot read pulse index signals.
The Quadrature Encoder Input on the Data Port is compatible with standard quadrature encoder signals, usually labeled as channel A, channel B, and Index. SPARK MAX shares these signals with the Encoder Port on the output side of the controller, therefore the Index signal is shared with the third brushless encoder signal C. When in Brushless Mode, these Data Port pins cannot be used with an external encoder.
This is pretty new stuff. I messed around with it a little on a bench, and it seems to work. We aren’t planning on using it this year though since it’s super new.
Seems like the documentation is out of date a little (didn’t realize that in my first post). I’m sure it will get better with time. You can sorta deduce whats going on though with some different products:
That would mean if you used this adapter board:
Pin 1 on the JST connector would go to pin 2 on the mag encoder.
Pin 2 on the JST would go to pin 9 on the mag encoder, and
Pin 6 on the JST would go to pin 10 on the mag encoder.
I don’t know what pin on the Spark Max is actually the PWM input, but if you search chief you may be able to figure it out.
Given the “newness” of this method, I don’t think many teams should be messing with it. It’s not well documented yet and pretty hacky.
4272 will probably experiment with this in the off season to be able to run the control loop directly on the steering axis of our MK4is and maybe see a tiny performance bump. For now though, it isn’t worth it.
I’m going to email REV and see if I can get some clarity. The documentation says it’s not supported, but I see two products that seem like they should enable absolute capability with their Through-Bore Encoder (which is an excellent product, btw.)
That’s fair. I think their documentation is just behind. I believe they intended these features for their swerve customers (who are using the hex encoders) so the documentation for the rest of us just isn’t there.
In short, you can use the CTRE Mag Encoder as an absolute encoder with a SPARK MAX, but you cannot use Alternate Encoder Mode when driving a brushless motor. So, it will be a little tricky to wire, but it seems like you’d probably want to use Gadgeteer Breakout and/or SPARK MAX Data Port Breakout so you can make the connections between the data ports. You could use the Absolute Encoder Adapter, but you’d also need a JST connector.
I stand by the question for the OP: Are you sure you have SRX Mag encoders, not CANCoders? If they are truly SRX Mag encoders, how do you have them wired?
We do have the srx mag encoders, but plugging them into the top port didn’t work because we are using a neo. Our team’s current plan is to solder a pwm wire to the encoder and plug it into the roborio, use a separate talon srx for the encoder, or buy different encoders and wait. If there are any other ideas, let me know.
Expanding on why this didn’t work, as other have stated, the A, B, and Index pins in our Data Port are shared with the A, B, and C hall sensor signals connected to the NEO. This doesn’t mean you can’t use the PWM output of the SRX Mag Encoder with the SPARK MAX running a NEO, you just need to make sure the A, B, and Index signals are not connected.
You can use a breakout board like our Data Port Breakout, and solder only the power, ground, and PWM signal wires to the appropriate pads on the breakout (PWM would get connected to P6).
This is also only current as of 2022, but has a lot of detail and suggested parts – and these are well tested and known to work. We have been using SRX MAG + SPARK MAX/NEO for a couple of years now, with no issues. We plan to try building slightly modified boards with the PWM going into pin 6 on the SPARK MAX soon.
@dyanoshak It would be really helpful to create a table describing the configurations in the documentation. You could also link it from the various product pages.
For example, it’s not clear from the product pages how the Absolute Encoder Adapter differs from the Alternate Encoder Adapter in absolute mode. The Alternate Encoder Adapter page doesn’t say you cannot use absolute mode with a brushless motor, you need the Absolute Encoder Adapter (not in alternate encoder mode) for that.