Rev Through Bore Encoder in Absolute and Incremental Mode

I am trying to use the Rev Through Bore Encoder in Absolute Mode for seeding a position and then use it in Incremental mode as the the feedback device for the SparkPIDController. This is what I have below. Is this even possible using the REVLib API and if so am I doing it correctly?

SparkPIDController wrist_controller_;
RelativeEncoder wrist_encoder_;

double abs_wrist_offset = tareWristEncoder();
wrist_motor_ = new CANSparkMax(ShooterConstants.WRIST_MOTOR_ID, CANSparkLowLevel.MotorType.kBrushless);
wrist_motor_.setInverted(true);
wrist_motor_.setIdleMode(IdleMode.kBrake);
wrist_controller_ = wrist_motor_.getPIDController();
wrist_encoder_ = wrist_motor_.getAlternateEncoder(8192);
wrist_encoder_.setPosition(abs_wrist_offset);
wrist_controller_.setFeedbackDevice(wrist_encoder_);
wrist_controller_.setP(ShooterConstants.WRIST_CONTROLLER_P);
wrist_controller_.setD(ShooterConstants.WRIST_CONTROLLER_D);

private double tareWristEncoder(){
    CANSparkMax abs_wrist_motor_ = new CANSparkMax(ShooterConstants.WRIST_MOTOR_ID, CANSparkLowLevel.MotorType.kBrushless);
    double abs_wrist_offset = abs_wrist_motor_.getAbsoluteEncoder(SparkAbsoluteEncoder.Type.kDutyCycle).getPosition() * 8192;
    abs_wrist_motor_.restoreFactoryDefaults();
    abs_wrist_motor_.close();
    return abs_wrist_offset;
}

You can’t use the through bore encoder in both modes, since there is a physical switch on the encoder to switch between modes.

I believe that is the case if you use the Encoder Adapter Board Alternate Encoder Adapter - 2 Pack - REV Robotics but we are using the Data Port Breakout Board SPARK MAX Data Port Breakout Board - REV Robotics

But the encoder itself has a switch on it, and it needs to be physically switched to be in either absolute or relative mode. I don’t think that changes even if you use the data breakout board.

Also, does your mechanism rotate more than one full rotation? If not, you can simply keep the encoder in absolute mode, and use that for feedback. And you can use the REV software (the hardware client) to zero the absolute encoder in whatever position you wish.

1 Like

The switch isn’t for in-field use, it is setup for SSI/SPI when you put it in the ‘S’ mode. the ‘A’ mode will output both the A, B and ABS on the cable bundles, you just need to use the appropriate PIN/adaptor board depending on if you are using the RIO direct or via the SparkMax (and in theory other motor controller as well).

1 Like

Oh I see interesting, I learned something today.

We want to be able to seed the starting position using absolute and run our controller using incremental for faster data reads.

The absolute is capable of running plenty fast, I’ve never had an issue with using it directly for onboard PID feedback for a positional mechanism.

1 Like

You can also increase the frequency of the appropriate CAN status message to get the updated position of the encoder more often. But since the Spark is directly connected to the encoder it can read the sensor on its own plenty fast, it just reports on the CAN bus at a slower rate.

I’ve never actually looked at all the output pins on the encoder but if they are just passing the same signal straight out from the chip (after buffering), you should absolutely be able to use the Index and the A/B at the same time. Will have to do some programming to use the Index as a reference point and then the A/B on top.

Can grab the application note off their website and look at the signal outputs -

I should just be able to use these two connection modes to use both encoder readings at the same time. The A B goes to the controller and ABS to the RIO. In REVs explanation video they described that teams could plug in all 4 cables depending on their use case.


You should but be careful your use-case and the differences in timing. i.e. things coming over the CAN bus will have to be part of the CAN refresh or if you are using it as any sort of PID on the SparkMax, then that sampling will also be a lot faster. {unfortunately we never done any sort of split use like this, there’s certainly a lot of information to be learned here}.

Good Luck.

Not sure I understand why you need to do this? Have you experienced specific issues with using the absolute mode directly as your PID feedback?

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