mirror of
https://gitlab.waag.org/make/fablab/interns/2025/sam.git
synced 2025-08-03 20:04:56 +00:00
structuring the project and docs about drone code
This commit is contained in:
12
docs/final_project/drone_breadboard.md
Normal file
12
docs/final_project/drone_breadboard.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# First breadboard testing
|
||||
|
||||
## Introduction
|
||||
|
||||
This is the first design I made. I wanted to start programming so I could start on the correction algorithm of the drone.
|
||||
[link to code](drone_code.md)
|
||||
|
||||
## The breadboard
|
||||
|
||||

|
||||

|
||||

|
120
docs/final_project/drone_code.md
Normal file
120
docs/final_project/drone_code.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# Coding the drone
|
||||
|
||||
## What does every part of my code do?
|
||||
### #include
|
||||
`#include` includes an external library into the project so you can use it.
|
||||
|
||||
//TODO: add docs about working code not broken code
|
||||
|
||||
## Issues
|
||||
|
||||
### Using the wrong library for the BNO085
|
||||
First used the wrong library I used the adafruit bno0xx library instead of the sparkfun bno08x library. The Example script below this reads the BNO085 sensor and returns the values in the arduino serial console.
|
||||
|
||||
??? failure
|
||||
|
||||
```cpp
|
||||
#include "conf.h"
|
||||
#include <Adafruit_BNO08x.h>
|
||||
#include <sh2.h>
|
||||
#include <sh2_SensorValue.h>
|
||||
#include <sh2_err.h>
|
||||
#include <sh2_hal.h>
|
||||
#include <sh2_util.h>
|
||||
#include <shtp.h>
|
||||
|
||||
Adafruit_BNO08x bno08x(BNOINTERRUPTSIG);
|
||||
sh2_SensorValue_t sensorValue;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//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 <SparkFun_BNO080_Arduino_Library.h>
|
||||
#include <Wire.h>
|
||||
#include "conf.h"
|
||||
|
||||
BNO080 myIMU;
|
||||
|
||||
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() {
|
||||
|
||||
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.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
|
||||
```
|
||||
|
||||
## New driver
|
||||
After researching for a while and looking through other fab academy projects I found out that other people also made drones with microcontrollers and used a premade driver that they customised (https://fab.cba.mit.edu/classes/863.23/Architecture/people/Zhixing/finalproject.html). After doing some research on how to keep the drone upright I also decided to use an exisitng driver because the math required for that is way above my level.
|
||||
|
||||
### The new driver
|
||||
Im gonna be using the [dRhemFlightVTOL](https://github.com/nickrehm/dRehmFlight/tree/master) driver. The only problem is that it doesn't support my Inertial measuring unit (BNO085). So I will have to customise the driver to make it work with it.
|
16
docs/final_project/drone_stabilisation.md
Normal file
16
docs/final_project/drone_stabilisation.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# How to keep a drone upright
|
||||
|
||||
|
||||
using accelerometers always try to keep them at 0
|
||||
except if you press a button then the desired pitch changes.
|
||||
|
||||
|
||||
|
||||
|
||||
https://www.reddit.com/r/diydrones/comments/1cm8ykx/how_is_stable_flight_possible/
|
||||
|
||||
https://github.com/lobodol/drone-flight-controller
|
||||
https://github.com/liourej/CodeDroneDIY
|
||||
https://electronoobs.com/eng_robotica_tut9_2_2.php
|
||||
|
||||
https://www.youtube.com/watch?v=4vpgjjYizVU
|
7
docs/final_project/microcontrollers.md
Normal file
7
docs/final_project/microcontrollers.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Microcontrollers
|
||||
|
||||
## Microcontroller requirements
|
||||
* 4 channel pwm output for 4 drone motors
|
||||
* 16 bit pwm so all electronic speed controllers can understand
|
||||
* Minimum 2 MB flash size
|
||||
* I2C
|
Reference in New Issue
Block a user