Building block programming for racing drones (3) --- User-defined waypoint automatic flight function (global positioning, where to hit)

Building block programming for racing drones (3) --- User-defined waypoint automatic flight function (global positioning, where to hit)

Anonymous brother June 10, 2023

Users learn the complete solutions of plant protection drones (2021) and delivery drones (2022) in the first two lectures. Careful customers can find that: when the lidar SLAM/T265 binocular camera provides global positioning data, the program design of the autonomous flight part of the UAV is basically through the secondary development mode of the flight control code. Flight control API functions, that is, the realization of automatic flight support functions and navigation control functions.

At the same time, it is necessary to combine the bottom/forward machine vision sensor and the lidar sensor for visual/distance positioning of the target features. For example, in the delivery drone competition, after reaching above the target waypoint, the precise target positioning of the drone can be realized through vision. Realizing the secondary alignment of the drone’s position through vision is actually the function of tracking the moving color blocks in the previous years’ competition questions;

In addition, in some requirements of plant protection drones, it is necessary to identify tower poles and barcode information. The laser radar sensor is used to identify the horizontal position of the tower pole and the angle relative to the direction of the drone's nose, and control the yaw direction of the drone and the distance between the nose and the pole, so that the nose can be aligned with the tower pole. The complex movement of adjusting the distance from the stick and visually identifying features is implemented here using the yaw control API and speed control API functions in the basic flight control functions.

In order to facilitate the rapid secondary development of new users for specific competition content, we have newly added the function of user-defined waypoint flight. Users can enter the waypoint parameters without programming and changing the flight control code by themselves. The man-machine can fly autonomously according to the waypoint actions entered by the user. It should be noted here that the flight action in the custom waypoint automatic flight function provided by default is only a sequential traversal of the waypoints, and does not involve intermediate actions. For example, visual positioning and distance positioning need to be combined with vision/lidar.

The user-defined waypoint automatic flight function provides a simplified autonomous flight framework, and users can quickly modify and arrange flight actions. Designing the waypoint flight mission for a certain competition mission, users can easily realize the automatic flight mission of multi-waypoint targets without repeating the design, and directly refer to this framework, leaving more time for the machine vision part and more refined mission design. In addition, in the national e-sports evaluation, contestants are required to go to the scene to program, so that there is no pressure to quickly realize a certain flight action requirement.

12_ The user can enter the custom waypoint flight function through the ADC button - support the setting of coordinate parameters on the spot (global positioning, pointing to where to play)

Demonstration video: https://www.bilibili.com/video/BV1wP411z7jo/

1 The detection design of the five-way button and the interface design of the waypoint parameter adjustment

According to the user's specific requirement of efficiently inputting waypoint parameters on site, we have upgraded the safety rope button of the previous version of ADC, while retaining the functions of the original four independent buttons of unlocking, developing, locking and landing. , newly added an independent five-way button acquisition ADC channel, one IO port realizes the detection of five direction buttons, and can be equipped with short press, long press, continuous press, multiple jog triggers, etc., further enriching the buttons key value. The five-way button and the OLED display on the extended version can facilitate the modification and storage of multiple parameters.

1.1 ADC key detection principle

The detection principle of the ADC button is that each button is connected with a different resistance value. After the button is pressed, the bias voltage is collected by the ADC port of the single-chip microcomputer after the button is pressed. The interval range is used to judge which button is pressed, and the duration and number of times of pressing are logically processed to realize the response of the button event. This part of the principle has been explained and analyzed in detail in previous tutorials, and it is not the focus of this article. It will not be expanded here. Users can refer to the following links to learn by themselves.

E-sports aircraft safety rope + no remote control button control solution  https://www.bilibili.com/read/cv11399668

E-sports bans "wireless communication and remote control" solutions  https://www.bilibili.com/read/cv7897817

Electric game artifact ADC safety rope button without remote control solution https://www.bilibili.com/video/BV1Gq4y1E7XM

1.2 Waypoint parameter interface design

The OLED display parameter display is divided into 8 lines, the first line displays the page and page number prompt, the second to eighth line data is the coordinate information of the ENU (equivalent to the northeast sky) direction of 1-7 waypoints, of which The input parameter of the EN direction indicates the position increment/decrement relative to the initial reference point. It is a relative position coordinate parameter, not the real-time internal position of the actual UAV. The horizontal position of the two differs by the coordinates of an initial reference point (base_position.x, base_position.y). The input in the U direction is the absolute coordinate information, that is, the height value of the drone from the ground.

Short press the up and down buttons among the five-way buttons to select a parameter, and the * prompt cursor will move to the front of the parameter to be adjusted.

Short press/long press of the left and right keys among the five-way buttons can realize the self-increment and self-decrement of a certain parameter, among which short press is self-increment/subtraction 1, and long press is self-increment/subtraction 50.

Press and hold the middle button in the five-way button to write all the parameters of the current page into EEPROM for power-off storage.

2 Waypoint automatic flight function software realization

The waypoint parameters entered by the user are stored in the EEPROM of the flight controller. Every time the flight controller is powered on, it will read the waypoint parameters from the EEPROM and save them in the param_value parameter array. The parameter of the first waypoint is stored in the first In the three variables starting from dimension 51, the function of the waypoint generation function is to judge whether the data in the waypoint byte segment of the param_value array is all 0, so as to judge whether the waypoint data is valid. Currently, the maximum number of waypoints that can be entered is 28, and customers can flexibly adjust for different competition tasks.

2.1 The first stage - automatic takeoff to cruise altitude method uint8_t Auto_Takeoff(float target)

The function input parameter target is the target height. The automatic takeoff task is divided into two threads. The first step is to record the current 3D position information as the initial origin position of the navigation. And set the desired target height position through the navigation control function. The second step is to detect the altitude deviation value in real time. After 2 seconds to meet the position deviation within 10cm, the function return value is set to 1, and the task of automatically taking off to the target altitude is completed. The usage refers to the usage of case 18 in Developer_Mode.c developer mode, autonomous takeoff After the task is completed, it will enter case 19 to execute the waypoint automatic flight function.

2.2 The second stage - custom waypoint flight Navigation_User_Setpoint(void)

In the first step, set the height expectation to the first operating height of 150cm, the horizontal position expectation to the horizontal position at the time of initial takeoff, and set the hovering time above the takeoff point to 1S, and the hovering time can be adjusted according to actual needs.

After hovering above the take-off point for 1 second, it will judge according to the waypoint data entered by the button. If the waypoint data is valid, this waypoint will be set as the target waypoint, and the thread counter flight_subtask_cnt[n] will be assigned a value of 2, and then enter the waypoint Task execution thread.

Execute the waypoint flight task in thread 2, and judge the 3D position deviation of the UAV in real time. When the deviation is less than a certain threshold for N consecutive times, it can be considered that the current waypoint has arrived, and continue to refresh the information of the next waypoint. When all waypoints are traversed, jump to the third thread to end the whole waypoint traverse process.

Finally, the in-situ landing task in thread 3 is executed. After the drone lands on the ground, the ground detection condition will be triggered and the drone will be automatically locked, ending the entire flight process.

Guess you like

Origin blog.csdn.net/u011992534/article/details/131217150