# Prometheus
**Repository Path**: Jason_Jie/prometheus
## Basic Information
- **Project Name**: Prometheus
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-12-19
- **Last Updated**: 2024-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Simulation User Manual
ubuntu20.04
ros noetic
gazebo 11
电脑建议Ubuntu 20.04,内存建议大于等于16G,如果内存不足可以通过增加Swap空间来避免编译爆内存。Ubuntu20.04电脑默认分配swap 2G,如果编译卡住,也可以通过增加swap空间解决
## 1.update system
```
sudo apt-get update
sudo apt-get upgrade
```
Ensure that the system remains up-to-date in the current version
## 2. install ros
### 2.1 Configure your Ubuntu repositories
Configure your Ubuntu repositories to allow "restricted," "universe," and "multiverse." You can [follow the Ubuntu guide](https://help.ubuntu.com/community/Repositories/Ubuntu) for instructions on doing this.
### 2.2 Setup your sources.list
Setup your computer to accept software from packages.ros.org.
```
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
```
### 2.3 Set up your keys
```
sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
```
### 2.4 Installation
First, make sure your Debian package index is up-to-date:
```
sudo apt update
```
Now pick how much of ROS you would like to install.
**Desktop-Full Install: (Recommended)** : Everything in **Desktop** plus 2D/3D simulators and 2D/3D perception packages
```
sudo apt install ros-noetic-desktop-full
```
To find available packages, see [ROS Index](https://index.ros.org/packages/page/1/time/#noetic) or use:
```
apt search ros-noetic
```
### 2.5 Environment setup
You must source this script in every **bash** terminal you use ROS in.
```
source /opt/ros/noetic/setup.bash
```
It can be convenient to automatically source this script every time a new shell is launched. These commands will do that for you.
If you have more than one ROS distribution installed, `~/.bashrc` must only source the `setup.bash` for the version you are currently using.
```
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
```
### 2.6 Dependencies for building packages
Up to now you have installed what you need to run the core ROS packages. To create and manage your own ROS workspaces, there are various tools and requirements that are distributed separately. For example, [rosinstall](http://wiki.ros.org/rosinstall) is a frequently used command-line tool that enables you to easily download many source trees for ROS packages with one command.
To install this tool and other dependencies for building ROS packages, run:
```
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
```
### 2.6.1 Initialize rosdep
Before you can use many ROS tools, you will need to initialize `rosdep`. `rosdep` enables you to easily install system dependencies for source you want to compile and is required to run some core components in ROS. If you have not yet installed `rosdep`, do so as follows.
```
sudo apt install python3-rosdep
```
With the following, you can initialize `rosdep`.
```
sudo rosdep init
rosdep update
```
### 2.7 ros test
Open a new ternimal:
```
roscore
```
Open a new ternimal:
```
rosrun turtlesim turtlesim_node
```
Open a new ternimal:
```
rosrun turtlesim turtle_teleop_key
```
If the display is as shown in the picture and the small turtle can be controlled to move using the keyboard, it is considered that the installation of ROS is normal.

### 2.8 gazebo
open a new ternimal:
```
gazebo
```
You can see:

## 3. install px4 autopilot
open a new ternimal:
```
git clone https://gitee.com/amovlab/prometheus_px4.git
```
When installing the PX4 firmware for the first time, it is necessary to install the PX4 environment:
```
cd prometheus_px4/Tools/setup
source ./ubuntu.sh
```
Install submodules and related dependencies:
```
cd prometheus_px4
git submodule update --init --recursive
pip3 install --user toml empy jinja2 packaging
```
compile px4:
```
cd prometheus_px4
make amovlab_sitl_default gazebo_p450
```
After compilation, the Gazebo simulation environment will automatically run and load the P450 drone:

## 4. Prometheus configuration
### 4.1 install prometheus
open a new terminal:
```
git clone https://gitee.com/amovlab/Prometheus.git
```
### 4.2 install and compile mavros:
Prometheus_mavros is a MAVROS feature package used in conjunction with the Prometheus project. The connection between the Prometheus project and PX4 for data exchange relies on the MAVROS feature package.
Open the terminal and enter the following command to install prometheus_mavros.
```
cd ~/Prometheus/Scripts/installation/prometheus_mavros
chmod +x install_prometheus_mavros.sh
./install_prometheus_mavros.sh
```
After installation, close the current terminal window and open a new terminal. Enter the following command to test whether prometheus_mavros is installed properly and whether the environment variables are loaded properly.
```
roscd mavros
```
If the path is ~/prometheus_mavros/src/mavros/mavros, it indicates a successful installation.

If there are no errors after the above execution, but roscd mavros does not succeed, then open the. bashrc file
```
gedit ~/.bashrc
source ~/prometheus_mavros/devel/setup.bash
```

Save and exit, then update environment variables in the terminal
```
source .bashrc
```
And then:
```
roscd mavros
```
### 4.3 Dependency Download
### 4.3.1 Update some gazebo model:
Unzip models.zip to ~/.gazebo, Now you can see many gazebo models in ~/.gazebo/models/
Note:
You need to remove the stereo_camera 3d_lidar in ~/.gazebo/models/
```
cd ~/.gazebo/models/
rm -r stereo_camera/ 3d_lidar/ 3d_gpu_lidar/ hokuyo_lidar/
```
### 4.3.2 Remote control simulation driver installation
```shell
## Install remote control simulation driver
sudo apt-get install jstest-gtk
## After installation, you can run the following command in the terminal to confirm whether the remote control is working properly and the response of the joystick and buttons
jstest-gtk
```

### 4.4 Compile Prometheus
Enter the following command to compile the Prometheus project.
```
cd Prometheus
# When using it for the first time, it is necessary to add executable permissions to the compiled script file
chmod +x compile_*
# Compile control function module
./compile_control.sh
```

## 4.5 Other configurations
Environment variable configuration
Open the terminal and enter the following command to open the. bashrc file.
```
gedit ~/.bashrc
```
Copy the following content to the. bashrc file, save and exit. If there is already relevant content in. bashrc, there is no need to add it again.
```
source ~/prometheus_mavros/devel/setup.bash
source ~/Prometheus/devel/setup.bash
export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:~/Prometheus/devel/lib
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/Prometheus/Simulator/gazebo_simulator/gazebo_models/uav_models
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/Prometheus/Simulator/gazebo_simulator/gazebo_models/ugv_models
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/Prometheus/Simulator/gazebo_simulator/gazebo_models/sensor_models
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/Prometheus/Simulator/gazebo_simulator/gazebo_models/scene_models
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/Prometheus/Simulator/gazebo_simulator/gazebo_models/texture
source ~/prometheus_px4/Tools/setup_gazebo.bash ~/prometheus_px4 ~/prometheus_px4/build/amovlab_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/prometheus_px4
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/prometheus_px4/Tools/sitl_gazebo
```
## 5. Introduction to Simulation
### 5.1 Installation of commonly used development tools
Vscode
VSCode (full name: Visual Studio Code) is a free cross platform source code editor developed by Microsoft. This software supports syntax highlighting, code auto completion (also known as Intelligence), code refactoring, view definition functionality, and comes with built-in command-line tools and Git version control system. Users can change the theme and keyboard shortcuts to achieve personalized settings, and can also install extensions through the built-in extension store to expand software functionality.
https://code.visualstudio.com/Download
After opening the VSCode download link, the following interface will appear. Click on the. deb download method.

In general, the default download is in the Downloads folder. Enter the following command to install.
```
cd ~/Downloads
sudo dpkg -i ***.deb
```
QGroudControl
QGroundControl, abbreviated as QGC, is a ground station software that interacts with PX4 flight control communication connection. The official website has very comprehensive instructions for downloading and installing it, so there will be no further explanation here. You can refer to the official website to complete the download and installation.
*QGroundControl* can be installed/run on Ubuntu LTS 20.04 (and later).
Ubuntu comes with a serial modem manager that interferes with any robotics related use of a serial port (or USB serial). Before installing *QGroundControl* you should remove the modem manager and grant yourself permissions to access the serial port. You also need to install *GStreamer* in order to support video streaming.
Before installing *QGroundControl* for the first time:
On the command prompt enter:
```
sudo usermod -a -G dialout $USER
sudo apt-get remove modemmanager -y
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y
sudo apt install libfuse2 -y
sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor-dev -y
```
1. Logout and login again to enable the change to user permissions.
To install *QGroundControl*:
1. Download [QGroundControl.AppImage](https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage).
2. Install (and run) using the terminal commands:
```
chmod +x ./QGroundControl.AppImage
./QGroundControl.AppImage (or double click)
```
### 5.2 PX4-Gazebo Simulation principle
Simulation interaction process

### 5.3 Composition of project functional modules
**Uav-control:** The basic module in the Prometheus project, responsible for the interface between other upper level functional modules and the underlying MAVROS for data exchange
**gazebo_simulator:** Simulation module, including indoor and outdoor drone simulation models, simulation environment, Gazebo plugin, and launch files for simulation startup, etc
**turtorial_demo:** Example module, including basic tutorial source code and corresponding startup launch files for most of the Prometheus project's functional modules
**planning:** Path planning module
**object_detection:** Visual inspection module(TODO)
**swarm_control:** Cluster control module(TODO)
## 6. Drone control module - uav_control
**uav_control code framework**
UAV_controller consists of two functional modules: UAV_controller (drone control) and UAV_estimator (drone status);
The core logic of a loop in the uav-controller module is:
1.Drone status check, including flight control connection status, positioning status, geofencing, etc
2. Check the control status of the drone, including the four control states of Init, RC_POS_CONTROL, COMMAND_CONTROL, and LAND_CONTROL, and assign values to the control variables
3. If the status of the drone is in the initial state, this cycle ends
4. Send control command
The core logic of a loop in the uav_estimator module is:
1. Subscribe to drone status, battery status, drone positioning data, external positioning data, etc.
2. If external positioning data is used, send the positioning data to MAVROS
3. Print and display drone related data
4. Send relevant prompt information to the ground station
### 6.1 uav_control_node introduction
The source code of the uav_control module is placed in the folder Prometheus/Modules/uav_control, and the corresponding ROS function package is named prometheus_uav_control. This module is the basic module of the Prometheus project, which completes the data interaction between other functional modules of Prometheus and mavros nodes.
Both the publishing topic and the subscription topic have the namespace /uav*. Different drone numbers correspond to different namespaces. Generally, the default namespace is /uav1.
**publish topics**
- /uav*/mavros/setpoint_raw/attitude(mavros_msgs/AttitudeTarget)
Expected drone attitude control amount
- /uav*/mavros/setpoint_raw/global(mavros_msgs/GlobalPositionTarget)
Expected high control volume of drone latitude and longitude
- /uav*/mavros/setpoint_raw/local(mavros_msgs/PositionTarget)
The desired control quantity of the drone ENU coordinate system (including position, velocity, acceleration, etc.)
- /uav*/mavros/vision_pose/pose(geometry_msgs/PoseStamped)
External positioning data interface provided by MAVROS
- /uav*/prometheus/control_state(prometheus_msgs/UAVControlState)
Prometheus control status
- /uav*/prometheus/odom(nav_msgs/Odometry)
Drone odometery data
- /uav*/prometheus/offset_pose(prometheus_msgs/OffsetPose)
Position offset in ENU coordinate system
- /uav*/prometheus/state(prometheus_msgs/UAVState)
Drone status collection, including position, speed, attitude, mode, etc.
- /uav*/prometheus/text_info(prometheus_msgs/TextInfo)
Print information fed back to the ground station
- /uav*/prometheus/trajectory(nav_msgs/Path)
Drone motion trajectory
- /uav*/prometheus/uav_mesh(visualization_msgs/Marker)
Drone position (with icon) for RVIZ display
**Subscribe to Topic**
- /uav*/mavros/battery(sensor_msgs/BatteryState)
drone battery status
- /uav*/mavros/global_position/global(sensor_msgs/NavSatFix)
The current latitude and longitude data of the drone, after being fused by the flight control.
- /uav*/mavros/gpsstatus/gps*/raw(mavros_msgs/GPSRAW)
GPS module data status
- /uav*/mavros/imu/data(sensor_msgs/Imu)
IMU module data
- /uav*/mavros/local_position/pose(geometry_msgs/PoseStamped)
UAV position data in ENU coordinate system
- /uav*/mavros/local_position/velocity_local(geometry_msgs/TwistStamped)
Current speed data of the drone's ENU coordinate system
- /uav*/mavros/setpoint_raw/target_attitude(mavros_msgs/AttitudeTarget)
The attitude setting value of the drone in PX4 (coordinate system: ENU system)
- /uav*/mavros/setpoint_raw/target_local(mavros_msgs/PositionTarget)
Position/speed/acceleration setting values of drones in PX4 (coordinate system: ENU system)
- /uav*/mavros/state(mavros_msgs/State)
Drone Current Status (PX4)
- /uav*/prometheus/command(prometheus_msgs::UAVCommand)
Drone control commands (for COMMAND_CONTROL mode)
- /uav*/prometheus/fake_rc_in(mavros_msgs/RCIn)
PX4 Remote Controller Data
- /uav*/prometheus/offset_pose(prometheus_msgs::OffsetPose)
Position offset in the ENU coordinate system
- /uav*/prometheus/set_local_offset_pose(prometheus_msgs::OffsetPose)
Set the position offset of the drone in the ENU coordinate system
- /uav*/prometheus/setup(prometheus_msgs/UAVSetup)
Drone Setup command
- /uav*/prometheus/state(prometheus_msgs/UAVState)
A collection of drone status, including position, speed, attitude, mode, etc.
**parameter:**
uav_id:
参数说明: 无人机编号
单位: -
数据类型: int
默认值: 1
备注: 无
sim_mode:
参数说明: 是否为仿真
单位: -
数据类型: bool
默认值: true
备注: true代表为仿真模式,false代表为非仿真模式
control/pos_controller:
参数说明: 控制器标志位
单位: -
数据类型: int
默认值: 0
备注: 0: PX4_ORIGIN, 1: PID, 2: UDE, 3: NE
control/enable_external_control:
参数说明: 是否使用外部控制器
单位: -
数据类型: bool
默认值: false
备注: true代表使用外部控制器,false代表不使用外部控制器
control/Takeoff_height:
参数说明: 起飞高度(command_control模式下的起飞高度)
单位: 米
数据类型: float
默认值: 1.0
备注: 无
control/Disarm_height:
参数说明: land_control模式下自动上锁的高度
单位: 米
数据类型: float
默认值: 0.2
备注: 无
control/Land_speed:
参数说明: land_control模式下下降的速度
单位: 米
数据类型: float
默认值: 0.2
备注: 位置坐标系为ENU坐标系
control/location_source:
参数说明: 定位数据来源
单位: 无
数据类型: int
默认值: 4
备注: 0: MOCAP, 1: T265, 2: GAZEBO, 3: FAKE_ODOM, 4: GPS, 5: RTK, 6: UWB
control/maximum_safe_vel_xy:
参数说明: XY轴最大安全速度
单位: 米/秒
数据类型: float
默认值: 4.0
备注: 无
control/maximum_safe_vel_z:
参数说明: Z轴最大安全速度
单位: 米/秒
数据类型: float
默认值: 3.0
备注: 无
control/maximum_vel_error_for_vision:
参数说明: 最大vision/px4速度误差
单位: 米/秒
数据类型: float
默认值: 1.0
备注: 无
geo_fence/x_min:
参数说明: 地理围栏X轴最小值
单位: 米
数据类型: float
默认值: -100.0
备注: 位置坐标系为ENU坐标系
geo_fence/x_max:
参数说明: 地理围栏X轴最大值
单位: 米
数据类型: float
默认值: 100.0
备注: 位置坐标系为ENU坐标系
geo_fence/y_min:
参数说明: 地理围栏Y轴最小值
单位: 米
数据类型: float
默认值: -100.0
备注: 位置坐标系为ENU坐标系
geo_fence/y_max:
参数说明: 地理围栏Y轴最大值
单位: 米
数据类型: float
默认值: 100.0
备注: 位置坐标系为ENU坐标系
geo_fence/z_min:
参数说明: 地理围栏Z轴最小值
单位: 米
数据类型: float
默认值: -100.0
备注: 位置坐标系为ENU坐标系
geo_fence/z_max:
参数说明: 地理围栏Z轴最大值
单位: 米
数据类型: float
默认值: 100.0
备注: 位置坐标系为ENU坐标系
### 6.2 无人机控制模块教学例程
无人机控制模块作为Prometheus项目的**基础子模块**,Prometheus项目中其余子模块均会通过控制模块与无人机进行数据交互。所以**学习Prometheus项目**以及**通过Prometheus项目进行无人机二次开发**都是需要先从控制模块开始学习。
在控制模块我们提供了对应的**教学例程**,包含**起飞降落**、**惯性系控制**、**机体系控制**、**经纬高控制**、**轨迹控制**以及**集群控制**六个教学例程。通过教学例程大家能够快速了解控制模块的相关**数据接口**,也能够通过学习例程demo的源码学习控制模块的**二次开发**。
教学例程提供有C++以及Python两种语言的源码,用户可自行选择相应的源码文件进行学习。
- 控制模块源码文件位置:/Prometheus/Modules/uav_control
- 教学例程demo源码文件:/Prometheus/Modules/tutorial_demo/basic
#### 6.2.1 无人机控制模块教学例程-起飞降落
起飞降落demo对应脚本文件位于 `~/Prometheus/Scripts/simulation/tutorial_demo/takeoff_land/takeoff_land_P450.sh`
操作步骤:
1. 将遥控器开机并通过USB接口接入电脑
2. 输入以下命令启动起飞降落仿真demo
```
cd ~/Prometheus/Scripts/simulation/tutorial_demo/takeoff_land
# 第一次启动该脚本时,需要添加可执行权限
chmod +x takeoff_land_P600.sh
./takeoff_land_P600.sh
```
3. 遥控器按下start button解锁无人机
4. 遥控器按下X button 将无人机控制状态切换到RC_POS_CONTROL
5. 遥控器按下Y button 将无人机控制状态切换到COMMAND_CONTROL
6. 无人机将自动起飞,到达预设高度后悬停30秒,随后自动降落
检查终端运行是否正常
ros主节点
- 下图所示为正常运行

PX4飞控仿真
- 下图所示为正常运行

Prometheus控制
- 下图所示为正常运行

Prometheus控制demo,起飞降落
- 下图所示为正常运行

正常启动仿真界面
- 下图所示为正常运行

遥控器按下start button解锁无人机, 遥控器按下X button 将无人机控制状态切换到RC_POS_CONTROL, 遥控器按下Y button 将无人机控制状态切换到COMMAND_CONTROL, 无人机将自动起飞,到达预设高度后悬停30秒,随后自动降落
演示视频demo:
**节点运行图:**

起飞降落例程主要包含 `/joy_node`、`/uav1/mavros`、`/uav_control_main_1`、`/takeoff_land`等ROS节点。
- `/joy_node`节点为遥控器ROS驱动节点,用以获取遥控器数据。
- `/uav1/mavros`节点为飞控ROS驱动节点,与飞控进行数据交互。在仿真中,该驱动节点与模拟飞控进行数据交互。
- `/uav_control_main_1`节点为Prometheus项目中最基础的ROS节点,所有Prometheus项目的功能模块都通过该节点与无人机进行数据交互。
- `/takeoff_land`节点为起飞降落节点,通过 `/uav_control_main_1`节点提供的数据接口获取无人机数据以及控制无人机。
从节点运行图中,我们可以看到 `/takeoff_land`节点与 `/uav_control_main_1`节点进行数据交互主要有**三个ROS话题**
- /uav1/prometheus/command:无人机控制接口,对应的消息为 `prometheus_msgs/UAVCommand`
- /uav1/prometheus/state:无人机状态,对应的消息为 `prometheus_msgs/UAVState`
- /uav1/prometheus/control_state:无人机控制状态,对应的消息为 `prometheus_msgs/UAVControalState`
建议阅读 `/Prometheus/Modules/common/prometheus_msgs/msg`内对应的消息文件,了解上面提到的三个消息的详细定义。
**代码讲解**
源码文件名为 `takeoff_land.cpp`
位于 `/Prometheus/Modules/tutorial_demo/basic/takeoff_land/src`文件夹下
```
//时间戳
uav_command.header.stamp = ros::Time::now();
//坐标系
uav_command.header.frame_id = "ENU";
//Init_Pos_Hover初始位置悬停,可在uav_control_indoor.yaml或uav_control_outdoor.yaml文件设置无人机悬停高度
uav_command.Agent_CMD = prometheus_msgs::UAVCommand::Init_Pos_Hover;
//发布的命令ID,每发一次,该ID加1
uav_command.Command_ID = 1;
//发布起飞命令
uav_command_pub.publish(uav_command);
```
```
//时间戳
uav_command.header.stamp = ros::Time::now();
//坐标系
uav_command.header.frame_id = "ENU";
//Land降落,从当前位置降落至地面并自动上锁
uav_command.Agent_CMD = prometheus_msgs::UAVCommand::Land;
//发布的命令ID加1
uav_command.Command_ID += 1;
//发布降落命令
uav_command_pub.publish(uav_command);
```
该demo为Prometheus 起飞&降落控制接口开发示例,核心代码如上图所示;主要是填充以下数据:
1. Agent_CMD设置为Init_Pos_Hover模式,该模式为起飞;Agent_CMD设置为Land,该模式为降落
2. 每发送一次数据,Command_ID加1
3. 时间戳通过调用 `ros::Time::now()`函数获取当前ROS系统时间并赋值即可,`frame_id`并不影响功能,但建议与控制命令所采用的坐标系一致。
## 7. 路径规划模块
### 7.1 ego_planner_swarm模块介绍
ego_planner_swarm 是 ego-planner 的扩展模块,专为多台无人机的协作和自主导航设计。该模块旨在帮助多个无人机在复杂和动态的环境中进行协同工作和自主决策,提升它们的自主性和效率。相关源代码位于 ~/Prometheus/Modules/ego_planner_swarm 文件夹下。具体特点和功能包括:
```
- 高度自主决策 : 无人机能够实时感知环境变化并自主调整飞行策略,确保任务高效完成。
- 协同导航 : 无人机能够接收来自更高优先级无人机的轨迹信息,并将其存储起来,以便在需要时参考这些轨迹来为自己规划出更加安全的飞行路径。
- 去中心化架构 : 完全自主与分散式设计,每台无人机独立决策,无需中央控制,提升了系统的灵活性和鲁棒性。
```
### 7.2 关键话题与参数介绍
**发布话题和订阅话题中均带有命名空间/uav~,无人机编号不同则对应的命名空间不同,单机时默认为:/uav1**
**订阅话题:**
- /broadcast_bspline (traj_utils/Bspline)
无人机当前时刻及未来一段时间内的飞行轨迹
- /uav1/mavros/local_position/odom (nav_msgs/Odometry)
无人机里程计数据
- /uav1/octomap_point_cloud_centers (sensor_msgs/PointCloud2)
无人机点云数据
- /uav1/prometheus/motion_planning/goal (geometry_msgs/PoseStamped)
无人机目标点
**发布话题:**
- /broadcast_bspline (traj_utils/Bspline)
每台无人机当前时刻及未来一段时间内的飞行轨迹
- /uav1/planning/bspline (traj_utils/Bspline)
一号无人机规划的B样条轨迹
- /uav1_ego_planner_node/grid_map/occupancy_inflate (sensor_msgs/PointCloud2)
无人机膨胀后的点云数据
- /uav1/prometheus/command (prometheus_msgs/UAVCommand)
无人机控制指令
- /uav1_ego_planner_node/global_list (visualization_msgs/Marker)
无人机规划的全局点合集,用于RVIZ显示
- /uav1_ego_planner_node/goal_point (visualization_msgs/Marker)
无人机终点,用于RVIZ显示
- /uav1_ego_planner_node/optimal_list (visualization_msgs/Marker)
无人机优化的轨迹,用于RVIZ显示
**参数:**
- uav_id :
参数说明: 无人机编号
单位:
数据类型: int
默认值: 1
备注: 无
- map_size_x_ :
参数说明: 规划范围,x 方向
单位: 米
数据类型: double
默认值: 50.0
备注:
- map_size_y_ :
参数说明: 规划范围,y 方向
单位: 米
数据类型: double
默认值: 50.0
备注:
- map_size_z_ :
参数说明: 规划范围,z 方向
单位: 米
数据类型: double
默认值: 3.0
备注:
- odometry_topic :
参数说明: 订阅的里程计话题
单位:
消息类型: nav_msgs/Odometry
默认值: /mavros/local_position/odom
备注: 在advanced_param.xml文件中加了前缀 /uav* ,可根据自身需求进行替换
- cloud_topic :
参数说明: 订阅的点云话题
单位:
消息类型: sensor_msgs/PointCloud2
默认值: /uav1/octomap_point_cloud_centers
备注:
- max_vel :
参数说明: 最大飞行速度
单位: m/s
数据类型: double
默认值: 0.8
备注:
- max_acc :
参数说明: 最大加速度
单位: m/s^2
数据类型: double
默认值: 6.0
备注:
- planning_horizon :
参数说明: 规划范围
单位: m
数据类型: double
默认值: 7.5
备注: 一般设置为传感器的1.5倍
- yaw_init :
参数说明: 偏航角初始值
单位: rad
数据类型: double
默认值: 0.0
备注:
- fsm/thresh_replan_time :
参数说明: 重规划时间
单位: rad
数据类型: double
默认值: 1.0
备注:
- fsm/thresh_no_replan_meter :
参数说明: 重规划阈值
单位: m
数据类型: double
默认值: 1.0
备注: 在阈值范围内,停止规划
- grid_map/resolution :
参数说明: 地图分辨率
单位:
数据类型: double
默认值: 1.0
备注:
- grid_map/local_update_range_x :
参数说明: x 方向截断距离
单位: m
数据类型: double
默认值: 5.5
备注: y z 方向同理
- grid_map/obstacles_inflation :
参数说明: 障碍物膨胀距离
单位: m
数据类型: double
默认值: 0.5
备注: 为保证飞行安全,膨胀距离最小设置为无人机最大尺寸的一半
### 7.3 单机避障教学例程
**仿真使用demo-D435i视觉避障**
提示:
运行Demo前请将该模块编译
编译代码如下:
```
cd ~/Prometheus
catkin_make --source Modules/ego_planner_swarm --build build/ego_planner_swarm
```
仿真脚本启动流程:
1. 将Xbox360遥控器通过USB接入电脑
2. 输入一下命令启动避障仿真demo:
```
cd ~/Prometheus/Scripts/simulation/ego_planner/
# 第一次启动该脚本时,需要添加可执行权限
chmod +x ego_planner_p450_d435i.sh
./ego_planner_p450_d435i.sh
```

**开始仿真**
1. 使用遥控器start按键, 解锁无人机
2. 使用遥控器X按键, 切换到RC_POS_CONTROL控制
3. 使用遥控器Y键, 切换到COMMAND_CONTROL控制,无人机会自主起飞
4. 选择 3D Nav Goal
- 选择后鼠标的图表会发生变化

5. 开始指点
- 鼠标左键点击目标点,然后不松开,拖向无人机方向,然后按住鼠标左键的同时,按下鼠标右键,在画面内向上划,可以提供Z的高度

**注意:**如果不按住鼠标左键,在画面内向上划,提供Z的高度,那么Z的高度默认为0,则会出现到达不了目标点的情况!
6. 开始自主规划避障

红色的轨迹就是规划出来的避障轨迹
7. 到达后再次规划
- 按照步骤再次指点规划
**节点运行图:**

例程主要包含`/joy_node`、`/uav1/mavros`、`/uav_control_main_1`、`/octomap_server`、`/gazebo`、 `/uav1_ego_planner_node`、`/uav1_traj_server_for_prometheus`等ROS节点。
- `/joy_node`节点为遥控器ROS驱动节点,用以获取遥控器数据,通过话题`uav1/prometheus/fake_rc_in`将遥控器数据传输给`/uav_control_main_1`节点。
- `/uav1/mavros`节点为飞控ROS驱动节点,与飞控进行数据交互。在仿真中,该驱动节点与模拟飞控进行数据交互。
- `/uav_control_main_1`节点为Prometheus项目中最基础的ROS节点,所有Prometheus项目的功能模块都通过该节点与无人机进行数据交互。
- `/octomap_server`节点为建图服务节点,通过仿真D435i点云数据来进行建图。
- `/gazebo`节点为gazebo ROS驱动节点,为`/octomap_server`节点提供局部点云数据,来进行建图
- `/uav1_ego_planner_node`节点为ego_planner规划节点,通过`/octomap_server`节点的话题数据进行建图,输出`/uav1/planning/bspline`,来进行路线规划
- `/uav1_traj_server_for_prometheus`节点为轨迹生成节点,由B样条(bspline)生成轨迹,转化为command命令控制无人机飞行
从节点运行图中,我们可以看到有如下的数据话题
- /uav1/prometheus/command:无人机控制接口,对应的消息为`prometheus_msgs/UAVCommand`
- /uav1/prometheus/state:无人机状态,对应的消息为`prometheus_msgs/UAVState`
- /uav1/prometheus/fake_rc_in:仿真模拟PX4遥控器数据
- /camera/depth/color/points:局部点云话题输入
- /octomap_point_cloud_centers:点云信息,仿真中由map_generator产生
- /broadcast_bspline:广播的B样条
- /uav1/planning/bspline:发布的B样条
建议阅读`/Prometheus/Modules/common/prometheus_msgs/msg`内对应的消息文件,了解上面提到的消息详细定义。
**代码讲解:**
脚本位于`/home/amov/Prometheus/Scripts/simulation/ego_planner/ego_planner_p450_d435i.sh`,打开规划脚本如下

除了运行ros必备启动的roscore,脚本依次运行了四个launch文件
1.sitl_p450_d435i.launch
2.uav_control_main_outdoor.launch
3.depth_to_octomap.launch
4.sitl_ego_planner_basic_octomap.launch
依次查看
1.sitl_p450_d435i.launch
```
```
启动prometheus_gazebo下gazebo环境,带有仿真D435i的无人机模型,以及rviz
2.uav_control_main_outdoor.launch
```
```
在prometheus_uav_control,启动UAV1控制节点,Prometheus下控制,为后面路径规划发送控制指令做准备
3.depth_to_octomap.launch
```
```
在prometheus_gazebo下启动octomap建图服务,为后面ego规划做准备。octomap_server是ROS中一个基于octomap的功能包,具有将点云地图转化为基于Octree的OctoMap的功能。
在ROS中,octomap_server和octomap_map都是用于构建三维地图的软件包。octomap_server软件包提供了一种将输入数据转换为OctoMap格式的方法。它可以将来自激光雷达或深度摄像头等传感器的数据转换为三维点云,并使用这些点云构建OctoMap。octomap_server还可以将OctoMap数据发布为ROS中的OctoMap消息,以便其他ROS节点可以使用它们。octomap_map软件包提供了一种使用OctoMap数据构建环境模型的方法。它可以订阅来自octomap_server的OctoMap消息,并使用该消息构建一个三维地图。该地图可以用于机器人的定位、路径规划和避障等任务。octomap_server用于构建OctoMap数据,而octomap_map用于将OctoMap数据转换为实际可用的地图。
4.sitl_ego_planner_basic_octomap.launch
```
```
在ego_planner包下启动ego_planner 仿真,并由B样条生成轨迹,发送控制指令给无人机,控制飞行。其中包含两部分`/uav1_ego_planner_node`和`/uav1_traj_server_for_prometheus`,
前者`/uav1_ego_planner_node`进行ego_planner规划,相关源代码参见ego_planner_node.cpp ,ego_replan_fsm.cpp,planner_manager.cpp,路径:/home/amov/Prometheus/Modules/ego_planner_swarm/plan_manage/src/。
EGO-Planner是一个无ESDF(欧几里得符号距离场)的基于梯度的局部路径规划框架,EGO-Planner由基于梯度的样条优化器和后细化两部分组成。
可以查看[EGO-Planner代码讲解](https://www.bilibili.com/video/BV1JL4116731/?spm_id_from=333.337.search-card.all.click&vd_source=22700b18fe6952d84f47cff1b4be2491)来深入了解EGO-Planner
后者`/uav1_traj_server_for_prometheus`订阅ego_planner规划结果,由B样条(bspline)生成轨迹,转化为command命令控制无人机飞行。其源代码为traj_server_for_prometheus.cpp,路径:~/Prometheus/Modules/ego_planner_swarm/plan_manage/src_for_prometheus/
**操作演示视频:**
// TODO
## 8.gazebo简易教程
### 8.1 介绍
• 在gazebo中,我们不仅可以对⽆⼈机建模,还可以对场景建模(即机器⼈所在环境),以下给⼤家介绍如何在gazebo中创建⼀栋房⼦,作为⽆⼈机的活动空间。
#### 8.1.1 打开场景编辑器
启动gazebo,依次点击 `Edit -> Building Editor`, 或者使用快捷键 `Ctrl+B` 打开编辑器。界面如下:

#### 8.1.2 UI介绍
***该编辑器由以下3个区域组成:***
1. 调色板,在这里你可以选择你的建筑特征和材料。
2. 2D视图,你可以导入楼层平面图,编辑器会根据平面图自动插入插入墙壁,门窗和楼梯。
3. 3D视图,在这里你可以看到你的建筑物的预览。您还可以在其中为建筑物的不同部分分配颜色和纹理。

#### 8.1.3 场景
场景是模拟器的主要部分,是仿真模型显⽰的地⽅,你可以在这操作仿真对象,使其与环境进⾏交互。
## 9. 其他
### 9.1 ROS常见指令
roscore
启动ROS核心程序,包含master主节点,ros参数服务器,ros日志记录节点
rosrun
启动任意ros功能包中的可执行节点,运行rosrun命令需要确保ROS主节点已经启动
```
# 用法示例
rosrun package_name executable_name
```
roslaunch
启动任意ros功能包中的launch文件,launch文件可启动多个ROS节点以及设置ROS参数,在启动launch文件时,会自动检测是否运行roscore,如果没有将自动运行
```
# 用法示例
roslaunch package_name launch_file.launch
```
rosnode
显示ROS节点相关信息
```
rosnode info # 打印有关节点信息
rosnode kill # 杀死一个正在运行的节点
rosnode list # 列出所有正在运行的节点列表
rosnode machine # 列出在特定机器上运行的节点或列出机器
rosnode ping # 测试节点的连接状态
rosnode cleanup # 清除不可达节点的注册信息
```
rostopic
显示ROS话题相关信息
```
rostopic bw # 显示话题的带宽
rostopic delay # 显示话题通信的延迟
rostopic echo # 打印话题中的消息内容
rostopic find # 按消息类型查找话题
rostopic hz # 话题发布消息的频率
rostopic info # 话题发布的信息
rostopic list # 显示话题列表
rostopic pub # 发布消息到某一话题
rostopic type # 打印话题消息类型
```
rosmsg
显示ROS消息相关信息
```
rosmsg show # 显示消息的具体数据类型以及变量名
rosmsg list # 显示消息列表
```
rosservice
显示ROS服务相关信息
```
rosservice call # 使用提供的参数调用服务
rosservice find # 按服务类型查找服务
rosservice info # 打印服务的信息
rosservice list # 显示服务列表
rosservice type # 打印服务消息类型
```
rossrv
```
rossrv show # 显示服务消息的具体数据类型以及变量名
rossrv list # 显示服务消息列表
```
rosparam
显示ROS参数相关信息
```
rosparam list # 显示参数列表
rosparam get # 获取参数变量
rosparam set # 设置某一参数值
rosparam delete # 删除某一参数变量
```
rosclean
清除ROS日志,超过1GB时,ROS系统会出现红字提醒
```
rosclean check # 检查ROS日志文件的磁盘使用情况
rosclean purge # 删除存储的ROS日志文件
```
roscd
直接通过功能包名搜寻到目标功能包路径,也可以搜寻其他ROS文件或文件夹
rosbag
记录ROS相关话题信息
```
rosbag record # 记录某一话题信息
rosbag info # 总结一个bag文件的内容
rosbag play # 播放一个bag文件的话题信息
rosbag check # 确定一个bag文件在当前系统中是否可以播放或迁移
rosbag fix # 修复bag文件的信息,使其可以在当前系统中播放
```
catkin_init_workspace
声明终端当前路径所在文件夹为ROS工作空间
catkin_create_pkg
创建一个ros功能包,改命令后第一个参数为新建功能包名字,后面的参数为依赖功能包名
```
# 用法示例
catkin_create_pkg package_name depend1 depend2 depend3
```