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.