Devices Screen not showing proper sensor value - lineTracker

Hi,

In a programing course I have used the line sensors to follow lines as an application of conditionals. We have done this successfully in the past by finding the values in the devices menu on the brain screen to find out threshold value, although they were actually the opposing percent (meaning if the devices menu saw 40% it seemed to really be 60%).

This year that is not working. We were able to get the values by printing the sensor value to the brain screen in a simple program, but it did not agree with the devices menu value or its opposing percent, seemingly being unrelated. In the devices menu on the brain we were reading the analog output percent during all of this, as well as the percent from the print to the brain

Has anyone else experienced this or a similar situation where the devices menu did not seem to read correctly? Any thoughts?

As far as I remember there were no changes to the display on the devices screen for the line sensor. There may have been some changes on the user program side as this sensor is used as part of the CTE workcell as an object detector, I’ll check later.

1 Like

Had a look, not seeing any issues. No changes to the line sensor API since 2019.

The devices screen will show the raw analog value as 12 bit (0 - 4095) and also converted to a percentage.

An example

The line sensor’s displayed value in the dashboard will never reach 0 or100%

At one extreme (no ir being detected) it will show approximately 3000 (~70%) at the other (max ir being detected, an object very close) it will show as low as perhaps 100 (~3%).

In the VEXcode line sensor class we usually convert the raw sensor value into a reflectivity range of 0 to 100%. The formula is

    // line sensor seems to output roughly
    // 3000 for no object
    // 100  for reflective white object
    // so use that for approx scaling
    int32_t r = value * 100 / 3000;
    // now we are in range 0 to 100, but it is reversed
    r = 100 - r;
    // limit
    if( r <   0 ) r = 0;
    if( r > 100 ) r = 100;

You still have access to raw values if you want, for example, some C++ code.

vex::line Line1(Brain.ThreeWirePort.A);

int main() {   
    Brain.Screen.printAt(20, 20, "C++" );

    while(1) {
        Brain.Screen.printAt(20,  60, "Reflectivity: %4d", Line1.reflectivity() );
        Brain.Screen.printAt(20,  80, "Value       : %4d", Line1.value(percent) );
        Brain.Screen.printAt(20, 100, "Raw analog  : %4d", Line1.value(analogUnits::range12bit) );

        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}

would show the following on the brain’s screen.

Notice that the raw analog and percentage values are the same as the dashboard shows but reflectivity is set to 10%.

Python code has equivalent functions available.

Block code only allows use of reflectivity, so these blocks

would show 10% on the screen.

Hope this helps.

3 Likes