The following code throws multiple errors.

userHead williampretty 2026-04-14 03:09:05 19 Views0 Replies

The following code throws multiple errors.

Has anyone successfully compiled a program that uses target tracking ?

 

--------------------- Code -----------------------------------------

 

#include "DFRobot_HuskylensV2.h"

#include "DFMobile.h"

#include "Wire.h"


 

// Create object

HuskylensV2 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);

  }

}