Which sensor measures how far something is from something?

I am new to VEX and I would like to know which sensor measures how far something is from somehting.

The ultrasonic range finder: https://www.vexrobotics.com/276-2155.html

Thankyou

How would you code the Ultrasonic Range Finder?

Are you using RobotC? There’s sample programs you can use to base your robot code off of.

I am using C++ not C++ pro

Use Sonar.distance(vex::distanceUnits) - this will return the the distance value. More info here

Would the vision sensor work here as well?

Where would you put the distance value in?

If you mean ultrasonic, then yes. Vision is something completely different.

you would plug in the units you want (mm, cm, or in), for example -


while(Sonar.distance(vex::distanceUnits::mm) < someValue)
{
//do something
}

Ok so would this be correct
while(Sonar.distance(vex::distanceUnits::23) <34
{
Backleftmotor.spin(vex::directionType::fwd,100, vex::velocityUnits::pct);
}

And Wouldn’t the while be “if”?

Also for the motion statement that I made above how long would It go for and if I needed multiple motors to move then would i just put those statements?

At the beginning of Auton would I just tell the robot to start so it can start sensing from there?

Sorry for the load of questions.

for vex::distanceUnits::23, change the 23 to mm, in, or cm. Also add another parenthesis after the 34.

It would be a while not an if. An if statement will run once, while a while loop will repeat until the statement is true.

The loop will run until you are within that distance, and if you need more motors to run, add the lines within the brackets.

I don’t know what you mean by “At the beginning of Auton would I just tell the robot to start so it can start sensing from there?”. It should just run if you put it in auton.

This is absolutely incorrect. The vision sensor does not in any way use sonar.

my mistake, i thought he meant ultrasonic. I reread the question and realized my mistake lol. vision is something way different lol

Oh, okay. I thought it could find the range as well as the color of an object, to use for object tracking. My bad.

Yes, depending on what your measuring. If you know the height of the object relative to the surface your robot is on or something similar, then it will work perfectly well to calculate distance. This is true in many cases. Because shapes don’t mess it up so much (like poor sound reflection) and because it can differentiate between different objects, frequently it will be better at determining distance than using ultrasound.

Or, if you really want to do it well, use two vision sensors and triangulate. The you don’t even need to know the height the object is at. You can figure out where it is in three dimensions relative to your robot so long as both cameras can identify the same object.