Capten
October 21, 2020, 9:45pm
#1
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?
void usercontrol(void) {
OpticalSensor.setLightPower(100, percent);
OpticalSensor.setLight(ledState::on);
while (1) {
if(OpticalSensor.color() == blue){
TopMotor.spin(reverse);
BottomMotor.spin(forward);
}
wait(20, msec);
}
}
https://api.vexcode.cloud/v5/html/classvex_1_1color.html
Just shooting in the dark, perhaps you need to say color::blue? Does the program give any errors?
2 Likes
Capten
October 21, 2020, 9:57pm
#3
No, there’s no errors in the program, but on the brain it says “Jump Table Error”
While programming sensors, the brain keeps displaying “jump table error.” My team and I were wondering what this meant and how to fix it
I loaded the example Accurate Turns(Inertial Sensor) with VexCode 1.0.3 19.121916 into a B1(VEXos 1…0.7) and get thevJump Table Error 03800EE8. I tried a second B1 and second sensor and got the same Error. I tried the sensor code lines in another program and got another Jump Code Error 038019F8.
I must be missing something simple.
2 Likes
then you need to update vexos to 1.0.12 and make sure you are running the latest version of VEXcode.
8 Likes
Capten
October 21, 2020, 9:59pm
#6
Okay, thank you, I will do that immediately
Capten
October 26, 2020, 8:27pm
#7
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);
}
}
74656A
October 26, 2020, 8:33pm
#8
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.
1 Like
Capten
October 26, 2020, 8:39pm
#9
What was the code part for? It’s literally exactly the same
74656A
October 26, 2020, 8:40pm
#10
Yea, idk why it quoted like that
Capten
October 26, 2020, 8:41pm
#11
Well I moved it to before the “while” part and more errors showed up
74656A
October 26, 2020, 8:42pm
#12
try moving to the part before void usercontrol(void) so that when you are calling the function, its not in void usercontrol(void)
Capten
October 26, 2020, 8:45pm
#13
Ah yes, no errors now. Thank you. I will see if it will work now
74656A
October 26, 2020, 8:45pm
#14
No problem
(20 Characters)
Capten
October 26, 2020, 8:58pm
#15
For some reason, the program doesn’t sense the color. It runs the same program for blue that it does red.
void blueball(void) {
TopMotor2.spinFor(fwd, 1300, degrees, false);
TopMotor.spinFor(fwd, 1300, degrees, false);
}
void redball(void) {
TopMotor2.spinFor(fwd, -1300, degrees, false);
TopMotor.spinFor(fwd, 1300, degrees, false);
}
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);
}
if(OpticalSensor.color() == red){
OpticalSensor.objectDetected(redball);
}
wait(20, msec); return; } }
74656A
October 26, 2020, 9:01pm
#16
try using an else if statement for sensing red rather than using another if statement. That way, no repetition is possible.
Capten
October 26, 2020, 9:08pm
#17
I tried that, this is the new program we would actually use. Now nothing happens.
void blueball(void) {
}
void redball(void) {
TopMotor2.spinFor(fwd, -1300, degrees, false);
TopMotor.spinFor(fwd, 1300, degrees, false);
}
void usercontrol(void) {
OpticalSensor.setLightPower(100, percent);
OpticalSensor.setLight(ledState::on);
TopMotor.setVelocity(100, percent);
TopMotor2.setVelocity(100, percent);
while (1) {
if(OpticalSensor.color() == red){
OpticalSensor.objectDetected(redball);
}
else if(OpticalSensor.color() == blue){
OpticalSensor.objectDetected(blueball);
}
wait(20, msec); return; } }
Capten
October 26, 2020, 9:11pm
#18
Okay I fixed that. But now it’s just not sensing color, I have no program for blue ball and it still runs
Don’t use event registration calls in a loop.
while (1) {
if(OpticalSensor.color() == red){
OpticalSensor.objectDetected(redball);
}
else if(OpticalSensor.color() == blue){
OpticalSensor.objectDetected(blueball);
}
just call your two functions directly.
if(OpticalSensor.color() == red){
redball();
}
etc.
2 Likes
Capten
October 26, 2020, 9:17pm
#20
Yeah turns out we dont want anything to happen with the blue ball though, so new program:
void redball(void) {
TopMotor2.spinFor(fwd, -1300, degrees, false);
TopMotor.spinFor(fwd, 1300, degrees, false);
}
void usercontrol(void) {
OpticalSensor.setLightPower(100, percent);
OpticalSensor.setLight(ledState::on);
TopMotor.setVelocity(100, percent);
TopMotor2.setVelocity(100, percent);
while (1) {
if(OpticalSensor.color() == red){
OpticalSensor.objectDetected(redball);
}
else if(OpticalSensor.color() == blue){
TopMotor.stop();
TopMotor2.stop();
}
wait(20, msec); return; } }
But when the blue ball is sensed it still runs.