Before using the MAXSwerve Java or C++ Templates, be sure to calibrate your swerve modules using the REV Hardware Client by following the steps below:
Verify you have completely assembled your MAXSwerve Module and have the Steering Motor’s (NEO 550) SPARK MAX connected to the MAXSwerve’s Through Bore Encoder with an Absolute Encoder Adapter.
Install and Open the Latest version of the REV Hardware Client onto a Windows computer
Connect the Steering Motor’s (NEO 550) SPARK MAX directly to your computer via the included USB-C to USB-A cable
Select the Steering SPARK MAX and navigate to the Update Tab to verify your SPARK MAX has the latest SPARK MAX Firmware (the latest version may be different than what is shown in the image below)
Select The Steering SPARK MAX in the sidebar, and select the AbsoluteEncoder Tab
Steps 6-9 are also included in the REV Hardware Client AbsoluteEncoder Tab under the “MAXSwerve Module Calibration” drop-down shown below
Put the Calibration Tool on the MAXSwerve module.
The Calibration Tool needs to be placed on the MAXSwerve module with the lip facing the module.
The MAXSwerve Wheel will only fit in one orientation because of the placement of the wheel's bevel gear. The Calibration tool is not symmetrical, so you will need to align the bevel gear with the side of the cutout indicated with the orange dot in this image.
Rotate the wheel along with the Calibration Tool until the tool's lip firmly drops into place around the MAXSwerve module's edges. Once this happens, the wheel and Calibration Tool will be unable to rotate freely until the tool's lip has been lifted above the edges of the module.
Ensure that the Direction parameter is set to Inverted in the Duty Cycle Absolute Encoder Settings section above.
Click the Set Zero Offset button to calibrate the zero-position of the absolute encoder to this position.
Start driving your MAXSwerve Modules by loading our code templates onto your robot!
The SPARK MAX can accept data from encoders through both the Encoder Port and the Data Port on the top of the motor controller. Encoders have a different method of connecting to the SPARK MAX that depends on what motor you are using and what type of encoder it is. When preparing your encoders, be sure to set up your SPARK MAX correctly for the type of devices you are using.
Incremental encoders measure a change in position as a mechanism rotates while absolute encoders will report an exact position at any time, including at startup. A common analogy to help with knowing the difference is that incremental encoders are like a stopwatch that measures a change in time and absolute encoders are like a clock where you can know exactly what time it is.
With SPARK MAX Firmware Versions 1.6.0 and newer, absolute encoders are compatible with the SPARK MAX Data Port.
To connect an encoder to your SPARK MAX, start by identifying what type of encoder you are using. Below is a flowchart to help generally identify the method you should use.
Running a brushless motor, like the NEO and NEO 550, without the integrated encoder plugged into the SPARK MAX's Encoder Port can damage your motor.
Absolute encoders will work with the default pinout of the SPARK MAX Data Port if the latest firmware has been installed. When using an absolute or duty cycle encoder it is recommended to use one of the following methods to connect your encoder to the SPARK MAX.
Check out our documentation of the Through Bore Encoder.
Other Absolute Encoder: Connect with SPARK MAX Data Port Breakout Board (REV-11-1278)
Use the Data Port Pinout to match the signals from your encoder
Absolute Encoders are only supported through the SPARK MAX Data Port at this time
Easily connect a Through Bore Encoder to your SPARK MAX with an Absolute Encoder Adapter and a 6-Pin JST PH Cable.
For encoders that need a custom wiring harness, you can use the following solder pads on a SPARK MAX Data Port Breakout Board with any generic absolute encoder.
If you are using an Incremental Encoder with a brushed motor you can plug your encoder into the SPARK MAX's front Encoder Port directly. If you are driving a NEO or NEO 550 brushless motor with your SPARK MAX, you will need to configure Alternate Encoder Mode to accommodate the additional encoder input from the Data Port. When using an incremental or quadrature encoder it is recommended to use one of the following methods to connect your encoder to the SPARK MAX.
Check out our documentation of the Through Bore Encoder.
Through Bore Encoder (REV-11-1271)
With brushless motor: Connect with Alternate Encoder Adapter (REV-11-1881). You will need to configure Alternate Encoder Mode.
With brushed motor: Connect to the Encoder Port
Other Incremental Encoder
With a brushless motor: Connect the encoder with SPARK MAX Data Port Breakout Board (REV-11-1278). Use the Alternate Encoder Mode Data Port Pinout to match the signals from your encoder. You will need to configure Alternate Encoder Mode.
With brushed motor: Connect to the Encoder Port with a 6-Pin JST Breakout Board (REV-11-1276) using the Encoder Port pinout
With a brushed motor: Connect the encoder with SPARK MAX Data Port Breakout Board (REV-11-1278) or a similar custom cable. Use the Data Port Pinout to match the signals from your encoder.
Easily connect a Through Bore Encoder to your SPARK MAX with an Alternate Encoder Adapter and a 6-Pin JST PH Cable. When using the Alternate Encoder Adapter make sure the switch is set to "index".
A Through Bore Encoder, or any incremental encoder with the same pinout, can be plugged in directly to the SPARK MAX's Encoder Port.
For encoders that need a custom wiring harness, you can use the following solder pads on a SPARK MAX Data Port Breakout Board with any generic incremental encoder.
Receiving both Incremental and Absolute encoder feedback from a single encoder through the SPARK MAX directly is not currently supported. To do this you will need to wire the encoder directly to your roboRIO or robot controller.
Currently, Limit Switch inputs are only supported when using an absolute encoder or an incremental encoder run through the SPARK MAX's Encoder port. Please note, the limit switch inputs cannot be used at the same time as an Alternate Encoder Mode. The limit switch pins are repurposed for the alternate encoder and are thus disabled.
The SPARK MAX can be configured to run in Alternate Encoder Mode, which reconfigures the Data Port on the top of the controller to accept an alternative quadrature encoder, separate from the default encoder inputs shared between the front Encoder Port and the default quadrature encoder Data Port pins. Analog input is not affected by Alternate Encoder Mode.
This feature is designed for use in low-RPM mechanisms such as drivetrains, arms, and other manipulators. For high RPM applications, it is recommended to use the built-in motor sensor for brushless motors or the default encoder inputs for brushed motors.
Encoder Output Voltage Level
3.3V or 5.0V
Encoder Type Supported
Quadrature†
Maximum Counts per Second
165000
†
Index pulses are not currently supported
Before connecting a sensor with 5V output, the SPARK MAX must first be updated to firmware version 1.5.0 or later, or damage may occur. This can be done through the REV Hardware Client.
Encoder
Counts per Revolution
Max RPM
8192
1200
CTRE SRX Mag Encoder
4096
2400
Greyhill 63R256
1024
9600
When configured for Alternate Encoder Mode, a quadrature encoder connected to the reconfigured Data Port pins can be used as a feedback device by the SPARK MAX. Please note, the limit switch inputs cannot be used at the same time as an alternate encoder. The limit switch pins are repurposed for the alternate encoder and are thus disabled. Please see Connecting an Alternate Encoder for for more information.
Connecting an alternate encoder will likely require a custom wiring harness to connect the necessary encoder power, ground, and signals to the reconfigured Data Port. When configured in Alternate Encoder Mode, the Data Port has the following pinout:
Connector Pin
Pin Type
Pin Function
1
Power
+3.3V
2
Power
+5V
3
Analog
Analog Input
4
Digital
Alternate Encoder Index†
5
Digital
Encoder B
6
Digital
Alternate Encoder A
7
Digital
Encoder A
8
Digital
Alternate Encoder B
9
Digital
Encoder C / Index
10
Ground
Ground
†
The Alternate Encoder Index pin is reserved but not currently supported
Use an Alternate Encoder Adapter (REV-11-1881) to connect a REV Through Bore Encoder directly to the SPARK MAX Data Port. This adapter has a JST PH 6-pin connector that is compatible with the Through Bore Encoder's pinout and a selection switch to change the signal that is connect to pin 4 of the data port.
Check out our documentation of the Through Bore Encoder.
Another option is the SPARK MAX Data Port Breakout Board. This board can be used to wire an alternate encoder to the Data Port. The following table describes which pads on the breakout should be used for which signals coming from the alternate encoder.
Breakout Board Pad Label
Alternate Encoder Function
Limit - F
Index†
P6 (P5 in older batches)
A
Limit - R
B
3.3V or 5.0V
Encoder Power
GND
Encoder Ground
†
The Alternate Encoder Index pin is reserved but not currently supported
Below you will find the steps required to set up and use the Alternate Encoder Mode on the SPARK MAX, starting with configuration through either the REV Hardware Client or the SPARK MAX APIs.
Using the REV Hardware Client, select your SPARK MAX, then navigate to the Advanced Tab and scroll to the Alternate Encoder parameter section. Enable the alternate encoder by setting the kDataPortConfig parameter to 'Alternate Encoder' via the drop down menu. You can also set the other Alternate Encoder parameters at this time.
If using the SPARK MAX APIs, the Alternate Encoder is automatically configured when the Alternate Encoder object is instantiated. An Alternate Encoder is created the same as a CANEncoder, either by directly using the constructor or calling GetAlternateEncoder() on a previously constructed CANSparkMax.
Currently, quadrature is the only available type of configuration for an alternate encoder. This is differentiated from the other types of encoder configurations available for an encoder connected through the front facing Encoder Port on the SPARK MAX.
Since the alternate encoder inputs and the default digital inputs are shared on the Data Port, the user cannot use both the alternate encoder and a digital inputs in code. Therefore, a std::invalid_argument (C++), IllegalArgumentException (Java), or an Error on the Error Out terminal (LabVIEW) will be thrown if a user tries to construct both types objects in code simultaneously.
The alternate encoder can be used with the different closed-loop control modes available on the SPARK MAX. The feedback device used by a CANPIDController must be set to use the alternate encoder through SetFeedbackDevice().
Unlike the built-in sensor on the NEO Brushless motors, the 'phase' of the alternate encoder is unknown to the SPARK MAX. Before enabling any closed-loop control, it is critical that the phase is configured correctly. To verify:
Configure and connect the sensor as a quadrature alternate encoder, but do not run a closed-loop mode.
Plot the output signal of the motor using GetAppliedOutput() and the output of the encoder using altEncoder.GetVelocity(). Confirm that the sensor is behaving as expected. This can be done on the SmartDashboard:
frc::SmartDashboard::PutNumber("Alt Encoder Velocity", m_alternateEncoder.GetVelocity());
frc::SmartDashboard::PutNumber("Applied Output", m_motor.GetAppliedOutput());
Verify that the sign of the sensor is correct relative to the motor direction when driving it forward and backward. If it is not, the sensor must be inverted by calling altEncoder.SetInverted(true).
The Encoder Adapters and SPARK MAX Data Port Breakout Boards can be secured to a SPARK MAX in two ways.
1) To use a SPARK MAX Mounting Bracket to secure your Encoder Adapter or Breakout Board you will need to remove the middle tab of plastic
2) Cut this piece of plastic with a pair of snips, or remove it by twisting the plastic until it breaks
3) Once the middle piece of plastic has been removed, remove any sharp edges with a file or some sandpaper
4) The SPARK MAX Mounting Bracket will fit over the board as shown in this image. Attach the mounting bracket to your surface as you normally would after this step
A zip-tie can be secured around the SPARK MAX's zip-tie notches and over the board to securely attach it to the motor controller as well.
The SPARK MAX does not need to be configured to a specific mode to accept input from an absolute encoder as long as the encoder is connected to the SPARK MAX Data Port.
Encoder Output Voltage Level
5.0V
Encoder Type Supported
Duty Cycle or PWM
Absolute encoder input is supported by SPARK MAX Firmware Version 1.6.0 and newer,
Connecting an absolute encoder that is not a Through Bore Encoder will likely require a custom wiring harness or SPARK MAX Data Port Breakout Board to connect the necessary encoder power, ground, and signals to the SPARK MAX Data Port. When using an Absolute Encoder use the following pinout information for the Data Port:
Connector Pin
Pin Type
Pin Function
1
Power
+3.3V
2
Power
+5V
3
Analog
Analog Input
4
Digital
Forward Limit Switch Input
5
Digital
Encoder B
6
Digital
Absolute/PWM Input
7
Digital
Encoder A
8
Digital
Reverse Limit Switch Input
9
Digital
Encoder C / Index
10
Ground
Ground