Skip to content

About

This is a library of control allocation algorithms used to compare different allocation algorithms and develop new ones.

Resources

Stars

7 stars

Watchers

1 watching

Forks

Latest commit

 

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library of Control Allocation Algorithms

About

This repository is designed for testing a new control allocation algorithm. The algorithm is developed based on simulations from the book "aircraft control allocation" and the QCAT project

The function of control allocation is to generate control effector commands that satisfy constraints within a given moment space. Because of these constraints, only a limited set of moments can be achieved.

This project uses the control allocation problem of ducted fan UAVs as an example to test several well-known open-source control allocation libraries. Several open source linear programming solvers have also been introduced, aiming to develop more efficient allocators for application in real aircraft. A new control allocation algorithm was also developed, which is based on modifications of existing methods. In order to be compatible with existing libraries, this project uses matlab and C/C++ programming languages. Matlab is used for testing and analysis. What is really used for aircraft is the C++ version of the function. For this purpose, We wrote test codes in two languages respectively.

Instructions

clone the coden by --recursive:

git clone https://github.com/mengchaoheng/control_allocation.git --recursive

If , run:

cd [control_allocation] path
git submodule update --init --recursive

For matlab usage:

  1. Run main_control_allocation_benchmark.m for the current PX4 ULog offline benchmark. Set LOG_DIR, LOG_FILE, PYULOG_BIN_DIR, B_CASES, METHODS_TO_RUN, RUN_CPP_ALLOCATOR, and plot/print switches at the top of the file.

  2. parse_control_allocation_flight_data.m reads the log and saves *_command_data.mat. It keeps the original PX4 topic names, builds v_sp_t = [torque; force], and reads u_px4.

  3. After running the main script, print_control_allocation_comparison.m and plot_control_allocation_results.m can also be run alone. They automatically load the latest *_allocation_compare_results.mat.

  4. For the older input-file workflow, run Generate_input_data.m to get input.mat / input.csv, then run test.m or a test_*.m script.

ToDo: fix the bug of LP_lib/linear-programming-using-MATLAB.

If you want to test the differences and similarities between the C++ version and MATLAB's code output, you can compile and run the target main of the alloc_cpp project by ./main. Then the data will be recorded into the output.csv file. Finally, execute test.m to compare (you need to modify the contents of the plot). More detail in alloc_cpp/README.md.

For C/C++ project:

This repository implements the control allocation algorithm based on various mathematical operation libraries. The points 1, 2, 3, and 4 below are not steps but rather ways of using each code implementation.

  1. For alloc_cpp: see readme in the folder.
cd build
cmake ..
make && ./main ## or other target: matlab_code_gen_LPwrap_test, Eingen_based_simplex, alglib_based_minlp_basic.

and then you can run test.m to compare the output of different implement of the algorithm.

  1. For LP_lib/alglib_demo: Run
$ cd build

cd to build folder and run

$ g++ -I ../src/alglib-cpp/src/ -o LPWrap_test.out  ../src/LPwrap/*.cpp ../src/LPwrap/*.c ../src/alglib-cpp/src/*.cpp -w  -O3

$ ./LPWrap_test.out

For test alglib-based vs allocator_dir_LPwrap_4 dir allocator. we can see that running time of the allocator. alglib-based is 1.1416e-05s and allocator_dir_LPwrap_4 is 3.75e-07s. after get the output.csv data file, run test.m for compare with the offline version.

  1. For LP_lib/lp_tiny: cd to path, and run the following command, allocator running time is 0.0002s.
$ 
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./test_input_alloc

The following lib have some bug, maybe the lib can't solve the problem.

  1. For LP_lib/SDLP: Build and run by:
mkdir build && cd build

cmake .. && make

./sdlp_example 

the output is

➜  build git:(main) ./sdlp_example 
optimal sol: 0.155327 0.426713   0.6981   0.6981  1.20496
u: -0.193773 0.0776133     0.349     0.349
optimal obj: -1.20496

It is not the right u but optimal is right.

File structure

  • alloc_cpp: The C++ implementation of control allocation based on linear programming algorithm implemented by eigen is a subfolder that can be run independently.
    • src/LPwrap: the test/main.cpp file used to test the running time of alforithm.
    • src/ControlAllocation: ControlAllocation.h implement simplxuprevsol, DP_LPCA and DPscaled_LPCA of the book "aircraft control allocation" by cpp. to test some function, cd to alloc_cpp/build, then build and run the target by main.cpp. the output can be used in test.m.
    • more to see README of alloc_cpp.
  • control_allocation_lib: some open source allocation lib, be used as submodules.
    • aircraft-control-allocation-book-simulation
    • qcat
  • function_lib: some matlab function used in the project.
  • LP_allocator: LP-based control allocator obtained by modifying the existing control allocation library. Some files come from the project of converting matlab to C language, just for comparison.
  • LP_lib: some open source LP solver lib.
  • PCA: prioritized control allocation (PCA) algorithm, test on matlab.
  • QP_allocator: QP-based control allocator obtained by modifying the existing control allocation library (QCAT ).
  • reformula_LP: The control allocation problem is reformulated into the standard form of the LP problem, and then a control allocator is designed based on the open source LP library, just for comparison.
  • main_control_allocation_benchmark.m: parse a PX4 ULog, set B cases, run selected MATLAB/C++ allocators, print results, and plot comparison figures.
  • parse_control_allocation_flight_data.m: read PX4 ULog topics and save command/allocation data for the benchmark.
  • print_control_allocation_comparison.m: print allocation error, actuator command, and runtime comparison from a saved benchmark result.
  • plot_control_allocation_results.m: plot allocation commands, achieved v, allocation error, and statistics from a saved benchmark result.
  • Generate_input_data.m: use flight data and unit vectors to generate input.mat / input.csv for the older test workflow.
  • test.m: test the allocator.
  • test_*.m: extra tests for specific cases.
  • ac.slx and twin.slx: simulink test.

About

This is a library of control allocation algorithms used to compare different allocation algorithms and develop new ones.

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages