I have added a vision sensor to my robot and configured two color signature for red and blue balls. The next goal is to use the color signature to automatically sort balls to go to the tower or out the back of the robot. I assume you would the code would look something like this:
if(Vision.Sig1){
put balls into tower
}else if(Vision.Sig2){
send balls out the back
}
I don’t know what the arguments in the if/else statements would be so if someone could provide an example, your help would be much appreciated.
So, the vision get signature function a boolean that says whether or not the signature specified in the function is found. So, assuming that the signature 1 is the color you want to spit out, you would:
if(Vision.takeSnapshot(blue) >= 1){
send balls out the back
}
else{
put balls in tower
}
That’s completely wrong, getSignature does not tell you anything about objects. You need to use takeSnapshot. See the examples included with VEXcode, or perhaps search the forum, here is an old example (written for VCS but should still work).
It lets you read back a signature that was sent to the vision sensor. It has no practical use in VEXcode. You pass it an id and signature instance by reference.
bool getSignature( uint32_t id, signature &sig );
The return value just lets you know that the result is valid.
In the driver control then I would use this code right? I would probably have to define a red and blue uint number to compare to in preaton right?
while(1) {
// request any objects with color code C1
int numberObjects = Vision1.takeSnapshot( C1 );
bool getSignature(uint32_t id, sig1 &sig)
if(id == red){
mainConveyor.spin(forward);
sorter.spin(reverse)
}else if(id == blue){
mainConveyor.spin(forward);
sorter.spin(reverse);
}
// run 10 times/second
this_thread::sleep_for(100);
}
int main() {
int nObjects;
while(1) {
// Allow other tasks to run
this_thread::sleep_for(10);
nObjects = Vision1.takeSnapshot(SIG_BLUE);
if( nObjects ) {
Brain.Screen.printAt( 10, 10, "Blue found ");
// we found a blue object !
continue;
}
nObjects = Vision1.takeSnapshot(SIG_RED);
if( nObjects ) {
Brain.Screen.printAt( 10, 10, "Red found ");
// we found a red object
continue;
}
Brain.Screen.printAt( 10, 10, "Nothing found");
}
}
that’s assuming you have calibrated the vision sensor and named the two signatures SIG_RED and SIG_BLUE like this.