Trouble with spark max encoder

our team uses victor spx motor controllers and during comp we used one borrowed talon so we could use an encoder, we decided to use one of our 2 sample spark maxes we have saved to replace the talon and used the same vex mag encoder with the CTRE encoder housing. i copied all the robot.java code from the example code for an alternate encoder given here by rev, but when it comes to implementing the encoder data into our arm’s limit i keep getting the fatal problem

Type mismatch: cannot convert from RelativeEncoder to double on
return m_motor.getAlternateEncoder(4096)

(line 48 of thiscode)

i have tried everything i know to try and cannot find anyone else who has this issue. any help is appreciated.

You have to initiate the encoder object RelativeEncoder, we do it in the constructor. Currently, you are comparing the encoder object to a double causing the error. In your getter, you should be returning a double to compare against, using getPosition() or getVelocity().

RelativeEncoder m_encoder;
public arm() {
m_encoder = m_motor.getAlternateEncoder(4096);
}

private double getAlternateEncoderPosition() {
return m_encoder.getPosition();
}
1 Like

In moveArm, where you call getArmEncoder(), you probably want something like getArmEncoder().getPosition().

what file/class would i need to put

RelativeEncoder m_encoder;
public arm() {
m_encoder = m_motor.getAlternateEncoder(4096);
}

in

so like this

public double getArmEncoder() {
    return m_motor.getAlternateEncoder(4096).getPosition();
}