There still seems to be some issues setting up the vision sensor. Although we do know that VCS 1.0/vision sensor utility has a few bugs in this area, it is still pretty simple, I’m not sure why the theories about needing to freeze the image are running around. Anyway, here’s a quick demo showing how easy it is.
The configuration that is hidden inside robot-config.h looks like this and is what is used in your program to setup the vision sensor when it runs.
vex::vision::signature SIG_1 (1, -1397, -737, -1068, 3495, 4711, 4102, 3, 0);
vex::vision::signature SIG_2 (2, 4557, 5491, 5024, 537, 1301, 920, 3, 0);
vex::vision::signature SIG_3 (3, 0, 0, 0, 0, 0, 0, 3, 0);
vex::vision::signature SIG_4 (4, 0, 0, 0, 0, 0, 0, 3, 0);
vex::vision::signature SIG_5 (5, 0, 0, 0, 0, 0, 0, 3, 0);
vex::vision::signature SIG_6 (6, 0, 0, 0, 0, 0, 0, 3, 0);
vex::vision::signature SIG_7 (7, 0, 0, 0, 0, 0, 0, 3, 0);
vex::vision Vision1 (vex::PORT1, 50, SIG_1, SIG_2, SIG_3, SIG_4, SIG_5, SIG_6, SIG_7);
Here’s a screen grab of the output of the demo code I used.
and here is the code I was using, it’s just a slightly different version of demo code I’ve posted in the past.
#include "robot-config.h"
using namespace vex;
int screen_origin_x = 150;
int screen_origin_y = 20;
int screen_width = 316;
int screen_height = 212;
// function to draw a single object
void
drawObject( vision::object &obj, vex::color c ) {
int labelOffset = 0;
Brain.Screen.setPenColor( vex::color::yellow );
Brain.Screen.drawRectangle( screen_origin_x + obj.originX, screen_origin_y + obj.originY, obj.width, obj.height, c );
Brain.Screen.setFont( vex::fontType::mono12 );
if( obj.originX > 280 )
labelOffset = -40;
if( obj.originY > 10 )
Brain.LCD.printAt( screen_origin_x + obj.originX + labelOffset, screen_origin_y + obj.originY-3, "Sig %o", obj.id );
else
Brain.LCD.printAt( screen_origin_x + obj.originX + labelOffset, screen_origin_y + obj.originY+10, "Sig %o", obj.id );
}
// function to draw all objects found
void
drawObjects( vision &v, vex::color c, bool clearScreen ) {
if( clearScreen ) {
Brain.Screen.setPenColor( vex::color::black );
Brain.Screen.drawRectangle( screen_origin_x, screen_origin_y, screen_width, screen_height, vex::color::black );
}
for(int i=0;i<v.objectCount;i++)
drawObject( v.objects[i], c );
}
int main() {
// Draw an area representing the vision sensor field of view
Brain.Screen.clearScreen( vex::color::black );
Brain.Screen.setPenColor( vex::color::green );
Brain.Screen.drawRectangle( screen_origin_x-1, screen_origin_y-1, screen_width+2, screen_height+2 );
while(1) {
// request any objects with signature 1
int numberObjects = Vision1.takeSnapshot( SIG_1 );
Brain.Screen.setPenColor( vex::color::white );
Brain.Screen.setFont( mono20 );
Brain.Screen.setCursor( 2, 2 );
Brain.Screen.print( "Sig 1 %2d", (int)numberObjects );
// draw any objects found
drawObjects( Vision1, vex::color::blue, true );
// request any objects with signature 2
numberObjects = Vision1.takeSnapshot( SIG_2 );
Brain.Screen.setPenColor( vex::color::white );
Brain.Screen.setFont( mono20 );
Brain.Screen.setCursor( 3, 2 );
Brain.Screen.print( "Sig 2 %2d", (int)numberObjects );
// draw any objects found
drawObjects( Vision1, vex::color::red, false );
// run 10 times/second
this_thread::sleep_for(100);
}
}