Line follower value printed to V5 brain screen doesn't match value shown in device info

Had an piece of code in Vexcode V5 Python that was essentially this:

while 1==1:
if line_follower.reflectivity(PERCENT) <27:
turn a motor on and do some other stuff

When we would run the code we could look on the brain under the device info section that has a live display of all currently monitored sensors. Ours had an analog value (can’t remember what) and next to it a percent. When we place a white marble in front of the line follower it always goes lower than 27%, but the commands inside the if statement would not run.

I decided to print the value to the screen to test, so right above the if statement I inserted the line: brain.screen.print(line_follower.reflectivity(PERCENT). It started printing out 70 over and over again, then when we put the white marble in front it printed 81. I adjusted the if statement to account for this and it worked and ran the code inside.

So if line_follower.reflectivity(PERCENT) == 81, why would the percentage be 24% or 25% when looking at the device info for that sensor on the brain? Why are these things different?

Anyone know why these would be different? Thanks.

The devices screen doesn’t know what the sensor is, all it knows is it’s an analog sensor, it displays percentage of the full range that the analog value can be.

The VEXcode class understands the best way to turn the raw analog value into reflectivity, a lower raw analog value means more reflective.

2 Likes

This makes sense. So I would prefer to use the actual analog values that are being registered instead of the percent. I have seen ways to do this in C++ using value(analogUnits::range12bit) but can’t quite seem to find the right syntax using Python. Is this possible in the Python text version of Vexcode?

There should be a value() function that will return raw values, you can pass PERCENT as an argument.

2 Likes

This is what I was looking for. line_follower.value() does return the raw value. Thanks!