From 9b5edfa40ffc78c7c5e8bd23fa87bd8b507ad5bb Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Tue, 28 Jan 2025 14:50:33 +0100 Subject: [PATCH] finaly fix hopefully --- docs/week_1_fabacademy/drone_code.md | 164 ++++++++++++++------------- 1 file changed, 83 insertions(+), 81 deletions(-) diff --git a/docs/week_1_fabacademy/drone_code.md b/docs/week_1_fabacademy/drone_code.md index 217bc53..53d3b16 100644 --- a/docs/week_1_fabacademy/drone_code.md +++ b/docs/week_1_fabacademy/drone_code.md @@ -7,102 +7,104 @@ First used the wrong library I used the adafruit bno0xx library instead of the sparkfun bno08x library ??? failure -```cpp -#include "conf.h" -#include -#include -#include -#include -#include -#include -#include -Adafruit_BNO08x bno08x(BNOINTERRUPTSIG); -sh2_SensorValue_t sensorValue; + ```cpp + #include "conf.h" + #include + #include + #include + #include + #include + #include + #include -void setup() { - Serial.begin(9600); - Serial.println("setup started"); - // Setup all ESC - // ledcAttach(MOTOR1, PWMFREQ, PWMRESOLUTION); - // ledcAttach(MOTOR2, PWMFREQ, PWMRESOLUTION); - // ledcAttach(MOTOR3, PWMFREQ, PWMRESOLUTION); - // ledcAttach(MOTOR4, PWMFREQ, PWMRESOLUTION); - Serial.print("Setup Started"); -} + Adafruit_BNO08x bno08x(BNOINTERRUPTSIG); + sh2_SensorValue_t sensorValue; -void loop() { - // put your main code here, to run repeatedly: - sleep(3) - if (!bno08x.begin_I2C()) { - Serial.println("Failed to find BNO08x chip"); - sleep(1); - } + void setup() { + Serial.begin(9600); + Serial.println("setup started"); + // Setup all ESC + // ledcAttach(MOTOR1, PWMFREQ, PWMRESOLUTION); + // ledcAttach(MOTOR2, PWMFREQ, PWMRESOLUTION); + // ledcAttach(MOTOR3, PWMFREQ, PWMRESOLUTION); + // ledcAttach(MOTOR4, PWMFREQ, PWMRESOLUTION); + Serial.print("Setup Started"); + } + + void loop() { + // put your main code here, to run repeatedly: + sleep(3) + if (!bno08x.begin_I2C()) { + Serial.println("Failed to find BNO08x chip"); + sleep(1); + } - Serial.print("Game Rotation Vector - r: "); - Serial.print(sensorValue.un.gameRotationVector.real); - Serial.print(" i: "); - Serial.print(sensorValue.un.gameRotationVector.i); - Serial.print(" j: "); - Serial.print(sensorValue.un.gameRotationVector.j); - Serial.print(" k: "); - Serial.println(sensorValue.un.gameRotationVector.k); -} + Serial.print("Game Rotation Vector - r: "); + Serial.print(sensorValue.un.gameRotationVector.real); + Serial.print(" i: "); + Serial.print(sensorValue.un.gameRotationVector.i); + Serial.print(" j: "); + Serial.print(sensorValue.un.gameRotationVector.j); + Serial.print(" k: "); + Serial.println(sensorValue.un.gameRotationVector.k); + } -//https://randomnerdtutorials.com/esp32-pwm-arduino-ide/ -//https://github.com/adafruit/Adafruit_BNO08x/blob/master/examples/rotation_vector/rotation_vector.ino#L25 -``` + //https://randomnerdtutorials.com/esp32-pwm-arduino-ide/ + //https://github.com/adafruit/Adafruit_BNO08x/blob/master/examples/rotation_vector/rotation_vector.ino#L25 + ``` ??? example -```cpp -#include -#include -#include "conf.h" -BNO080 myIMU; + ```cpp + #include + #include + #include "conf.h" -void setup() { - Serial.begin(9600); - Serial.println("setup started"); - // Setup all ESC - // ledcAttach(MOTOR1, PWMFREQ, PWMRESOLUTION); - // ledcAttach(MOTOR2, PWMFREQ, PWMRESOLUTION); - // ledcAttach(MOTOR3, PWMFREQ, PWMRESOLUTION); - // ledcAttach(MOTOR4, PWMFREQ, PWMRESOLUTION); - Serial.print("Setup Started"); + BNO080 myIMU; - Wire.begin(); - myIMU.begin(); - Wire.setClock(400000); //Increase I2C data rate to 400kHz - myIMU.enableRotationVector(50); //Send data update every 50ms} -} + void setup() { + Serial.begin(9600); + Serial.println("setup started"); + // Setup all ESC + // ledcAttach(MOTOR1, PWMFREQ, PWMRESOLUTION); + // ledcAttach(MOTOR2, PWMFREQ, PWMRESOLUTION); + // ledcAttach(MOTOR3, PWMFREQ, PWMRESOLUTION); + // ledcAttach(MOTOR4, PWMFREQ, PWMRESOLUTION); + Serial.print("Setup Started"); + + Wire.begin(); + myIMU.begin(); + Wire.setClock(400000); //Increase I2C data rate to 400kHz + myIMU.enableRotationVector(50); //Send data update every 50ms} + } -void loop() { + void loop() { - if (myIMU.dataAvailable() == true) { - float roll = (myIMU.getRoll()) * 180.0 / PI; // Convert roll to degrees - float pitch = (myIMU.getPitch()) * 180.0 / PI; // Convert pitch to degrees - float yaw = (myIMU.getYaw()) * 180.0 / PI; // Convert yaw / heading to degrees + if (myIMU.dataAvailable() == true) { + float roll = (myIMU.getRoll()) * 180.0 / PI; // Convert roll to degrees + float pitch = (myIMU.getPitch()) * 180.0 / PI; // Convert pitch to degrees + float yaw = (myIMU.getYaw()) * 180.0 / PI; // Convert yaw / heading to degrees - Serial.print(roll, 1); - Serial.print(F(",")); - Serial.print(pitch, 1); - Serial.print(F(",")); - Serial.print(yaw, 1); + Serial.print(roll, 1); + Serial.print(F(",")); + Serial.print(pitch, 1); + Serial.print(F(",")); + Serial.print(yaw, 1); - Serial.println(); - } -} -void calibrateESC() { - ledcWrite(MOTOR1, 1100); - ledcWrite(MOTOR2, 1100); - ledcWrite(MOTOR3, 1100); - ledcWrite(MOTOR4, 1100); -} + Serial.println(); + } + } + void calibrateESC() { + ledcWrite(MOTOR1, 1100); + ledcWrite(MOTOR2, 1100); + ledcWrite(MOTOR3, 1100); + ledcWrite(MOTOR4, 1100); + } -//https://randomnerdtutorials.com/esp32-pwm-arduino-ide/ -//https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/blob/main/examples/Example24-UncalibratedGyro/Example24-UncalibratedGyro.ino -``` + //https://randomnerdtutorials.com/esp32-pwm-arduino-ide/ + //https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/blob/main/examples/Example24-UncalibratedGyro/Example24-UncalibratedGyro.ino + ```