I have it so that when the distance sensor finds something within 15 centimeters it calls a function, but sometimes it’ll call that function even when there is nothing in front of the sensor at all.
Is this noise from the sensor?
Is it returning some negative value because it can’t find the distance to anything?
It is closing correctly when something gets close, it just closes randomly other times too.
I think, more likely than not, it is something in the program that’s causing this issue. While sensors can be inconsistent, I don’t think they’re that inconsistent. It might be a hardware issue with just the sensor. Assuming the sensor is perfectly fine, it’s probably the code. Also, if you’re in VRC, consider looking into the Kalman filter, it helps make data readings more accurate.
So, troubleshoot and narrow the ends down.
print the values on the screen so you know what they are. IIRC the V5 distance sensor still reports 0 when nothing is in range, that’s probably what you are seeing.
I tried to do that but I always get this weird flashing on the controller lcd that I can never seem to make it just stay there while the numbers change.
Chances are it’s the 0 so thank you.
I will check tomorrow.
Which programming environment ?
VEXcode, VEXcode Pro, PROS ?
Text, C or Python, blocks ?
the issue is fixed now I just made it also check if the distance is greater than 1