diff --git a/.gitignore b/.gitignore index 684bb8f..837852e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .vscode -*.png \ No newline at end of file +*.png +*.JPEG +*.mov \ No newline at end of file diff --git a/docs/Assignments/week_4_programming/IMG_8180.jpg b/docs/Assignments/week_4_programming/IMG_8180.jpg new file mode 100644 index 0000000..ce0bbbf Binary files /dev/null and b/docs/Assignments/week_4_programming/IMG_8180.jpg differ diff --git a/docs/Assignments/week_4_programming/IMG_8182.jpg b/docs/Assignments/week_4_programming/IMG_8182.jpg new file mode 100644 index 0000000..9696cea Binary files /dev/null and b/docs/Assignments/week_4_programming/IMG_8182.jpg differ diff --git a/docs/Assignments/week_4_programming/image-1.jpg b/docs/Assignments/week_4_programming/image-1.jpg new file mode 100644 index 0000000..5456f19 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-1.jpg differ diff --git a/docs/Assignments/week_4_programming/image-10.jpg b/docs/Assignments/week_4_programming/image-10.jpg new file mode 100644 index 0000000..f5909ba Binary files /dev/null and b/docs/Assignments/week_4_programming/image-10.jpg differ diff --git a/docs/Assignments/week_4_programming/image-11.jpg b/docs/Assignments/week_4_programming/image-11.jpg new file mode 100644 index 0000000..d425382 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-11.jpg differ diff --git a/docs/Assignments/week_4_programming/image-12.jpg b/docs/Assignments/week_4_programming/image-12.jpg new file mode 100644 index 0000000..6a73ce5 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-12.jpg differ diff --git a/docs/Assignments/week_4_programming/image-13.jpg b/docs/Assignments/week_4_programming/image-13.jpg new file mode 100644 index 0000000..458d53f Binary files /dev/null and b/docs/Assignments/week_4_programming/image-13.jpg differ diff --git a/docs/Assignments/week_4_programming/image-14.jpg b/docs/Assignments/week_4_programming/image-14.jpg new file mode 100644 index 0000000..29c7320 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-14.jpg differ diff --git a/docs/Assignments/week_4_programming/image-15.jpg b/docs/Assignments/week_4_programming/image-15.jpg new file mode 100644 index 0000000..512702e Binary files /dev/null and b/docs/Assignments/week_4_programming/image-15.jpg differ diff --git a/docs/Assignments/week_4_programming/image-16.jpg b/docs/Assignments/week_4_programming/image-16.jpg new file mode 100644 index 0000000..a3490da Binary files /dev/null and b/docs/Assignments/week_4_programming/image-16.jpg differ diff --git a/docs/Assignments/week_4_programming/image-17.jpg b/docs/Assignments/week_4_programming/image-17.jpg new file mode 100644 index 0000000..7475e02 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-17.jpg differ diff --git a/docs/Assignments/week_4_programming/image-18.jpg b/docs/Assignments/week_4_programming/image-18.jpg new file mode 100644 index 0000000..7c79505 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-18.jpg differ diff --git a/docs/Assignments/week_4_programming/image-19.jpg b/docs/Assignments/week_4_programming/image-19.jpg new file mode 100644 index 0000000..d4736da Binary files /dev/null and b/docs/Assignments/week_4_programming/image-19.jpg differ diff --git a/docs/Assignments/week_4_programming/image-2.jpg b/docs/Assignments/week_4_programming/image-2.jpg new file mode 100644 index 0000000..e5339f7 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-2.jpg differ diff --git a/docs/Assignments/week_4_programming/image-20.jpg b/docs/Assignments/week_4_programming/image-20.jpg new file mode 100644 index 0000000..737aa35 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-20.jpg differ diff --git a/docs/Assignments/week_4_programming/image-21.jpg b/docs/Assignments/week_4_programming/image-21.jpg new file mode 100644 index 0000000..d701d3d Binary files /dev/null and b/docs/Assignments/week_4_programming/image-21.jpg differ diff --git a/docs/Assignments/week_4_programming/image-22.jpg b/docs/Assignments/week_4_programming/image-22.jpg new file mode 100644 index 0000000..207dddc Binary files /dev/null and b/docs/Assignments/week_4_programming/image-22.jpg differ diff --git a/docs/Assignments/week_4_programming/image-23.jpg b/docs/Assignments/week_4_programming/image-23.jpg new file mode 100644 index 0000000..fe3bdfe Binary files /dev/null and b/docs/Assignments/week_4_programming/image-23.jpg differ diff --git a/docs/Assignments/week_4_programming/image-24.jpg b/docs/Assignments/week_4_programming/image-24.jpg new file mode 100644 index 0000000..c052717 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-24.jpg differ diff --git a/docs/Assignments/week_4_programming/image-25.jpg b/docs/Assignments/week_4_programming/image-25.jpg new file mode 100644 index 0000000..4802eb1 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-25.jpg differ diff --git a/docs/Assignments/week_4_programming/image-3.jpg b/docs/Assignments/week_4_programming/image-3.jpg new file mode 100644 index 0000000..f94b186 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-3.jpg differ diff --git a/docs/Assignments/week_4_programming/image-4.jpg b/docs/Assignments/week_4_programming/image-4.jpg new file mode 100644 index 0000000..0e6457b Binary files /dev/null and b/docs/Assignments/week_4_programming/image-4.jpg differ diff --git a/docs/Assignments/week_4_programming/image-5.jpg b/docs/Assignments/week_4_programming/image-5.jpg new file mode 100644 index 0000000..80add5a Binary files /dev/null and b/docs/Assignments/week_4_programming/image-5.jpg differ diff --git a/docs/Assignments/week_4_programming/image-6.jpg b/docs/Assignments/week_4_programming/image-6.jpg new file mode 100644 index 0000000..ed0b3c3 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-6.jpg differ diff --git a/docs/Assignments/week_4_programming/image-7.jpg b/docs/Assignments/week_4_programming/image-7.jpg new file mode 100644 index 0000000..4b9a9fb Binary files /dev/null and b/docs/Assignments/week_4_programming/image-7.jpg differ diff --git a/docs/Assignments/week_4_programming/image-8.jpg b/docs/Assignments/week_4_programming/image-8.jpg new file mode 100644 index 0000000..440edf6 Binary files /dev/null and b/docs/Assignments/week_4_programming/image-8.jpg differ diff --git a/docs/Assignments/week_4_programming/image-9.jpg b/docs/Assignments/week_4_programming/image-9.jpg new file mode 100644 index 0000000..871f17b Binary files /dev/null and b/docs/Assignments/week_4_programming/image-9.jpg differ diff --git a/docs/Assignments/week_4_programming/image.jpg b/docs/Assignments/week_4_programming/image.jpg new file mode 100644 index 0000000..bec8243 Binary files /dev/null and b/docs/Assignments/week_4_programming/image.jpg differ diff --git a/docs/Assignments/week_4_programming/programming.md b/docs/Assignments/week_4_programming/programming.md index 0a00736..73189bd 100644 --- a/docs/Assignments/week_4_programming/programming.md +++ b/docs/Assignments/week_4_programming/programming.md @@ -153,10 +153,10 @@ In this case minVal is 800 an maxVal is 2200. So we need to stay between these r At the local lecture we got thought how to use platformIO. I was already used to Arduino IDE v2. But I found the UI and the speeds of PlatformIO very nice so that's why I decided to switch to PlatformIO. First off. I created a new project with the Xiao espC3 because the espC6 isn't registered on the list. I've googled a bit and that's because PlatformIO needs to get profit so they ask money to the board developers to add the board to their platform. So we need to set the correct board later on. -![alt text](image-3.png) +![alt text](image-3.jpg) When it created the project. I copied all the files over to the src folder and renament my drone.ino to main.cpp. Now I had a lot of include errors because Arduino IDE automatically imports everything and with PlatformIO you need to define everything yourself. So I started out in the Library manager installing all the libraries to the project I needed. -![alt text](image-4.png) +![alt text](image-4.jpg) #### Setting the correct board @@ -184,7 +184,7 @@ To get the correct configuration if it isn't listed on PlatformIO, is to go to t #### Installing libraries in platformIO To install a library click the platformIO icon. In there click the libraries button. Then you can search a library and click add to project. Now you have added a library to your project! -![alt text](image.png) +![alt text](image.jpg) After that it will edit platformio.ini and there you will see the library added to the project. It's also in `.pio/libdeps` @@ -194,23 +194,23 @@ When setting up PlatformIO on another system we ran into the issue that the mach ### Programming and compiling and uploading Using platformIO is really straight forward. The only folder you should look at in your platformIO project is the `src` folder. -![alt text](image-5.png) +![alt text](image-5.jpg) In the main.cpp file you can write your program to run on a microcontroller. On the bottom of your screen you see that there are a few new buttons. -![alt text](image-6.png) +![alt text](image-6.jpg) The Compile and Upload and Serial console buttons are going to be the most used. Compile compiles the code and checks if it's correct. If it has incorrect syntax you need to correct it. The upload button compiles the code first and then sends it to the Microcontroller. The Serial console is a really nice debug tool to see what the microcontroller is doing if you added print statements in your code. ## Editing the new driver Adding in support for the BNO085. The original driver doesn't support the BNO085. I first started off searching for every instance of an existing sensor. -![alt text](image-7.png) +![alt text](image-7.jpg) From there I started out changing everything to BNO085 and also importing the correct library. As I have found the correct library earlier in the code. -![alt text](image-8.png) +![alt text](image-8.jpg) ### The purple text (Compiler flags) The purple text are compiler flags. They tell the compiler what to do with certain pieces of code or variables. @@ -227,42 +227,110 @@ The purple text are compiler flags. They tell the compiler what to do with certa ### Setting the correct library I added a compiler case for my sensor and added the correct library to it. -![alt text](image-8.png) +![alt text](image-8.jpg) ### Setting correct value selection -I am not sure what it does. It sets some values for the calculations later on. So I copied over the configuration for the MPU6050 because it was the most similar to the BNO085. ![alt text](image-9.png) +I am not sure what it does. It sets some values for the calculations later on. So I copied over the configuration for the MPU6050 because it was the most similar to the BNO085. ![alt text](image-9.jpg) ### Setting up the sensor For this part I went into the documentation of the Sparkfun BNO0xx library. I first looked through the rest of the code what values it wanted because with the BNO085 you need to enable which information you want. -![alt text](image-11.png) +![alt text](image-11.jpg) When digging deeper into the driver to where it pulls the data from the sensors you can see what values it want's and according to that I can go through the documentation to enable the correct data outputs. I went to the [examples list](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/tree/main/examples) of the library and clicked every data example I needed. -![alt text](image-12.png) +![alt text](image-12.jpg) I first clicked the data type I needed. -![alt text](image-13.png) +![alt text](image-13.jpg) Then I copied the line that enabled the data output. -![alt text](image-10.png) +![alt text](image-10.jpg) Then I inserted it into the driver code. ### Getting data from the sensors This step goes similar to the last step except you need to copy over another bit. -![alt text](image-14.png) +![alt text](image-14.jpg) What this part does is acquire the sensor data and storing it in a variable. The same needs to be done in the driver like this. -![alt text](image-15.png) +![alt text](image-15.jpg) The only issue is that the BNO085 can't output degrees. So we need to convert the radians to degrees using a simple formula I found on google. -![alt text](image-16.png) +![alt text](image-16.jpg) The same also has to be done later on in the error correction algorithm -![alt text](image-17.png) +![alt text](image-17.jpg) That was the last we needed to change. Hopefully it works now since I still need to fix some compile errors. +## Creating my own controls +I want to create my own controller. So I need to edit the current controls. The base driver attempts to set up radio communication. We won't be using that so I'm gonna comment that out. + +![alt text](image-18.jpg) + +When attempting to compile it still throws some errors so there are still functions being called from the original radio script. The error log indicated it comes from line 1239 +![alt text](image-20.jpg) + +![alt text](image-19.jpg) +So I will be needing to make my own case to control the drone. + +I wanna control to drone using another microcontroller, specifically an esp because then I can use the espNOW protocol to connect them together and get communication running between them. First I wanna make something functional before I upgrade it so that's why I'm starting out easy. + + +### Components for the controller +Im going to start off with 2 sliding potentiometers and a espC3 for throttle and for left-right. The Driver expects PWM frequencies so I'm sending PWM frequencies based on the potsliders. + +![alt text](IMG_8180.jpg) + +* [PotSlider](https://nl.aliexpress.com/item/1005006733220962.html) x2 +* [espC3 supermini](https://nl.aliexpress.com/item/1005008125438785.html) x1 + + +### Wiring the controller +To read the Pot meter values we need to read the resistance from the potslider. So we need analog read. When looking at the datasheet I can see that I can use pins from 0 to 5. + +![alt text](image-21.jpg) + +Wiring it is pretty straight forward, VCC to 3v3, GND to GND and the out pin to a analog pin. + +![alt text](IMG_8182.jpg) + +### Programming the controller +#### Testing if I can upload +I started out by creating a new PlatformIO project. And selected the `Lolin Wemos C3 Mini`. Then I tried to upload some code to see if it worked. + +![alt text](image-22.jpg) +In short the answer was yes. I was a bit surprised because the ESP-C3 supermini isn't in the list of platformIO. + +#### Reading the Potentiometer +Reading the potentiometer is really straightforward. The only line we need is `analogRead()`, something to tell the pin that's it an input and something to print it to console. + +```cpp +#include + +void setup(){ + Serial.begin(9600); //Opens serial bus + pinMode(0, INPUT); //sets pin 0 to input +} + +void loop(){ + Serial.println(analogRead(0)); //prints the result of analogRead() to console +} +``` + +When attempting to upload this I got this error a few times. +![alt text](image-23.jpg) +Then I remembered from the local lecture that if you `press and hold boot > press reset > release boot`. You can start the microcontroller in boot mode so you can easily flash to it. + +After flashing it onto the microcontroller I could test it. +![alt text](image-24.jpg) + +![alt text](image-25.jpg) + +I've noticed there are some ghost values when it needs to be 0 so I need a small area where it's always 0. The upper side of the Potentiometer is always 4095 thats the max value so that's good. + +##### Fixing the ghost measurements +Im going to map everything lower than 80 to 80 using software. The reason im doing 80 is because then it will keep on counting up from 80 instead of jumping from 0 to 81 and I didn't see any ghost readings above 80. \ No newline at end of file diff --git a/src/controller/drone controller/.gitignore b/src/controller/drone controller/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/src/controller/drone controller/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/src/controller/drone controller/include/README b/src/controller/drone controller/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/src/controller/drone controller/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/src/controller/drone controller/lib/README b/src/controller/drone controller/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/src/controller/drone controller/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/src/controller/drone controller/platformio.ini b/src/controller/drone controller/platformio.ini new file mode 100644 index 0000000..881501c --- /dev/null +++ b/src/controller/drone controller/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:lolin_c3_mini] +platform = espressif32 +board = lolin_c3_mini +framework = arduino diff --git a/src/controller/drone controller/src/main.cpp b/src/controller/drone controller/src/main.cpp new file mode 100644 index 0000000..4c34ffa --- /dev/null +++ b/src/controller/drone controller/src/main.cpp @@ -0,0 +1,13 @@ +#include + + +void setup(){ + Serial.begin(9600); + pinMode(0, INPUT); +} + +void loop(){ + Serial.println(analogRead(0)); + + +} \ No newline at end of file diff --git a/src/controller/drone controller/test/README b/src/controller/drone controller/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/src/controller/drone controller/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/src/drone/src/main.cpp b/src/drone/src/main.cpp index 42d83be..b89d5bf 100644 --- a/src/drone/src/main.cpp +++ b/src/drone/src/main.cpp @@ -220,12 +220,12 @@ const int ch5Pin = 21; // gear (throttle cut) const int ch6Pin = 22; // aux1 (free aux channel) const int PPM_Pin = 23; // OneShot125 ESC pin outputs: -const int m1Pin = 0; -const int m2Pin = 1; -const int m3Pin = 2; -const int m4Pin = 3; -const int m5Pin = 4; -const int m6Pin = 5; +const int m1Pin = D0; +const int m2Pin = D1; +const int m3Pin = D2; +const int m4Pin = D3; +const int m5Pin = D4; +const int m6Pin = D5; // PWM servo or ESC outputs: const int servo1Pin = 6; const int servo2Pin = 7; @@ -371,7 +371,7 @@ void setup() { delay(5); // Initialize radio communication - radioSetup(); + // radioSetup(); //commented out because I'm making my own controller // Set radio channels to default (safe) values before entering main loop channel_1_pwm = channel_1_fs; @@ -602,7 +602,7 @@ void getIMUdata() { #elif defined USE_MPU9250_SPI mpu9250.getMotion9(&AcX, &AcY, &AcZ, &GyX, &GyY, &GyZ, &MgX, &MgY, &MgZ); #elif defined USE_BNO085_I2C - //bno magnetometer + //BNO magnetometer MgX = myIMU.getMagX(); MgY = myIMU.getMagY(); MgZ = myIMU.getMagZ();