Sensor faults with hex thoroughbore encoder on SPARK MAX

Hi everyone,

We’re currently experiencing some problems with the hex thorough-bore encoder from REV. We’re running a CIM on the SPARK MAX in brushed mode, and we’re initializing it as a CANEncoder in code.

The problem:
Whenever the encoder is spun, it rapidly flashes a sensor fault on the spark max, but stops whenever it stops spinning. Sometimes it just stays in sensor fault mode, and won’t turn off until we turn off the robot, and unplug the cable.

What we’ve tried:
We’ve tried using two different encoder wires and two different encoders, I’ve looked at the code examples for the encoder, and it doesn’t seem to indicate that there should be any difference in the code.

Any help would be greatly appreciated.
Thanks in advance,

EDIT:
Thank you to Will Toth and Jacob_C for their help in solving the problem (As well as identifying a new one)!

Michael

It sounds like it is configured as a hall sensor. Can you post a link to your code, or at least the location where you configure the encoder?

1 Like

Your problem sounds similar to this - are you using a CANencoder device, or connecting the through-bore to the MAX, or directly to the RIO, or something else?

Sure thing:
– SNIP –
private CANSparkMax angleChanger;
private CANEncoder angleChangerEncoder;

  private SensorCollection leftFlywheelSensor;
  private SensorCollection rightFlywheelSensor;

  public TurretSubsystem(Integer turretMotorID, Integer leftflyWheelID, Integer rightflyWheelID,
      Integer angleChangerID) {
    // turretMotor = new CANSparkMax(turretMotorID, MotorType.kBrushless);
    // turretEncoder = new CANEncoder(turretMotor);

    angleChanger = new CANSparkMax(angleChangerID, MotorType.kBrushed);
    angleChangerEncoder = new CANEncoder(angleChanger);

    leftFlywheel = new TalonFX(leftflyWheelID);
    rightFlywheel = new TalonFX(rightflyWheelID);
    leftFlywheelSensor = new SensorCollection(leftFlywheel);
    rightFlywheelSensor = new SensorCollection(rightFlywheel);
  }
 -- SNIP --

We are using the CANEncoder object (In code), and connecting the encoder cable directly to the SPARK MAX. I can provide a photo if you need.

You will need to initialize the encoder object with the correct encoder type and counts per revolution. The default constructor assumes a built in senor like on the NEO.

This is actually a very easy change, and is required for the through bore anyway since you must set the settings.

Change this line from:

angleChangeEncoder = new CANEncoder(angleChanger)

to

angleChangeEncoder = new CANEncoder(angleChanger, EncoderType.kQuadrature, 8192)

This line does a few things:

  1. Sets the encoder type correctly to use the quadrature encoder.
  2. Sets the ‘counts per revolution’ to 8192 to match the REV Through Bore Encoder
1 Like

Alright, will try. Thanks!

As you would have found following my link,

With an encoder connected to the MAX, you will use a method of the SparkMAX object to get its encoder, not the CANCoder class.

@GeeTwo Except the post you linked doesn’t apply to this at all - it’s one of mine and it refers to one of our products, not the product the OP is using. Per Will’s post above they were absolutely using the right class, just the wrong constructor.

If you’re going to chastise someone for not reading I would suggest verifying your information first.

@M3azzz The real reason I popped in here was to comment on your use of SensorCollection. Two items I wanted to mention:

  1. You shouldn’t create a “new” SensorCollection. A SensorCollection object is already created inside the motor controller object, so use getSensorCollection instead. ie, leftFlywheel.getSensorCollection().
  2. What are you using SensorCollection for? Typically this should only be done if you absolutely need raw sensor data. Otherwise you should use the selected sensor api (ie, TalonFX.getSelectedSensorPosition/Velocity). Getting the selected sensor’s data will give you data that appropriately factors in things like sensor phase and motor invert, and is also updated much faster (every 20ms instead of every 100+ ms). By default the selected sensor for FX is the Falcon’s integrated encoder.
3 Likes

Oh, I didn’t know about the getSensorCollection() object, just assumed that it would be basically the same way that you set up the built-in encoders on the NEO (As in, creating an object with the motor controller being passed into the constructor.)

I was using SensorCollection as that’s what I was told to use on the FRC Discord to get encoder velocity/position for the TalonFX. Could you be able to point me in the right direction to update the code? I’m currently looking at the Java docs for the TalonFX, but can’t find any method called getSelectedSensorPosition or getSelectedSensorVelocity for that object.

Thanks,
Michael

getSelectedSensorPosition/Velocity is inherited from BaseMotorController, so it’s common to all our motor controller classes.

This example should be exactly what you need:

Alright, I’ll check it out, thank you for your help!

Let us know if it worked for you, please. We tried it late tonight and it didn’t work for us but we didn’t get to fully debug it.

Sorry for the late reply.
Yes, the solution worked for us

1 Like

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