Line Tracking Example
HUSKYLENS 2 line tracking outputs path length, angle and X/Y data. It’s like a map app that not only shows the route but also every turn’s direction and distance, including how many branches are ahead and each branch’s coordinates.
1.Line Tracking Code Example
Before You Start:
1.1 Output Data for Intersection Recognition
In line tracking mode, HUSKYLENS 2 can mark the trajectory of the path in the image and obtain the current path's length, angle, and X/Y components. When the path branches, it can acquire the number of path junction branches and the corresponding data of each branch starting counterclockwise.For detailed functional instructions on Line Tracking, please refer to Line Tracking.
#include "DFRobot_HuskylensV2.h"
// Create object
HuskylensV2 huskylens;
// Main program starts
void setup() {
Serial.begin(9600);
Wire.begin();
while (!huskylens.begin(Wire)) {
delay(100);
}
huskylens.switchAlgorithm(ALGORITHM_LINE_TRACKING);
}
void loop() {
huskylens.getResult(ALGORITHM_LINE_TRACKING);
if ((huskylens.available(ALGORITHM_LINE_TRACKING))) {
Serial.println((String((String("X component of current path: ") + String((RET_ITEM_NUM(huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING), Result, xTarget))))) + String((String("; Y component: ") + String((RET_ITEM_NUM(huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING), Result, yTarget)))))));
Serial.println((String((String("Angle of current path: ") + String((RET_ITEM_NUM(huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING), Result, angle))))) + String((String("; Length: ") + String((RET_ITEM_NUM(huskylens.getCurrentBranch(ALGORITHM_LINE_TRACKING), Result, length)))))));
Serial.println((String("Number of upcoming junction branches: ") + String((huskylens.getUpcomingBranchCount(ALGORITHM_LINE_TRACKING)))));
Serial.println((String((String("X component of the 1st branch in counterclockwise direction") + String((RET_ITEM_NUM(huskylens.getBranch(ALGORITHM_LINE_TRACKING, 1-1), Result, xTarget))))) + String((String("; Y component") + String((RET_ITEM_NUM(huskylens.getBranch(ALGORITHM_LINE_TRACKING, 1-1), Result, yTarget)))))));
}
delay(500);
}
Running Result: As shown in the figure, align the HUSKYLENS camera with the map containing routes, and observe that the Serial Monitor can output data such as the current route length and angle. When the route consists of multiple branches, it can also output the number of branches.
Was this article helpful?
