<< return to Pixycam.com

User Tools

Site Tools


wiki:v2:lego_line_tracking_test

Pixy2 LEGO Line Tracking Test

From the LEGO Mindstorms EV3 Software, go to the File menu and select Open Project.

Browse to the location where you unzipped the “LEGO blocks and examples” file, and then to the examples directory. Select “line_test.ev3” and click on Open. The program is shown below.

Run the program by clicking the play icon in the lower right corner of your EV3 software window. If you don't see the play icon, make sure your LEGO brick is powered on, finished booting, and connected to your computer via a USB cable.

Detecting and Tracking a Line (Vector)

Draw a line on a piece of paper and put it in front of Pixy2. Pencil will work, but black marker is usually better. If you are running PixyMon, you should see something like this:

Similarly, you should see a rendering of a line on the EV3's LCD. The line should move back and forth as you move the line side to side in front of Pixy2. What Pixy2 has done is found the best line candidate to track and has assigned it to the Vector. The Vector is the line that Pixy2 (or your robot) is currently tracking/following.

The Lamp

You can also see what happens when you turn off and on Pixy2's lamp by setting it to false or true. You'll need to stop the program and re-run it for the change to take effect.

Note, with the lamp on, Pixy2 will typically reduce the exposure (sampling) time of the image, which reduces motion blur. In general, motion blur happens because a camera is sampling a subject while the subject is moving. In this case, the subject is a line (or set of lines). If they are blurred due to motion (the motion of your robot), it can make the lines more difficult for Pixy2 to detect and track. Pixy2's lamp can help with this. The upshot is that the lamp makes your robot go faster!

Make an intersection

Make a 4-way intersection by drawing another line through the original line and place it in front of Pixy2. Pixy2 will identify the intersection and quickly choose the default branch of the intersection, which is the “straightest” branch of the intersection, assuming the Turn Angle input is set to 0 (default). If you run the EV3 program, you should notice that while Pixy2 sees the intersection, the EV3 LCD will show “Intsctn: 4”, meaning that it sees a 4-way intersection.

Make a "Turn" at an Intersection

You can stop the program and change Turn Angle to -90 degrees.

-90 degrees is a right turn according to the diagram below.

Angle coordinates from Pixy2's perspective.

Re-run the program and notice that when it sees the intersection it will choose the right-most branch of the intersection as the Vector (instead of the straightest.)

Barcodes

We wanted Pixy2 to be able to receive simple commands or information while it is performing line tracking, so we added the barcode feature. The barcodes are intended to act as “roadsigns”. You can add graphics to the barcodes that are human-readable as long as you keep the barcode unobstructed. To test the barcode functionality, download the print the all_codes.pdf document. (Note, other barcode files and images can be found here.)

Holding the document in front of Pixy2 while it is running the line tracking algorithm will yield something like this in PixyMon:

If you run the EV3 program, you should see the text “Barcode: n” on the EV3 LCD, where “n” is the barcode's number.

What's Next?

This is just a test program to help demonstrate Pixy2's line following capabilities. From here, you might want to test things on a simple robot with the Line Following Demo.

wiki/v2/lego_line_tracking_test.txt · Last modified: 2019/01/31 01:40 by pixycam