Code archive of my bachelor's thesis Research on Cooperative Control Algorithm for UAV Ad-Hoc Network.
-
ROS Noetic
-
Gazebo Classic 11
-
PX4 13
-
Apt Packages:
sudo apt install -y tmux zsh
-
Python Packages:
pip install -r requirements.txt
One command to rule them all:
roscd dmpc_uav_ad_hoc && sh ./scripts/run_all.sh -n <uav_num> -t <simu_time> -a -r # delete -r if you don't want to run immediately.
Or, schedule all the simulations automatically:
python ./scripts/simu_auto_scheduer.py
-
Launch the simulation environment:
roslaunch dmpc_uav_ad_hoc simu_env.launch
-
Launch the swarm controller node:
rosrun dmpc_uav_ad_hoc swarm_controller_launcher.py --uav_num <num>
For specifing setpoint via rviz:
rosrun dmpc_uav_ad_hoc swarm_controller_launcher.py --uav_num <num> --rviz --remap_target_topic
-
Enable the controller: To enable the controller for a UAV, use:
rosservice call /iris_0/enable_ctrl "data: true"
Manage controllers with:
python ./scripts/swarm_controller_switch.py on # enable all controllers python ./scripts/swarm_controller_switch.py off # disable all controllers
uav_controller_node.py
supports ROS dynamic reconfigure mechanism. The tunable parameters are defined in ./config/nmpc.cfg
.You can use rqt_reconfigure
to tune the parameters online.
Note:exclamation:: Set default parameters in
uav_controller_node.py
rather than innmpc.cfg
to avoid unexpected behavior.
-
Instantly shut down Gazebo:
./scripts/kill_gazebo.sh
-
Instantly terminate ROS processes:
./scripts/kill_ros.sh
-
Instantly terminate all processes:
./scripts/kill_all.sh
-
src/uav_controller_node.py
Subscribtions:
/<uav_name>/real_pose
/<uav_name>/target_pose
/<uav_name>/mpc_matrix_q
/<uav_name>/mpc_matrix_r
Publications:
/<uav_name>/opti_traj
/<uav_name>/opti_input
Services:
-
/<uav_name>/enable_ctrl
-
/<uav_name>/set_mpc_matrix
msg type:dmpc_uav_ad_hoc/SetMPCMatrix.srv
Note:exclamation:: Service calling may be laggy, which may cause a decrease in the running speed of other nodes. If synchronous configuration isn't necessarily required, use the topic
/<uav_name>/mpc_matrix_q
and/<uav_name>/mpc_matrix_r
instead. -
/<uav_name>/get_mpc_matrix
-
/<uav_name>/set_controller
msg type:dmpc_uav_ad_hoc/SetController.srv
Set the controller type (nmpc/px4) of the UAV. This action can be performed online.
-
src/perf_analysis_node.py
Subscribtions:
/<uav_name>/real_pose
/<uav_name>/real_twist
/<uav_name>/thrust_est
/crowds/target_net_capacity
/enable_simu
Publications:
/<uav_name>/perf_analyzer/induced_power
/<uav_name>/perf_analyzer/profile_power
/<uav_name>/perf_analyzer/instant_power
/perf_analyzer/ave_curr_net_cap
Average current network capacity of all UAVs./perf_analyzer/ave_tgt_net_cap
Average target network capacity of all UAVs./perf_analyzer/ave_instant_power
/perf_analyzer/cpu_usage
Instant CPU usage of the simulation environment.
-
src/scheduler_node.py
Subscribtions:
<uav_name>/target_pose
<uav_name>/real_pose
/crowds/target_net_capacity
enable_simu
Publications:
<uav_name>/matrix_q
<uav_name>/matrix_r
<uav_name>/max_atti_ang
<uav_name>/max_lin_acc
In this project, the quadrotor dynamics in NED coordinate is formulated as
Which can be rewritten as
CasADi is used to implement Nonlinear Model Predictive Control (NMPC). The NMPC formulation for single UAV is as follows:
Where