Does the v5 rotation sensor need any time to initialize?

@jpearman: James, sorry to bother you, quick question:
Does the v5 rotation sensor need any time to initialize or run something in firmware first? I am asking because we noticed that if reading the angle from sensor is among the first instructions to execute sometimes (no pattern observed) the value returned is 0. With a small system sleep it seems to be consistent so far. We use it to set a reference point for a lift. Someone had an idea to put some error checking code that loops until a good value is read (zero is not something we want because weird math things happen at the 0/360 point so we simply offset by 10 or so degrees). But curious if the sensor needs that split second to come to life or something else going on with our system. Thanks as always.

1 Like

Here is documentation on the Rotation sensor then use this link:

The angle is determined absolutely and is not lost when the robot is powered off.

1 Like

Rotation sensor (V5 Rotation Sensor - VEX Robotics). Thanks for links. Did not find answer though. Angle is indeed stored. However, if we read the sensor too fast (like the very first line of code after the inits) then sometimes the value read is just 0, so we were wondering if this is happening because the sensor did not have time to wake up and respond properly. Thanks.

3 Likes

I misread your question initially but I would think that it may take a few ms for the processor to start reading values from the sensors. You may experiment with an initialization queue in your pre-auton.

1 Like

Yeah, doing that, we just have a while loop that exits when all our read values are within normal (no NULLS etc…)

1 Like

yes, we send a reset signal to the rotation sensor when user code starts, there’s approximately a 20mS delay before valid data is received after that. You could either just add that fixed delay at the code start or use the protected class function status to determine that data is valid. status usually will have bit 15 set when data is valid after a reset, other status bits may indicate sensor error and are not usually needed by end user code. you will need to subclass the rotation class to use status(), for example.

class rotation_x : public vex::rotation {
    public:
      rotation_x( uint32_t index ) : vex::rotation(index) {}
      ~rotation_x() {}

      uint32_t status() {
        return rotation::status();
      }
};

rotation_x  enc(PORT20);

int main() { 
    printf("start\n");

    // wait for valid data
    while( (enc.status() & 0x8000) == 0 ) {
        this_thread::sleep_for(10);
    }

    printf("angle %.1f\n", enc.angle() );
}
8 Likes

Oh thank you so much! Completely forgot most V5 sensors report their status.

1 Like