void lig(int ti,int many) {
//RESET
Brain.Timer.reset();
int lc = 0;
//RUN TILL ONE IS TRUE
while(ti > Brain.Timer.value() || lc < many){
//SPIN
Brain.Screen.clearLine(1,color::black);
Brain.Screen.print("Balls Detected: %f ", lc);
vex::task::sleep(10);
InL.spin(directionType::fwd, 100, velocityUnits::pct);
InR.spin(directionType::fwd, 100, velocityUnits::pct);
roller_top.spin(directionType::fwd, 100, velocityUnits::pct);
roller_bottom.spin(directionType::fwd, 100, velocityUnits::pct);
if(Line.reflectivity() < 1700){
//LOOP TILL THE BALL IS GONE
waitUntil(Line.reflectivity() > 2700);
lc ++;
//COUNT +1
}
}
//YOU ETER HIT THE COUNT LIMET OR THE THE TIMEOUT
//MOTORS OFF YOU ARE DONE
InL.stop();
InR.stop();
roller_bottom.stop();
roller_top.stop();
}
So i’ve been really strugling with this code lately, I am very new to vex code and was wondering if someone could help me with it. Everyone I have asked has not been able to figure it out, when I start the auton the robot just keeps runing the intakes and rollers, and does not add to the ball count like it is supossed to. If you know how to help me or have any ideas it would be greatly apreciated that you.
Based on the symptoms described, it’s getting stuck in the “wait until” and the condition defined is not being met. Maybe check your threshold value for that condition.
vision sensors can sometimes give funky readings so maybe making it a waitUntill(Line.reflectivity()>=2700);
or loosening up the value that it needs to hit as tfriez said.
Correct me if i am wrong but couldn’t you swap out the wait until with an If statement?
I would debug your values. The logic is not doing what you want so you need to see why. In your while loop I would print ti, Brain.Timer.value(), lc, many, and Line.reflectivity(). Then run the program and look to see where a value may be outside of your expectation.
are you using a 3 wire line sensor? or the V5 vision sensor?
the 3 wire line sensor requires that you see the values and tune accordingly and the vision sensor should be able to tell colors(dont quote me on that i havent used it much)
From what we see in the code, it is implied that this is a 3-wire line tracker, but it is worth asking this question. I suspect that the detection values are not correct in this code.
Yes it is a 3 wire line tracker that is being used and we have tuned the values should i go in a area with different lighting and retune the values and try again?
ah there is your problem
that perticular line sensor is pretty sensitive
It will be thrown off by ANY even the slightest changes in lighting. I would not reccomend using this to find the balls and count them. If you have the Vex vision sensor you should be able to use that to the same effect. or alternatively you could use a limit switch to tap each ball as it passes
So I need to disagree a bit. These sensors DO NOT like direct sunlight, however with most indoor lights, they seem to be fairly tolerant. I would first take the advice of @Hudsonville_Robotics. Use the print commands that I have showed you in the past to print out the line reflectivity value and run some balls in to the robot. What does the value do? If it doesn’t change at all, there is a sensor setup issue.
Edit: this opinion was formed by my overusing line trackers for the turning point season. If memory serves, I had at least 4 on my robot.
Sadly, no it does not I am still having the problem of it not counting the ball and the brain timer only works if I take out the balls that I want counted in the auton .