PX4的软件在环仿真

一、Linux/ROS Nodes单机仿真
1.安装ROS-Kinetic(参考http://wiki.ros.org/kinetic/Installation/Ubuntu
1.1 添加软件源
sudo sh -c ‘echo “deb http://packages.ros.org/ros/ubuntu (lsbreleasesc)main>/etc/apt/sources.list.d/roslatest.list1.2sudoaptkeyadvkeyserverhkp://ha.pool.skskeyservers.net:80recvkey421C365BD9FF1F717815A3895523BAEEB01FA1161.3sudoaptgetupdate1.4ROSKineticsudoaptgetinstallroskineticdesktopfull1.5rosdepsudorosdepinitrosdepupdate1.6echosource/opt/ros/kinetic/setup.bash>> /.bashrcsource /.bashrc1.7ROSmkdirp /catkinws/srccd /catkinws/catkinmake1.8sourcedevel/setup.bashecho ( l s b r e l e a s e − s c ) m a i n ” > / e t c / a p t / s o u r c e s . l i s t . d / r o s − l a t e s t . l i s t ′ 1.2 安 装 密 钥 s u d o a p t − k e y a d v – k e y s e r v e r h k p : / / h a . p o o l . s k s − k e y s e r v e r s . n e t : 80 – r e c v − k e y 421 C 365 B D 9 F F 1 F 717815 A 3895523 B A E E B 01 F A 116 1.3 更 新 软 件 源 s u d o a p t − g e t u p d a t e 1.4 安 装 R O S − K i n e t i c s u d o a p t − g e t i n s t a l l r o s − k i n e t i c − d e s k t o p − f u l l 1.5 初 始 化 r o s d e p s u d o r o s d e p i n i t r o s d e p u p d a t e 1.6 环 境 变 量 设 置 e c h o “ s o u r c e / o p t / r o s / k i n e t i c / s e t u p . b a s h ” >>   / . b a s h r c s o u r c e   / . b a s h r c 1.7 创 建 R O S 工 作 空 间 m k d i r − p   / c a t k i n w s / s r c c d   / c a t k i n w s / c a t k i n m a k e 1.8 检 查 是 否 安 装 成 功 s o u r c e d e v e l / s e t u p . b a s h e c h o ROS_PACKAGE_PATH
若结果是:/home/catkin_ws/src:/opt/ros/kinetic/share:/opt/ros/kinetic/stacks 则表明一切正常,可以继续

2.安装MAVROS(参考https://dev.px4.io/en/ros/mavros_installation.html
2.1安装mavros
sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
./install_geographiclib_datasets.sh
2.2下载mavros源码
cd ~/catkin_ws/src
git clone https://github.com/mavlink/mavros.git
2.3编译mavros
cd ~/catkin_ws
catkin_make

3.安装Gazebo(参考https://dev.px4.io/en/setup/dev_env_linux.html#jmavsimgazebo-simulation
3.1安装Gazebo和jMAVSim仿真器
下载ubuntu_sim.sh(https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim.sh
source ubuntu_sim.sh
3.2安装Gazebo在ROS上的开发工具链
下载ubuntu_sim_ros_gazebo.sh(https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_ros_gazebo.sh
source ubuntu_sim_ros_gazebo.sh

4.编写外部控制程序
4.1 建立一个外部控制程序包
这个程序包依赖于roscpp 、mavros以及geometry_msgs。可以理解为一个ROS的一个节点
pip install catkin_create_pkg #不一定需要
cd ~/catkin_ws/src/
catkin_create_pkg offb roscpp mavros geometry_msgs
4.2 外部控制程序
cd ~/catkin_ws/src/offb/src/
gedit offb_node.cpp
将官网的示例程序https://dev.px4.io/en/ros/mavros_offboard.html复制粘贴进来或者编写自己的控制程序
4.3 修改Cmakelists
cd ~/catkin_ws/src/offb/
gedit CMakeLists.txt
修改后##build##部分如下所示

#####

Build ##

#####

Specify additional locations of header files

Your package locations should be listed before other locations include_directories(

include ${catkin_INCLUDE_DIRS}

)

Declare a C++ library

add_library(${PROJECT_NAME}

src/${PROJECT_NAME}/offb.cpp

)

Add cmake target dependencies of the library

as an example, code may need to be generated before libraries

either from message generation or dynamic reconfigure

add_dependencies( PROJECTNAME P R O J E C T N A M E {{PROJECT_NAME}_EXPORTED_TARGETS} {PROJECT_NAME}_EXPORTED_TARGETS} {catkin_EXPORTED_TARGETS})

Declare a C++ executable

With catkin_make all packages are built within a single CMake context

add_executable(offb_node src/offb_node.cpp)

Rename C++ executable without prefix

target back to the shorter version for ease of user use

e.g. “rosrun someones_pkg node” instead of “rosrun someones_pkg someones_pkg_node”

set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX “”)

Add cmake target dependencies of the executable

same as for the library above

add_dependencies( PROJECTNAMEnode P R O J E C T N A M E n o d e {{PROJECT_NAME}_EXPORTED_TARGETS} {PROJECT_NAME}_EXPORTED_TARGETS} {catkin_EXPORTED_TARGETS})

${catkin_LIBRARIES}

5.仿真测试
5.1 编译
cd ~/catkin_ws
catkin_make
5.2 开始仿真
打开终端1,启动gazebo仿真:
cd ~/src/Firmware
make posix_sitl_default gazebo
打开终端2,运行mavros
roslaunch mavros px4.launch fcu_url:=”udp://:14540@127.0.0.1:14557”
打开终端3,启用外部控制程序
source ~/catkin_ws/devel/setup.bash
rosrun offb offb_node

二、多机仿真(参考http://wiki.ros.org/hector_quadrotor
1.安装
mkdir -p hector_quadrotor_tutorial/src cd hector_quadrotor_tutorial wstool init src https://raw.github.com/tu-darmstadt-ros-pkg/hector_quadrotor/kinetic-devel/tutorials.rosinstall

2.编译
cd hector_quadrotor_tutorial
catkin_make

3.编写多机模型(四架)
cd ~/hector_quadrotor_tutorial/src/hector_quadrotor/hector_quadrotor_gazebo/launch/
gedit spawn_four_quadrotor.launch
编写模型代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值