Line tracking for Lego Mindstorms (and others)

110 views
Skip to first unread message

Per Jakobsen

unread,
Apr 8, 2017, 8:09:29 AM4/8/17
to pixy_firmware_sdk
Last week I got an idea for line tracking with the Pixy.
I added two lines of code to the Pixy firmware, recompiled and installed it on the Pixy, and tadaaa, pretty ok line tracking with the Pixy on Mindstorms Lego!

Patch:
###########
--- src/device/libpixy_m4/src/blobs.cpp~
+++ src/device/libpixy_m4/src/blobs.cpp
@@ -146,6 +146,8 @@
         }
 
         sig = qval.m_col&0x07;
+    if ((sig == 1) && (row < 170))
+        continue;
 
         u = qval.m_u;
         v = qval.m_v;
############

This limits the detection of signature 1 to the last/lowest scanlines of the camera, making it act more or less like a line-sensor.

A line is found when signature(1).x is non-zero.
Tracking along the line is just steering on signature(1).x
A branch is detected with signature(1).width larger than threshold (1.5 to 2 times the line width).

If the branch is train track-like (soft curves):
Right branch is tracked with: signature(1).x + signature(1).width/2 - linewidth/2.
Left branch is tracked with: signature(1).x - signature(1).width/2 + linewidth/2.
The branch is passed, when signature(1).width is back down below threshold.

I attached the compiled version of the patched firmware (LEGO style).

Simply program the camera with the patched firmware, set the signature, adjust parameters in Pixymon until satisfactory detection is achieved, then make a simple MindStorms program that asks for signature 1, and steers on the X-result.
The robot can still use the other signatures from the entire image.
Running PixyMon in Cooked mode still detects signature 1 in the entire image, but after setting the signature, you can switch to "default program" and see how the Pixy detects it.

Enjoy.

~Per

pixy_firmware.hex
Reply all
Reply to author
Forward
0 new messages