<< return to Pixycam.com

Using Line Tracking API to See Line at a Distance

Hello, we are trying to use a Pixy2 on a robot to find a line ahead of the robot, drive to it, and then turn to follow it. We have it setup our Pixy2 to be on the robot about 6.5" off the ground, and can see a white line on the floor about 18" in front of the robot. From the returned vector, we are hoping to calculate the distance from the robot’s current location to the nearest end of the vector, assuming the 78×51 grid the Pixy2 returns found vectors in.

Our first question is, what is the point on the grid of coordinates that the pixy uses to track vectors where the actual pixy camera is sitting. Is it (0,0), or (0,39), or somewhere else?

We are getting data back, but having trouble calculating the distance to the end of the vector as the Pixy2 gets further away from the end of the vector. Since the Pixy2 is facing down at a 45 degree angle from 6.5 inches above the floor, we are assuming there is something wrong in our math for that distance as it gets further away.

Does anyone have a good way to calculate this distance to a line/vector found out ahead of the Pixy2 in this situation?

Hello Jared,
It sounds like you are close to solving this.

Try this – within PIxymon, and Pixy2 mounted on your robot looking at the floor, bring up line tracking mode and place a marker in front of the robot such that it appears at the bottom of the image, left-right centered. Measure the distance from the marker to the front of your robot and record that distance. (you can choose whatever “front” you want, as long as it’s well-defined and reproducable). We’ll call this distance Db.

Now take another marker and place it in front of the robot such that it appears at the top of the image (left-right centered). Measure the distance from this marker to the “front” of your robot. We’ll call this distance Dt.

With these 2 numbers, you can now estimate the distance of a marker that is in the middle of the image to the front of your robot. It will be (Db + Dt)/2. You can create an expression that takes the y-value of the vector and it will return a distance estimate to the front of your robot.

distance = Db + (Dt - Db)/51 * (51-y_value)

Hope this helps!

Edward

Hi Edward,

Thank you for the help, we really appreciate it. We tried your suggestions, working with the scenario pictured below:

In this case, the pieces of yellow tape are showing the bottom and top of the Pixy’s image. We found Db=4.5 inches and Dt=30 inches.

The white tape is the vector we are looking for, and through the robot’s code it found the vector with a y0=13 and a y1=0 (off the top of the image).

So with the equation we have:

distance = 4.5 + (30-4.5)/51 * (51-13) = 23.5

When we measured the actual distance to the closest end of the white tape, it was just about 17 inches.

Any idea where we got that wrong? Could it be the height of the pixy on the robot, or the angle it is looking at downwards?

Thanks again for all your help!

Hello Jared,
This process is called camera calibration, and it’s just a simple calibration. It will not be exact. Still, you need to make sure your calibration numbers check out – that the measurements are accurate and the markers are as close to the top and bottom of the image as possible. Other than that, I don’t know what else to suggest (sorry).

Edward