Hello there, we are currently working with a V5 vision sensor, and we seem to be having some issues with it giving us data. We wanted to detect a yellow goal, and have our robot be able to drive towards it consistently, we do this using a while loop in a function to adjust our path accordingly. In our code, we have it print out data from the vision sensor for the centerX position and width of the largest object in the terminal. We have played around with it to print out whether or not it even registers a largest object in the vision sensors field but it comes back with zeros in every single catagory of data. We have tried taking a snapshot before reading the data but it still comes back as zero. We can’t seem to find anything relating to this issue anywhere.
To calrify:
YELLER is the name of the color we are reading
Not the best at coding, but try putting all the code in the while loop, this makes sure that it’s always checking for the object.
Here’s what it should look like:
// always updates values
while( true) {
visionSensor.takeSnapshot(YELLER);
// this checks if the goal is there, 0 means the largest object in the field of vision
if (visionSensor.objects[0].exists) {
// define and update variables
int CenterX = visionSensor.largestObject.centerX;
int width = visionSensor.largestObject.width;
//prints out whatever stats you want as long as the goal exists.
cout << "CenterX: " << CenterX << endl;
cout << "Rvel: " << Rvel << endl;
cout << "Lvel: " << Lvel << endl;
cout << "Width: " << width << endl;
}
else {
cout << "no object found \n";
We thought you might be on to something because we did have this in a while loop. Here is our code now and we’re still getting the same results where Exists, Width and CenterX are always zero. We’ve confirmed that “YELLER” is being seen by the sensor.
int x=1;
while (x<500)
{
visionSensor.takeSnapshot(YELLER);
int CenterX = visionSensor.largestObject.centerX;
int width = visionSensor.largestObject.width;
cout << "Exists? " << visionSensor.largestObject.exists << endl;
cout << "CenterX: " << CenterX << endl;
cout << "Width: " << width << endl;
x += 1;
vex::task::sleep(20);
}
If you’re still getting 0 then maybe try printing to the brain screen instead of the terminal? That’s usually how I track variables. Something like
if (centerx != 0) {
print out centerx
}
in your while loop
Also visionSensor.largestObject.exists should be a boolean value, weird that it’s printing 0. Can you double check that everything is configured correctly?