Rev Through Bore Absolute Encoder Wrapping

Hello! I am trying to use a Rev Through Bore Absolute Encoder for my Arm’s encoder. Currently, the “zeroed” posistion is when the arm is parallel to the ground. However, the arm can go below this, which causes the Absolute Encoder to read a positive number, which is not good. Is there a way to have negative Absolute Encoder values in Rev’s Hardware Client and/or a way to fix this in WPILib Java?

Position Factor: 6.2831854820251465 (rad)
Velocity Factor: 0.10471975803375244 (rad/sec)
Zero Offset: 1.6548365 (should be in radians)

Here is the command that moves my arm in my code:

  //TODO: Do I need to add an offset to the setpoint?
  public void moveArm(double setpoint) {

    double FFvoltage = m_armFeedforward.calculate(setpoint, 0);

    // Leave pidSlot at 0
    m_armPIDController.setReference(setpoint, CANSparkMax.ControlType.kPosition, 0, FFvoltage,
        SparkPIDController.ArbFFUnits.kVoltage);

  }

Thanks for your help :slight_smile:

1 Like

There isn’t a way to change the range of values that the through bore encoder natively produces in absolute mode, however, you should be able to use MathUtil.angleModulus(double angleRadians) to achieve the desired effect.

Or pull the encoder off, rotate the bore by your desired multiple of 60°, and put the encoder back.

1 Like

We are also in the same situation. Hoping to try out viggy96’s answer

We ended up zero-ing the encoder at a position that the robot can never get too (too low) and based our Setpoints off of that (eg: low point = 0.04, high point = 2.5). Please LMK if this helps or you get viggy96’s strat working :smiley:

1 Like