In recent years, drone applications have been well-liked and used in many fields, such as aerial technology, plant protection, transportation, security, and so on. With the increase of application scenarios, the performance and function requirements of the brain control of drones are strictly requested. I started the Starry Pilot project in 2016. The design concept of flight control is a lightweight, powerful flight control, mainly for scientific research and UAV industry applications, making UAV development technology more popular, but also easier to apply drone technology to various industries.

img

img

img

Outdoor Height Keeping Flying.

img

Gazebo HITL simulating

img

Msh shell system

Integrated Development Environment(IDE)

Hardware Design

The hardware uses the open source project Pixhawk, as shown in the following image. Pixhawk is also the most widely used and supported open source flight control hardware in the world.

img

Main Features are as follows:

Sensor:

Interface:

In addition to the Pixhawk, the entire system also has a number of external electronic devices, such as brushless motor, GPS, electronic speed control, radio modem, RC receiver, Lidar-Lite lidar and so on. The overall system framework is shown below:

img

Software Design

The software is designed in a hierarchical structure, as shown as follows, from the bottom to the top are the Driver layer, RTOS (RT-Thread and Fatfs), HAL hardware virtual layer, Framework layer and application layer.

img

1. Driver Layer

The Driver layer enables the driver of all hardware devices on board Pixhawk, such as sensor devices (gyroscopes, accelerometers, magnetometers, air pressure meters, etc.), bus devices (UART, I2C, SPI, etc.), USB, motor driver, SD card driver, GPS driver, LED, and some on-board devices. Each driver registers with RT-Thread in the form of Device and provides its own init(), read(), write, ioctrl() functions for upper-level calls. Here we are taking the driver of the hmc5883 magnetometer to illustrate the general design steps of the driver.

- Device Initialization Function

The following is the initialization function of hmc5883. First, the Functions of the device functionality are assigned a function pointer, init(), read() and ioctrl() are defined. A driver device named hmc5883 is then registered with RT-Thread, and the upper layer can obtain the driver device by looking for the device name. Next is to set up the corresponding bus device for hmc5883. hmc5883 uses i2c communication, so the corresponding i2c device is found in the initialization.

img

- init()

The Init() function does some initialization for chips, including register configuration.img

- read()

The read() function enables the reading of device data, such as raw magnetic field data and reading the magnetic field data after calibration.img

- ioctrl()

The Ioctrl() function mainly implements the configuration functionalities of some devices, such as setting the range of magnetic field measurement, sampling frequency, etc.img

2. RTOS Layer

In this project, I'm using RT-Thread opensource embedded operating system, it is powerful by providing basic thread scheduling, memory management, synchronization and other basic functions, as well as providing msh shell system, device drive system, making the overall architecture of the system more clear and with more complete functions.

3. HAL Layer
The HAL layer is primarily a further encapsulation of the underlying driver device, abstracting the specific device into the same category of devices. Taking serial devices as an example, different hardware platforms, the bottom driver of the serial port will be different, through the HAL layer, the serial device is encapsulated as a unified interface, so that when the system is ported to different platforms, the upper layer code does not need to make any changes, only need to replace the corresponding underlying driver. This greatly reduces the complexity of system migration.

4. Framework Layer
The Framework layer implements the main functions of drone devices, such as attitude estimation, location estimation, controller, communication, log management, and so on. It is the core of the whole system, most of the functional modules are implemented at this layer.

5. Application Layer
The application layer is the division of the various large functions of drone into a small function. Each function is a separate thread in the system, each thread is responsible for performing its own tasks, and communicates with other threads through the IPC. The Vehicle thread has the highest priority and has an execution cycle of 1ms. It is responsible for all functions related to drone flight, such as status estimation and motor control.

Startup Process
Move to the system startup process. The startup process follows the original structure provided by the RT-Thread. First making the initialization of RTOS in rtthread_*startup(), and then into the rt_application_init(). In this function, an initial thread of init is established, in which the drone modules are initialized. Once the initialization is complete, individual threads are established and awakened according to the definition of the Application layer, and the init threads are eventually destroyed themselves to avoid unnecessary memory consumption.

Features

RT-Thread Contact Info:

Website | Github | Twitter | Facebook | Youtube