V5 optical sensor refresh rate

Anyone know the refresh rate of the optical sensor? Need to know how fast the sensor can see a big change in hue (ex. red to blue or blue to red ranges). Thanks.

100ms pretty sure. Would not recommend for stopping the roller at a high speed.

2 Likes

I think it’s 100ms, but the thing is if you roller is moving to fast then it could just mess up the whole thing

The optical sensor will send back data to the the brain every 20mS, however, to make the sensor sensitive enough to light the default integration time is 103mS, that means that normally you will see values change approximately every 100mS. The integration time can be changed in VEXcode as necessary, the relevant APIs are.

      /**
       * @brief set sensor integration time
       */
      void            integrationTime( double timeMs );

      /**
       * @brief get sensor integration time
       */
      double          integrationTime();
8 Likes

Thank you. All makes sense now. 100ms is almost 1/10 of a roller gone out of sight if spun fast.

1 Like

What is the minimum integration time?
Can these be documented with more details? There are other optional configurations that have very little explanation.

Does it only work in VexCode? Tried in VS Code VEX Extension (what our teams programmed in this season) and could not figure out the syntax, in fact nothing with the word “integration” comes up. Is this not implemented or taken out? The VEX Command Help shows significantly less items than listed in the v5 API (with clear understanding that this is still a “preview” version, just trying to figure out where this is heading). Also assuming this is user program level parameter so it is not possible (for us users) to program it into the sensor permanently (as in set it in VexCode C++ then use it with a VS Code program)? Thank you.

Here’s a demo I tested this morning.

code
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       james                                                     */
/*    Created:      11/30/2022, 8:11:43 AM                                    */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "vex.h"

using namespace vex;

// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;

// define the optical sensor
vex::optical     op1(PORT20);

int main() {
    // faster integration time needs more light
    op1.integrationTime(50);
    // turn on LED full power
    op1.setLightPower(100);

    while(1) {
        optical::rgbc rgb = op1.getRgb();

        Brain.Screen.printAt(10, 40,"Hue        : %6.2f", op1.hue() );        
        Brain.Screen.printAt(10, 60,"Brightness : %6.2f", op1.brightness() );   
     
        Brain.Screen.printAt(10,100,"Red        : %6.2f", rgb.red );        
        Brain.Screen.printAt(10,120,"Greeb      : %6.2f", rgb.green );        
        Brain.Screen.printAt(10,140,"Blue       : %6.2f", rgb.blue );        
        // Allow other tasks to run
        this_thread::sleep_for(20);
    }
}

notice that as you make integration time shorter (time steps are somewhere around 3mS so the value you pass will be adjusted to the nearest valid value) the rgb values will decrease. brightness is normalized, you won’t see much change there, hue will become less accurate as rgb values become smaller.

5 Likes

minimum integration time is about 3mS, but not practical to use. maximum is 712mS.

5 Likes

Thank you. Forgot to mention my teams use VEX Extension / Python. Did not find it in the list and could not brute-force the syntax.

yea, it’s a C++ only feature, I’ll look at adding to Python for a future release.

5 Likes

I wish this stuff was explained in the VEX kb/library and/or on the sensor product page. If my teams were aware they would not have spent so much time on making roller spinning code that seems impossible at not very slow speeds using optical sensors. But at least now we know and also went to read about how sensor integration time is used in imaging devices in general. Thank you for teaching us.

3 Likes