Line Tracking Example
HUSKYLENS 2 line tracking reads line angle, length, and XY components in real time, like a GPS for drawn paths. It’s like watching a map app trace every turn on a road. Using the Python example with UNIHIKER, the camera detects intersections, counts branches counterclockwise, and prints each branch’s coordinates so robots can follow or choose routes precisely.
1.Line Tracking
Before You Start:
1.1 Recognize Intersections and Output Data
Under the Line Tracking function, HUSKYLENS 2 can mark the trajectory of the line in the frame and acquire the current line's length, angle, and X, Y components. When the line branches, it can get the number of branches at the intersection and the corresponding data for each branch, starting counterclockwise.
Example Program:
from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *
u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_LINE_TRACKING)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=15, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=15, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=15, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=15, color="#0000FF")
line5=u_gui.draw_text(text="",x=0,y=160,font_size=15, color="#0000FF")
line6=u_gui.draw_text(text="",x=0,y=200,font_size=15, color="#0000FF")
line7=u_gui.draw_text(text="",x=0,y=240,font_size=15, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_LINE_TRACKING)
if (huskylens.available(ALGORITHM_LINE_TRACKING)):
line1.config(text=(str("Route angle:") + str((huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING,'angle')))))
line2.config(text=(str("Route length:") + str((huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING,'length')))))
line3.config(text="X & Y component:")
line4.config(text=(str((huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING,'xTarget'))) + str((str(",") + str((huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING,'yTarget')))))))
line5.config(text=(str("Junction branch count:") + str((huskylens.getUpcomingBranchCount(ALGORITHM_LINE_TRACKING)))))
line6.config(text="Counterclockwise Ist route")
line7.config(text=(str("X component:") + str((huskylens.getBranch(ALGORITHM_LINE_TRACKING, 1-1,'xTarget')))))
Output Result: As shown, point the HUSKYLENS camera at a map with lines. Observe the UNIHIKER M10 screen output, which displays data such as the current line's length and angle. When the line has multiple branches, it can output the number of branches and the X-component data of a specified line branch, starting counterclockwise.
Was this article helpful?
