We tried to code a distance sensor for our v5 robot so that we can stop the motors when the robot is close to the goal. However, we did not see a command to execute something when the sensor was a certain distance away.
Plz help
Sending your code will help
Which programming language are you using?
v5 pro text, i think
for VRC
you’ll have to write your own execution code in this case. Here is an example pseudocode
while(true){
if(distance sensor reading smaller than 5cm){
break
}
motor move with power 127;
}
generally, vex sensors only give feedback based on the data collected (ex. encoder degree, distance). What to do with those sensor data is completely up to you. You’ll have to implement everything else.
I looked at what commands were available in the library, and it only can register if it sees something or not. I checked everything, but there is no command to see how far something is, and i don’t see anywhere to get feedback on what it sees.
double vex::distance::objectDistance(distanceUnit units) should be what you’re looking for. For example, do smthn like this:
double dist = distSensor.objectDistance(mm);
thanks! ill try it out and let you know if it works!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.