Hey my team is using an optical sensor this season to sense the ball color. I tried to program it myself, but it doesn’t seem to work. Can anyone tell what’s wrong?
So we updated the brain (turns out it was three updates behind) and the program works. Kinda. It worked at first but then stopped right away. Right now there is an error, it says “Use of undeclared identifier, ‘blueball’.” This is the newest version of the program:
void usercontrol(void) {
OpticalSensor.setLightPower(100, percent);
OpticalSensor.setLight(ledState::on);
TopMotor.setVelocity(100, percent);
TopMotor2.setVelocity(100, percent);
while (1) {
if(OpticalSensor.color() == blue){
OpticalSensor.objectDetected(blueball);
}
wait(20, msec);
return;
}
}
void blueball(void) {
TopMotor2.spinFor(fwd, -1000, degrees, false);
TopMotor.spinFor(fwd, 1000, degrees, false);
}
//Callbacks
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
OpticalSensor.objectDetected(blueball);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}
It might be due to the order in which you have the functions. You are defining the blueball function after you call it in where I assume is the user control function. I would move the blueball portion of the code above where you define the usercontrol function.