Rotation Sensor reading value that are way off

Okay, so I’m working on implementing a rotation sensor for tracking my ladybrown position. When I run the code to move it, the arm maxes out it’s movement and tries to keep going. I have the code outputting readings to the brain, and while the target is correct, every other position is either -4194304 or INT_MAX. what might be the issue here? code below.

void armToPosition(double target) {
    double targetPosition = target * 100; // e.g., 4500
    double currentPosition = armEncoder.get_angle();
    int direction = (targetPosition < currentPosition) ? 1 : -1;

    pros::lcd::print(0, "Start: %d", currentPosition);
    pros::lcd::print(1, "Target: %d", targetPosition);
    pros::lcd::print(2, "Dir: %d", direction);

    //arm_motor.move_voltage(6000 * direction);

    while (fabs(armEncoder.get_angle() - targetPosition) > 100) {
        pros::lcd::print(3, "Pos: %d", armEncoder.get_angle());
        pros::lcd::print(4, "Error: %d", (armEncoder.get_angle() - targetPosition));
        pros::delay(10);
    }

    arm_motor.move_voltage(0);
    pros::lcd::print(5, "Stopped: %d", armEncoder.get_angle());
}

EDIT: I know that the move command is commented, out, we did that to rotate the arm and check encoder values, which all read the same as what I specified.

Are you sure you setup the armEncoder correctly? That reminds me of the error I had when I accidentally setup the sensor on the wrong port.

1 Like

we did double-check the port setup, yes. The encoder is set to Port 1 in the programming and is hooked up to port 1 on the brain. I do have the port reversed in the constructor, could that be the problem?

Based on PROS 4 Documentation for the Rotation Sensor:

get_angle returns “The angle value or PROS_ERR if the operation failed, setting errno”
PROS_ERR is equal to INT_MAX, or 2147483647, which aligns with your findings.

Therefore, your issue is most likely one of the following:
ENXIO - The given value is not within the range of V5 ports (1-21).
ENODEV - The port cannot be configured as an Rotation Sensor

Try checking the Rotation Sensor on the “Devices” section of your brain and see if it shows expected values.

the rotation sensor on the brain shows up and does show the expected values, and it is worth noting that I use PROS 3.8.3

It doesn’t look like much has changed in the front-facing API of the get_angle function from PROS 3 to 4 (PROS 3 documentation for reference).

Could you try printing the value of PROS_ERR right after you receive the return value of get_angle()? If it is equal to ENXIO (6) or ENODEV (19), then you have a bit more information to go after.