Vision sensor Problem (Help needed)

Hi so I wanted to write a code to make a robot follow a cube until is close enough to pick it up with an elevator-like lift. I wrote a code looking through some forums and this is what it came out of:

// ----------------------------------------------------------------------------
//                                                                            
//    Project:                                               
//    Author:
//    Created:
//    Configuration:        
//                                                                            
// ----------------------------------------------------------------------------

// Include the V5 Library
#include "vex.h"

// Allows for easier use of the VEX Library
using namespace vex;

// Begin project code

#define TARGET  150

void preAutonomous(void) {
  // actions to do when the program starts
  Brain.Screen.clearScreen();
  Brain.Screen.print("pre auton code");
  wait(1, seconds);
}


void userControl(void) {
  Brain.Screen.clearScreen();
  // place driver control in this while loop
  while (true) {
    wait(20, msec);
  }
}


void autonomous(void) {
 
  Brain.Screen.clearScreen();
  Brain.Screen.print("autonomous code");
  Brain.Screen.newLine();

  Brain.Screen.print("Initializing...");
    Drivetrain.setDriveVelocity(50,percent);
    Drivetrain.setTurnVelocity(50,percent);
    Lift.setVelocity(50,percent);
    Brain.Screen.newLine();
    task::sleep(100);

    int numberObjects = Visor.takeSnapshot( SIG_1 );

    while(1) {

    if( numberObjects > 0 ) {
      // make a copy
      vex::vision::object obj = Visor.objects[0];


        if (obj.centerY > (TARGET-15) && obj.centerY < (TARGET+15)) {
          Brain.Screen.printAt( 10, 20, "Object detected     ");
          Drivetrain.driveFor(forward,10,inches);
          Lift.spinFor(forward,150,degrees);
          Drivetrain.turnFor(right,90,degrees);
        }
        else {
          Brain.Screen.printAt( 10, 20, "no color detected");          
        }

        // Allow other tasks to run
        this_thread::sleep_for(10);
    }


  // place automonous code here
}

}

int main() {
  // create competition instance
  competition Competition;
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(userControl);

  // Run the pre-autonomous function.
  preAutonomous();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

also I have a problem about “int numberObjects = Visor.takeSnapshot( SIG_1 );|int numberObjects = Visor.takeSnapshot( SIG_1 );” it says it’s an undeclared function.

Do you have an instance of the vision class called “Visor” ?
(and why is this urgent ?)

3 Likes

No it’s the name of the vision sensor

Well, I can’t tell just from the code above, zip up (if you are using pro) and attach the whole project.

2 Likes

Yea I attached the whole project and it’ in vexcode V5, not the pro version

No, all you did was paste the user code, there’s no config information in what you had posted.
Attach the .v5cpp file so I can open it in VEXcode and see how you have configured the robot.

3 Likes

Oh ok sure but were do I find that, I mean in the old v5 pro text it was easy but now I don’t know where to look, I can also just write a brief description:

Lift: motor at port 11

Drivetrain: drivetrain with 4 wheels port 20 | 13, 10 | 1

Controller1: a controller

Visor: a vision sensor

ok, well, the only thing I can think of is that in VEXcode the signature names are sort of strange (a good reason to be using Pro). So, if the vision sensor is configured and a signature set in the vision utility called SIG_1, in VEXcode the automatic configuration will add the name of the sensor in front (in case there is more than one vision sensor). So perhaps try this.

    int numberObjects = Visor.takeSnapshot( Visor__SIG_1 );

3 Likes

Oh yea ok now I get that, thanks for the help, and also if you could help me with one more thing, do you know how to tell a drivetrain to go forward until it touches the ball or it comes really close, (apart from using an other sensor).

I would say that would would look at object size and stop when the area of the object is above a certain value.

1 Like

Do you have a sample code for that or some tips for you know implementing it in an if command?

I do not have any sample code.
VEXcode includes at least one vision sensing example, you will see that an object has width and height properties, calculate the objects area and compare that to a constant that you will need to figure out based on how you robot is built and what objects you are using.

3 Likes

Ok so I can tell for example if you exceed this volume you are near enough to the ball/cube? ( and also I just saw that you asked me why it’s so urgent, I have a deadline that is on Monday).