PX4与仿真入门教程-GAAS-ros控制飞行测试
PX4与仿真入门教程-GAAS-通过python控制飞行测试
说明:
- 介绍如何整合ros并通过python控制飞行测试
步骤:
- 建立相关软连接,加载项目的模型和相关配置
- 编辑文件copy_once.sh
cd ~/tools/gaas
vim copy_once.sh
- 内容如下
mkdir -p $(pwd)/Firmware/posix-configs/SITL/init/ekf2
ln -s $(pwd)/GAAS/deprecated/demo demo
ln -s ~/tools/gazebo_models ~/.gazebo/models
ln -s $(pwd)/GAAS/deprecated/simulator/launch $(pwd)/Firmware/launch/gaas
#cp -r $(pwd)/GAAS/deprecated/simulator/launch/* $(pwd)/Firmware/launch/
ln -s $(pwd)/GAAS/deprecated/simulator/models $(pwd)/Firmware/Tools/sitl_gazebo/gaas-models
#cp -r $(pwd)/GAAS/deprecated/simulator/models/* $(pwd)/Firmware/Tools/sitl_gazebo/models/
ln -s $(pwd)/GAAS/deprecated/simulator/worlds $(pwd)/Firmware/Tools/sitl_gazebo/gaas-worlds
#cp -r $(pwd)/GAAS/deprecated/simulator/worlds/* $(pwd)/Firmware/Tools/sitl_gazebo/worlds/
cp -r $(pwd)/GAAS/deprecated/simulator/posix-config/* $(pwd)/Firmware/posix-configs/SITL/init/ekf2/
- 运行脚本:
chmod +x copy_once.sh
./copy_once.sh
- 这个文件只要运行一次就可以
- 需要配置环境来加载ros环境
- 编辑文件load_old_environment.sh
cd ~/tools/gaas
vim load_old_environment.sh
- 内容如下:
export GAZEBO_MODEL_PATH=${GAZEBO_MODEL_PATH}:$(pwd)/GAAS/deprecated/simulator/models
source $(pwd)/Firmware/Tools/setup_gazebo.bash $(pwd)/Firmware $(pwd)/Firmware/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Firmware
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Firmware/Tools/sitl_gazebo
echo "SUCCEED."
- 运行脚本
chmod +x load_old_environment.sh
# . load_old_environment.sh
source load_old_environment.sh
- 使用点号source都可以
测试:
- 运行gazebo
. load_old_environment.sh
roslaunch px4 mavros_posix_sitl.launch
- 效果如下:
- 新开终端,启动脚本查看状态
rostopic echo /mavros/state
- 运行上述命令后,检查是否启动成功 查看是否
header:
seq: 1
stamp:
secs: 730
nsecs: 280000000
frame_id: ''
connected: True
armed: False
guided: False
mode: "MANUAL"
system_status: 3
- 如果出现
connected: True
,即说明成功
测试:
- 关闭之前的所有测试
- 新终端,运行gazebo
cd ~/tools/gaas/
. load_old_environment.sh
roslaunch px4 mavros_posix_sitl.launch
- 效果图:
- 新终端,启动无人机逐渐起飞到3米高并悬停
cd ~/tools/gaas/
cd demo/tutorial_1/1_px4_mavros_offboard_controller
python px4_mavros_run.py
- 效果图:
- 调整一下gazebo视图方向,X向前,容易看效果
- 注意gazebo上的X红色,Y绿色,Z蓝色
- 无人机左飞5米,逆时针旋转90度
python commander.py
- 效果图:
- 自己可以修改commaner.py里面的xy坐标,高度,方向,测试飞机如何飞行
- 返回原始位置
python home.py
- 效果图:
- 无人机走5米的正方形
- gazebo视角,拉成从上往下看,容易看到效果
python square.py
- 效果图:
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号