Source code found via Google throws error when compiling
williampretty 2026-04-11 04:16:57 4 Views0 Replies The following code throws the following error:
huskylens.switchAlgorithm(ALGORITHM_OBJECT_TRACKING); // Switch to Object Tracking
^~~~~~~~~~~~~~~
writeAlgorithm
exit status 1
Compilation error: 'class HUSKYLENS' has no member named 'switchAlgorithm'; did you mean 'writeAlgorithm'?
------------ Code ------------------
#include "HUSKYLENS.h"
#include <DFMobile.h> // Library for Devastator motors
#include "Wire.h"
HUSKYLENS huskylens;
DFMobile Robot(4, 5, 7, 6); // Motor control pins for Romeo
int centerThreshold = 50; // Tolerance for steering
void setup() {
Wire.begin();
Serial.begin(115200);
while (!huskylens.begin(Wire)) {
Serial.println("Begin HUSKYLENS failed!");
delay(100);
}
huskylens.switchAlgorithm(ALGORITHM_OBJECT_TRACKING); // Switch to Object Tracking
}
void loop() {
if (huskylens.available()) {
HUSKYLENSResult result = huskylens.read();
// Check if object is left, right, or center
if (result.xCenter < (160 - centerThreshold)) {
// Object on left: Turn Left
Robot.Speed(-150, 150);
} else if (result.xCenter > (160 + centerThreshold)) {
// Object on right: Turn Right
Robot.Speed(150, -150);
} else {
// Object centered: Move Forward
Robot.Speed(200, 200);
}
} else {
// No object found: Stop
Robot.Speed(0, 0);
}
}

