Vex v5 coding query

Wondering about Line Trackers. I’ve seen that they measure “reflectivity” on a measure of 0 to 100 (percent). Our team is attempting to utilize sensors for worlds but this one part of the code I’m struggling with. I’m also wondering about how to return to a previous line of the code

Below is a sample code I came up with (the premise being to move diagonally next to the white diagonal splitting the playing field in two, but if the bot sensor detects the white line up ahead, it’ll move away from the line (preventing us from being disqualified during autonomous mode)

Code Sample

Any advice? (All is appreciated)

You want to use the method LineTrackerA.reflectivity(pct)

There’s no magic solution for returning to a previous line of code; you’ll have to actually program what you want it to do for this method to work. The right way to go about this is to make a control loop which constantly tracks the robot’s position and also the reflectivity of the line sensor and adjusts the output of the Drivetrain accordingly. Some pseudocode to do this would look like:

while(Drivetrain.distance_travelled < 60){
     if(LineTrackerA.reflectivity(pct) > 50){
          Drivetrain.drivewithvoltages(6, 6);
     } else {

This will sort of do the job you want, but it won’t be pretty and it won’t help you win autons. My very best advice to you is to take the line tracker off the bot and just program it in such a way that it won’t cross the line.


goto lol (don’t use goto, do what 2775Josh said)

1 Like

Firstly, thank you so much for the advice!

This is the first time our team has had access to the 3-wire devices such as the Line Tracker and Potentiometer, so just before the tournament we’re trying to streamline all the coding issues we’ve had over the year. Our main coding problem involves going along the diagonal to reach the roller on the other corner, but it seemed like each time we started a round, any slight difference in where the discs were laid on the ground shifted our bot’s trajectory for this turn leading it to either cross the line on the left or hit our goal on the right and get stuck (which I’m thinking may be fixed by a potentiometer). Of course we have a code that just stops before this point and secures the roller points but we’re trying to get as many auton points as possible and securely (of course), leading to this question.

I’m also wondering about “.distance_travelled” and “.drivewithvoltages(#,#)” I understand it’s a pseudocode but I also wouldn’t be surprised if it was just something I never knew about before either. And what exactly does the “pct” mean after reflectivity?

Appreciate the suggestion either way.

pct means “percent” in C++. If you are using Vexcode v5 or Pro, you can use either "percent" or "pct"

An example is:

LeftMotor.spin(forward, 100, percent);

This is the same as:

LeftMotor.spin(forward, 100, pct);

Oh ok, makes sense. Appreciate it.

1 Like