We’re using the Ultrasonic rangefinder on a V5 cortex and can’t seem to get it to display or use the correct values. If we put the call to get the value and have it display on the screen in cm we get a 3 digit number, so 30cm will display as 300, if we put mm we get a 4 digit number and while the brain seems to be updating it in the while loop it isn’t being used to trigger any if statements or working as while loop exits etc. Even putting something like
while(true){
if(value<300){
move
}
}
Even when the sonar is displaying and updating a value shown as 200 we get nothing. It will also load at 0 triggering some functions that are only supposed to get called when the sonar is less than a certain value.
First it is just the V5. The cortex is not a general term for the robot brains, it is the one specific one. Second, what coding platform are you using (PROS, VCS, Robotmesh, etc). If you are using PROS and the move is meant to move a motor like I think it is, then you need to say
motor.move(127);
In order for it to do anything, besides also declaring the motor somewhere. That could contribute to nothing happening. I haven’t personally used the ultrasonic in V5 but the values could just be how you declare the sensor and the problem is in the code which is why you are seeing nothing.
This is just a consequence of how VEXos and the legacy ports work. The legacy ports don’t start sending data until the program is running. The memory where their results will go is initialized to 0’s, so if you read from them before they’ve had a chance to deliver their first report you will just see that initial 0. The solution is usually just to ensure that there’s some delay before trying to read from them after the program starts.