NOTE: It is supposed to be SIG_YELLOW but it is set to SIG_1 so the code doesn’t give an error.
/----------------------------------------------------------------------------/
/* /
/ Module: main.cpp /
/ Author: C:\Users\vexrobotics /
/ Created: Tue Jan 25 2022 /
/ Description: V5 project /
/ /
/----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// VisionSensor vision 1
// FL motor 12
// FR motor 11
// BL motor 14
// BR motor 13
// ---- END VEXCODE CONFIGURED DEVICES ----
#include “vex.h”
using namespace vex;
#include “robot-config.h”
competition Competition;
int centerFOV = 158;
int offsetX = 15;
int hw = 0;
int h = 0;
int w = 0;
void movement()
{
h = VisionSensor.objects[0].height;
w = VisionSensor.objects[0].width;
hw = h*w;
while(true)
{
Brain.Screen.clearLine();
VisionSensor.takeSnapshot(VisionSensor__SIG_1);//THIS HAS BEEN CHANGED SO THAT IT DOESNT THROW ERRORS. IT IS ACTUALLY SIG_ YELLOW
if(VisionSensor.largestObject.exists)
{
if(VisionSensor.largestObject.centerX > centerFOV + offsetX)//If the object is to the left then turns right
{
FL.spin(forward, 100, percent);
FR.spin(forward, 100, percent);
BL.spin(reverse, 100, percent);
BR.spin(reverse, 100, percent);
}
}
else if(VisionSensor.largestObject.centerX < centerFOV - offsetX) // If the object is to the right then turn left
{
FL.spin(reverse, 100, percent);
FR.spin(reverse, 100, percent);
BL.spin(forward, 100, percent);
BR.spin(forward, 100, percent);
//Spin Motors
}
else
{
FL.setVelocity(0,percent);
BL.setVelocity(0,percent);
FR.setVelocity(0,percent);
BR.setVelocity(0,percent);
}
if(hw > 53172)
{
FL.spin(forward, 100, percent);
FR.spin(forward, 100, percent);
BL.spin(forward, 100, percent);
BR.spin(forward, 100, percent);
}
else
{
FL.setVelocity(0,percent);
BL.setVelocity(0,percent);
FR.setVelocity(0,percent);
BR.setVelocity(0,percent);
}
}
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
while(true)
{
movement();
wait(150, msec);
}
}