In need of coding help

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.

1 Like

Thank you for formatting your code but could you please add punctuation or at least capitalization to your post? It’s a bit hard to read. Thanks!

1 Like

Yeah of course, sorry for that I was in a really big rush to try and get help.

2 Likes

Yeah no worries. Thanks!

1 Like

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.

4 Likes

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’m pretty sure that line.reflectivity() returns percent values. If that is true, you need to change your if and waituntil to percent.

1 Like

I just changed the wait until to a if statement and it still had the same issue.

I also changed the value to percent and had the same issue .

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.

4 Likes

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.

1 Like

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

2 Likes

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.

2 Likes

Ok so i have printed out the sensor values on the screen like you suggested and the value did drop when the ball passed in the auton.

You didn’t share your results. Did the Line.reflectivity() value drop below 1700 and then did it exceed 2700? Did the lc counter increment?

2 Likes

oh i’m so sorry yes when the ball passed by the sensor value varied between 1600 and 1500 and when their was no ball the sensor read 2900.

Is that your desired result? Does this solve your problem?

1 Like

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 .