Skip to content

README.md

Machine-translated by Robotheca from the original in Japanese (opens in a new tab). License: MIT (opens in a new tab).

firmwareフォルダの中身について

drone_PID_1 folder

The coding, building, and compiling were done using the VSCode extension "PlatformIO". It contains the 1_include folder, 2_lib folder, 3_platformio.ini file, and 4_src folder. The explanation of each follows.

1_include folder

Not used in particular.

2_lib folder

Not used in particular.

3_platformio.iniファイル

The file that specifies the target board type, the serial communication baud rate, and the libraries to include.

4_src folder

This is where the code itself lives. .cpp files contain the actual function implementations. .h files contain declarations of functions and constants, as well as includes for the external libraries that are needed. A brief description follows.

control.cpp and .h files
  • Setup functions for driving the motors via PWM, and the functions that actually drive them
  • Functions that perform PID control based on ① the roll, pitch, and yaw (RPY) attitude angles obtained from madgwick.cpp, and ② the target angle or angular velocity values received in interfaceBLE.cpp

and so on are written here. There are both single-loop angle PID control functions and cascade control functions.

debug.cpp file and .h file
  • Functions for debugging via the serial monitor connected to a PC

are written.

imu.cpp and .h files
  • Setup function for the 9-axis IMU sensor
  • Function that calibrates the sensor's gyro values
  • Function that reads the sensor's nine values
  • Function that applies a low-pass filter to the sensor

and so on. Note that because the DLPF setting has been enabled, the function that would apply a fourth low-pass filter does not actually apply any filter.

interfaceBLE.cpp and .h files
  • Setup functions for BLE communication
  • Functions that read commands when they arrive as binary communication
  • Wireless debug functions for sending NOTIFY (transmission) from our side to the smartphone

and so on are written here. Since I did not major in information engineering or communication engineering and this was my first time, it was the most difficult part, and I ended up relying mostly on ChatGPT.

madgwick.cpp and .h files

These contain a function that calculates the RPY attitude angles from the 9 (or 6) values obtained by the read functions in imu.cpp.

It uses the functions of the MadgwickfilterAHRS.h library as they are.

  • ① 9-axis (3-axis gyro + 3-axis accelerometer + 3-axis magnetometer)
  • ② 6-axis (3-axis gyro + 3-axis accelerometer)

You can choose either ① or ②, but the magnetometer did not work well due to the influence of electromagnetic fields generated by motor rotation, so the calculation currently uses ②.

main.cpp file
  • A void setup() function that runs the various setup functions described above
  • A void loop() function that performs BLE command value updates → sensor readings → attitude angle acquisition with MWF → PID calculation and motor output → various debug transmissions

are written. For detailed operating specifications, please also see the YouTube videos linked from the README in Example_MITAppInventor_for_DroneController (opens in a new tab).

struct.h File

In this drone code, structures are used for passing values. Related parameters can be managed as a single unit, which improves code readability and extensibility.
Especially in drone control, which handles multidimensional data such as position, velocity, and attitude, I considered data management with structures to be suitable. This file defines various data structures.

Files by @Haruki-Ayukawa, at commit 11fc08a, read from GitHub in your browser. Hardware license: MIT; software license: MIT. Robotheca doesn't review code: read it before running it.