How to program the vision sensor

We are trying to add a ball sorting program to our existing program and need some help. We have it set up to eject the ball out the back if it is the wrong color ball.

Our current program is

//Intake
void whenControllerL2Pressed() {
RightIntake.spin(forward);
LeftIntake.spin(reverse);
waitUntil(!Controller1.ButtonL2.pressing());
RightIntake.stop();
LeftIntake.stop();
}

void whenControllerL1Pressed() {
RightIntake.spin(reverse);
LeftIntake.spin(forward);
waitUntil(!Controller1.ButtonL1.pressing());
RightIntake.stop();
LeftIntake.stop();
}
//Tower
void whenControllerR1Pressed() {
TowerBack.spin(forward);
TowerFront.spin(forward);
waitUntil(!Controller1.ButtonR1.pressing());
TowerBack.stop();
TowerFront.stop();
}

void whenControllerR2Pressed() {
TowerBack.spin(reverse);
TowerFront.spin(forward);
waitUntil(!Controller1.ButtonR2.pressing());
TowerBack.stop();
TowerFront.stop();
}

// Initializing Robot Configuration. DO NOT REMOVE!
int main() {
vexcodeInit();

RightIntake.setStopping(hold);
LeftIntake.setStopping(hold);
RightIntake.setVelocity(80, percent);
LeftIntake.setVelocity(80, percent);
TowerBack.setStopping(hold);
TowerFront.setStopping(hold);
TowerBack.setVelocity(150, percent);
TowerFront.setVelocity(150, percent);

Controller1.ButtonL1.pressed(whenControllerL1Pressed);
Controller1.ButtonL2.pressed(whenControllerL2Pressed);
Controller1.ButtonR1.pressed(whenControllerR1Pressed);
Controller1.ButtonR2.pressed(whenControllerR2Pressed);

while (true) {
LeftFront.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value() + Controller1.Axis1.value())/2, velocityUnits::pct);
RightFront.spin(directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis4.value() - Controller1.Axis1.value())/2, velocityUnits::pct);
LeftBack.spin(directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis4.value() + Controller1.Axis1.value())/2, velocityUnits::pct);
RightBack.spin(directionType::rev, (Controller1.Axis3.value() + Controller1.Axis4.value() - Controller1.Axis1.value())/2, velocityUnits::pct);
}
}

If someone could help us add the programing to the vision sensor, that would be appreciated.

The code formatted:

//Intake
void whenControllerL2Pressed() {
RightIntake.spin(forward);
LeftIntake.spin(reverse);
waitUntil(!Controller1.ButtonL2.pressing());
RightIntake.stop();
LeftIntake.stop();
}

void whenControllerL1Pressed() {
RightIntake.spin(reverse);
LeftIntake.spin(forward);
waitUntil(!Controller1.ButtonL1.pressing());
RightIntake.stop();
LeftIntake.stop();
}
//Tower
void whenControllerR1Pressed() {
TowerBack.spin(forward);
TowerFront.spin(forward);
waitUntil(!Controller1.ButtonR1.pressing());
TowerBack.stop();
TowerFront.stop();
}

void whenControllerR2Pressed() {
TowerBack.spin(reverse);
TowerFront.spin(forward);
waitUntil(!Controller1.ButtonR2.pressing());
TowerBack.stop();
TowerFront.stop();
}

// Initializing Robot Configuration. DO NOT REMOVE!
int main() {
vexcodeInit();

RightIntake.setStopping(hold);
LeftIntake.setStopping(hold);
RightIntake.setVelocity(80, percent);
LeftIntake.setVelocity(80, percent);
TowerBack.setStopping(hold);
TowerFront.setStopping(hold);
TowerBack.setVelocity(150, percent);
TowerFront.setVelocity(150, percent);

Controller1.ButtonL1.pressed(whenControllerL1Pressed);
Controller1.ButtonL2.pressed(whenControllerL2Pressed);
Controller1.ButtonR1.pressed(whenControllerR1Pressed);
Controller1.ButtonR2.pressed(whenControllerR2Pressed);

while (true) {
LeftFront.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value() + Controller1.Axis1.value())/2, velocityUnits::pct);
RightFront.spin(directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis4.value() - Controller1.Axis1.value())/2, velocityUnits::pct);
LeftBack.spin(directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis4.value() + Controller1.Axis1.value())/2, velocityUnits::pct);
RightBack.spin(directionType::rev, (Controller1.Axis3.value() + Controller1.Axis4.value() - Controller1.Axis1.value())/2, velocityUnits::pct);
}
}

Also, what are you trying to accomplish and what have you already tried? Based on your code, there is nothing on the vision sensor.

2 Likes

We are trying to have the vision sensor trigger a line of code (that will make the tower motors spin) when it sees are certain color ball (Red or Blue). We have to create the code for the vision sensor, all we have done is configure it.

I have recently answered a question about Vision Sensor with a list of resources, that you may find useful:

1 Like