Team Ferrari 5- Cat Car- Notes

 


Zoom Feed:


Technical Notes and Sketches:
























ESP-NOW Projects
https://sites.google.com/view/acera-arduino/iot-projects/esp-now-projects

/***************************************************

 HUSKYLENS An Easy-to-use AI Machine Vision Sensor

https://wiki.dfrobot.com/HUSKYLENS_V1.0_SKU_SEN0305_SEN0336

 <https://www.dfrobot.com/product-1922.html>

/***************************************************

 HUSKYLENS An Easy-to-use AI Machine Vision Sensor

 <https://www.dfrobot.com/product-1922.html>

/***********Notice and Trouble shooting***************

 1.Connection and Diagram can be found here

 <https://wiki.dfrobot.com/HUSKYLENS_V1.0_SKU_SEN0305_SEN0336#target_23>

 2.This code is tested on Arduino Uno, Leonardo, Mega boards.

 ****************************************************/

Sample Program:

#include "HUSKYLENS.h"

#include "SoftwareSerial.h"

HUSKYLENS huskylens;

SoftwareSerial mySerial(10, 11); // RX, TX

//HUSKYLENS green line >> Pin 10; blue line >> Pin 11

void printResult(HUSKYLENSResult result);


void setup() {

    Serial.begin(115200);

    mySerial.begin(9600);

    while (!huskylens.begin(mySerial))

    {

        Serial.println(F("Begin failed!"));

        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>Serial 9600)"));

        Serial.println(F("2.Please recheck the connection."));

        delay(100);

    }

}


void loop() {

    if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));

    else if(!huskylens.isLearned()) Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!"));

    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));

    else

    {

        Serial.println(F("###########"));

        while (huskylens.available())

        {

            HUSKYLENSResult result = huskylens.read();

            printResult(result);

        }    

    }

}


void printResult(HUSKYLENSResult result){

    if (result.command == COMMAND_RETURN_BLOCK){

        Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID);

    }

    else if (result.command == COMMAND_RETURN_ARROW){

        Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID);

    }

    else{

        Serial.println("Object unknown!");

    }

}

-------------------------------------------------------

Clarify control system



#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>

double xPos = 0, yPos = 0, headingVel = 0;
uint16_t BNO055_SAMPLERATE_DELAY_MS = 10; //how often to read data from the board
uint16_t PRINT_DELAY_MS = 500; // how often to print the data
uint16_t printCount = 0; //counter to avoid printing every 10MS sample

//velocity = accel*dt (dt in seconds)
//position = 0.5*accel*dt^2
double ACCEL_VEL_TRANSITION = (double)(BNO055_SAMPLERATE_DELAY_MS) / 1000.0;
double ACCEL_POS_TRANSITION = 0.5 * ACCEL_VEL_TRANSITION * ACCEL_VEL_TRANSITION;
double DEG_2_RAD = 0.01745329251; //trig functions require radians, BNO055 outputs degrees

// Check I2C device address and correct line below (by default address is 0x29 or 0x28)
// id, address
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);

void setup(void)
{
Serial.begin(115200);

while (!Serial) delay(10); // wait for serial port to open!
if (!bno.begin())
{
Serial.print("No BNO055 detected");
while (1);
}


delay(1000);
}

void loop(void)
{
//
unsigned long tStart = micros();
sensors_event_t orientationData , linearAccelData;
bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER);
// bno.getEvent(&angVelData, Adafruit_BNO055::VECTOR_GYROSCOPE);
bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL);

xPos = xPos + ACCEL_POS_TRANSITION * linearAccelData.acceleration.x;
yPos = yPos + ACCEL_POS_TRANSITION * linearAccelData.acceleration.y;

// velocity of sensor in the direction it's facing
headingVel = ACCEL_VEL_TRANSITION * linearAccelData.acceleration.x / cos(DEG_2_RAD * orientationData.orientation.x);

if (printCount * BNO055_SAMPLERATE_DELAY_MS >= PRINT_DELAY_MS) {
//enough iterations have passed that we can print the latest data
Serial.print("Heading: ");
Serial.println(orientationData.orientation.x);
Serial.print("Position: ");
Serial.print(xPos);
Serial.print(" , ");
Serial.println(yPos);
Serial.print("Speed: ");
Serial.println(headingVel);
Serial.println("-------");

printCount = 0;
}
else {
printCount = printCount + 1;
}

while ((micros() - tStart) < (BNO055_SAMPLERATE_DELAY_MS * 1000))
{
//poll until the next sample is ready
}
}

void printEvent(sensors_event_t* event) {
Serial.println();
Serial.print(event->type);
double x = -1000000, y = -1000000 , z = -1000000; //dumb values, easy to spot problem
if (event->type == SENSOR_TYPE_ACCELEROMETER) {
x = event->acceleration.x;
y = event->acceleration.y;
z = event->acceleration.z;
}
else if (event->type == SENSOR_TYPE_ORIENTATION) {
x = event->orientation.x;
y = event->orientation.y;
z = event->orientation.z;
}
else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) {
x = event->magnetic.x;
y = event->magnetic.y;
z = event->magnetic.z;
}
else if ((event->type == SENSOR_TYPE_GYROSCOPE) || (event->type == SENSOR_TYPE_ROTATION_VECTOR)) {
x = event->gyro.x;
y = event->gyro.y;
z = event->gyro.z;
}

Serial.print(": x= ");
Serial.print(x);
Serial.print(" | y= ");
Serial.print(y);
Serial.print(" | z= ");
Serial.println(z);
}




No comments:

Post a Comment

EDW 2024 Montage Video