PX4仿真方案

PX4仿真方案
AyaPX4 仿真调试
建议在 WSL 上进行仿真
不要在板载上进行仿真!!!!
该仿真方案所采用的环境为 Ubuntu20.04 ROS2-Foxy
如需进行 Ubuntu22.04 环境的仿真,自行将 Gazebo Classic 改为 gz_x500
前置环境
安装 ros2
conda 安装
看查内核版本
1
uname -m
诺为 x86_64:
安装相应的 x86_64 版本的 conda:
1
2
3
4wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2024.10-1-Linux-x86_64.sh
# 下载完后再安装
sh Anaconda3-2024.10-1-Linux-x86_64.sh执行 Enter(回车)同意继续往下安装:
1
2
3
4
5
6Welcome to Anaconda3 2024.10-1
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>直到出现询问 [yes|no] 输入 yes:
1
2
3
4Version 4.0 | Last Modified: March 31, 2024 | ANACONDA TOS
Do you accept the license terms? [yes|no]
>>> yes询问是否初始化:
1
2
3
4
5
6
7
8
9Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
创建环境并启动环境
激活 conda 环境
1
source ~/.bashrc
创建 ros2 环境
1
conda create -n ros2 python=3.8
修改 conda 配置
1
2conda config --set auto_activate_base false # 默认不进入base环境
vim ~/.bashrc在文件末尾添加
1
conda activate ros2
激活环境
1
source ~/.bashrc
安装依赖
1 | sudo apt install --reinstall -y \ |
科学上网
学校校园网 git clone 很容易出现网络问题,需要跑梯子。
1
2
3
4
5
6# 自己电脑的ip:自己梯子开的端口号,默认是7890
export http_proxy=http://192.168.1.179:7890
export https_proxy=http://192.168.1.179:7890
# 记得将自己的梯子的允许局域网打开
# 没有梯子的话可以去搞个精灵学院的 60R 还是 68R 的 400G 流量梯子, 比按月计费的好
# 400G 足够用好几年了或者启动 Clash 的 TUN 模式(虚拟网卡)
git 配置
关联 github 账号邮箱
1
2
3
4git config --global user.name "Your github username"
# "Your github Name" 中填写你的github账号用户名
git config --global user.email "yourgitemail@yourdomain.com"
# "yourgitemail@yourdomain.com" 中填写你github注册的邮箱生成密钥
1
ssh-keygen -t ed25519 -C "username@email.com"
用 cat 查看密钥
1
cat ~/.ssh/id_ed25519.pub
前往 github 官网添加密钥
Gazebo Classic 安装
添加软件源
1
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
添加密钥
1
sudo wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
安装 Gazebo
1
2sudo apt update
sudo apt install gazebo11 libgazebo11-dev -y
安装 Micro XRCE - DDS
1 | # 进入 conda 环境 |
固件下载
一定要科学上网
确保 Micro XRCE - DDS 编译完成
1 | # 进入 conda 环境 |
安装 QGC 地面站
方案一:
在 Windows 上打开 QGC 地面站直接连接
方案二(不推荐):
专门下载 linux 的 QGC 地面站
工作空间配置
创建工作空间
1
mkdir -p ~/px4/px4_ws/src
安装 px4 功能包
1
2
3cd ~/px4/px4_ws/src
git clone https://github.com/PX4/px4_msgs.git -b release/1.14
git clone https://github.com/PX4/px4_ros_com.git -b release/v1.14编译
1
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
总测试
终端一(启动 Micro XRCE - DDS):
1
MicroXRCEAgent udp4 -p 8888
终端二(启动仿真):
1
2cd ~/px4/PX4-Autopilot/
make px4_sitl gazebo-classic终端三(启动 ros2 节点):
1
2
3cd ~/px4/px4_ws/
source ./install/setup.sh
ros2 launch px4_ros_com offboard_control_launch.yaml嫌麻烦的话可以将 ros 环境直接存进.bashrc中
1
echo "source ~/px4/px4_ws//install/setup.bash" >> ~/.bashrc
如果全部正常,则可以看到无人机起飞并悬停







