Multiple ports/channels for Encoder: corresponding wiring?

Hi all
I found FRC Swerve implementation but don’t understand the underlying wiring of the related encoder.
public static final int kRearRightDriveEncoderPorts = new int {14, 15};

m_driveEncoder = new Encoder(kRearRightDriveEncoderChannels[0], kRearRightDriveEncoderChannels[1]);

Can someone explain me what would be the corresponding wiring ? Which ports are they (from the motor controller/ Roborio …etc…)?
I have to say that I am ok with programming but robotic & wiring are pretty new to me.
Thanks a lot :slight_smile:

This expects a quadrature encoder to be in DIO ports 14 and 15.

You can read about how these work here:

The docs for wiring encoders:

The DIO ports are number 0-9 so i’m not sure what port 14 and 15 is referencing, you may want to change that to a lower port number.

2 Likes

Note that a quadrature encoder provides relative (incremental) values. For swerve, you need absolute encoders to know what direction the wheel is pointing. These can either be used full time, or the absolute value can be used to initialize a relative encoder value which is used from then on.

There are multiple kinds of encoders commonly used for swerve, and they connect differently, so it would be good to understand what type you’re using. Common types include:

  • Ones directly connected to CAN (which would NOT have the kind of quadrature connection you described). CTRE CANCoders are probably the most common example of these.
  • Ones connected to an analog signal input, commonly directly to the Rio, but some motor controllers have a provision for reading analog inputs. ThriftyBot analog encoders are of this type.
  • Ones connected to a motor controller, such as the REV through-bore (hex) encoder on the MaxSwerve. These output an absolute position as a PWM value, which the SparkMAX can read via an Absolute Encoder Adapter. These encoders also output a relative (quadrature) signal, but the motor controller can’t read both absolute and relative at the same time; to do that you’d have to wire them to the Rio, using 2 pins for quadrature and 1 for the PWM absolute signal.
  • Relative encoders built into brushless motors. These aren’t a separate item, but are part of the motors themselves. They provide values over CAN, but you’d still need a separate absolute encoder to initialize them (that is, to know where they’re initially pointed at power up).

If you tell us what kind of swerve modules and encoders you’re using (and perhaps what you were looking at for guidance) it would help focus the advice here.

There are additional DIO (and many other) ports available on the Rio MXP connector. This can be connected to either directly with a suitable connector, or through a board that provides MXP breakout connections. These extra connections typically get used when you need a lot of signal I/O.

2 Likes

Thanks for your reply.
We have to set up our swerve:
Neo motors with SPARK MAX Motor Controllers=> we will use the internal Neo encoders. And I guess they correspond to the relative encoder
for our absolute encoder, we have SRX MAG encoders that we need somehow to plug into the data port of the SPARK MAX Motor Controllers or the ROBOT Rio.

Based on the doc shared by Braykoff, it sounds like SRX MAG encoders are not quadrature encoders, meaning, the encoder instantiation mentioned into my post is not relevant. Am I right?
Thanks!

The CTRE Mag encoders offer both a quadrature relative output and a dutycycle absolute output, so they are listed in both sections of the article that Braykoff mentioned.

However, as bbonner said you want to use it in absolute mode for swerve turning, so you’d want to either use the absolute breakout for the Spark Max or the DutyCycle class for the roboRIO.

1 Like

image
[Source.]

The “A” and “B” signals can be used to get quad signals, but these are relative and you need an absolute output. This is what the “PWM” output is for. You can hook this to either the SPARK MAX or to the roboRIO. On the roboRIO, you use this with DutyCycle or DutyCycleEncoder.

This may be helpful: Using Encoders with the SPARK MAX - REV ION Brushless.

1 Like

sorry I got confused, I wanted to say:
"it sounds like the NEO internal encoders are not quadrature encoders, meaning, the encoder instantiation mentioned into my post is not relevant. "

That’s correct

1 Like

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