logo资料库

最详细的Ubuntu18配置px4_ros_gazebo仿真.pdf

第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
资料共5页,全文预览结束
最详细的Ubuntu18配置配置px4_ros_gazebo仿真仿真 最详细的 本教程将在Ubuntu18安装ros, px4工具链, 以及gazebo仿真环境 参考此教程可以在Ubuntu16的环境安装ros, px4工具链, 以及gazebo仿真环境 首先,我们来看下Ubuntu各版本对应的gazebo关系,在Ubuntu18中已经安装gazebo9.0 各版本的对应关系如下:请注意ubuntu18对应melodic,ubuntu16对应kinetic Ubuntu 14.04 Trusty Tahr – ROS Indigo Igloo – Gazebo 2.X 2014-2019 Ubuntu 16.04 Xenial Xerus – ROS Kinetic Kame – Gazebo 7.X 2016-2021 Ubuntu 18.04 Bionic Beaver – ROS Melodic Morenia – Gazebo 9.X 2018-2023 ** 1.安装安装px4_toolchain 首先我们来看下px4官网给出的安装说明,px4官网px4官网参考链接 1.px4提供的安装脚本,可以看到melodic版本需要ubuntu_sim_common_deps.sh + ROS/Gazebo and MAVROS ubuntu_sim_common_deps.sh脚本, 该脚本不会安装gazebo,不然会将ros-melodic中安装的gazebo9覆盖,ubuntu 16版本同样可使用该脚本 step1: 考虑到可能已经安装过ros, 这里我们选择使用 新建脚本一个空的文件ubuntu_sim_common_deps.sh,我直接在vscode中写入保存为.sh文件,可直接复制粘贴,无需改动,只安装px4工具链,代码如下: #!/bin/bash ## Bash script for setting up a PX4 development environment on Ubuntu LTS (16.04). ## It can be used for installing simulators (only) or for installing the preconditions for Snapdragon Flight or Raspberry Pi. ## ## Installs: ## - Common dependencies and tools for all targets (including: Ninja build system, Qt Creator, pyulog) ## - FastRTPS and FastCDR ## - jMAVSim simulator dependencies ## - PX4/Firmware source (to ~/src/Firmware/) # Preventing sudo timeout https://serverfault.com/a/833888 trap "exit" INT TERM; trap "kill 0" EXIT; sudo -v || exit $?; sleep 1; while true; do sleep 60; sudo -nv; done 2>/dev/null & # Ubuntu Config echo "We must first remove modemmanager" sudo apt-get remove modemmanager -y # Common dependencies echo "Installing common dependencies" sudo apt-get update -y sudo apt-get install git zip qtcreator cmake build-essential genromfs ninja-build exiftool astyle -y # make sure xxd is installed, dedicated xxd package since Ubuntu 18.04 but was squashed into vim-common before which xxd || sudo apt install xxd -y || sudo apt-get install vim-common --no-install-recommends -y # Required python packages sudo apt-get install python-argparse python-empy python-toml python-numpy python-dev python-pip -y sudo -H pip install --upgrade pip sudo -H pip install pandas jinja2 pyserial pyyaml # optional python tools sudo -H pip install pyulog # Install FastRTPS 1.7.1 and FastCDR-1.0.8 fastrtps_dir=$HOME/eProsima_FastRTPS-1.7.1-Linux echo "Installing FastRTPS to: $fastrtps_dir" if [ -d "$fastrtps_dir" ] then echo " FastRTPS already installed." else pushd . cd ~ wget https://www.eprosima.com/index.php/component/ars/repository/eprosima-fast-rtps/eprosima-fast-rtps-1-7-1/eprosima_fastrtps-1-7-1-linux-tar-gz -O eprosima_fastrtps-1-7-1- linux.tar.gz
tar -xzf eprosima_fastrtps-1-7-1-linux.tar.gz eProsima_FastRTPS-1.7.1-Linux/ tar -xzf eprosima_fastrtps-1-7-1-linux.tar.gz requiredcomponents tar -xzf requiredcomponents/eProsima_FastCDR-1.0.8-Linux.tar.gz cpucores=$(( $(lscpu | grep Core.*per.*socket | awk -F: '{print $2}') * $(lscpu | grep Socket\(s\) | awk -F: '{print $2}') )) (cd eProsima_FastCDR-1.0.8-Linux && ./configure --libdir=/usr/lib && make -j$cpucores && sudo make install) (cd eProsima_FastRTPS-1.7.1-Linux && ./configure --libdir=/usr/lib && make -j$cpucores && sudo make install) rm -rf requiredcomponents eprosima_fastrtps-1-7-1-linux.tar.gz popd fi # jMAVSim simulator dependencies echo "Installing jMAVSim simulator dependencies" sudo apt-get install ant openjdk-8-jdk openjdk-8-jre -y 为脚本添加权限: sudo chmod +x ubuntu_sim_common_deps.sh step2: 打开一个新的terminal,执行: sudo usermod -a -G dialout $USER 执行完之后重启一下 step3: 重启一下, 官方说的是Logout and login again 使得操作生效 在刚刚建立ubuntu_sim_common_deps.sh的目录下,执行 source ubuntu_sim_common_deps.sh 等待安装… terminal中出现done 表示安装完成 22.编译编译px4_Firmware 由于git clone速度非常慢,这步是最折腾人的,博主将网上所有提供的提高git速度都尝试了一遍,包括添加域名,使用码云等,域名这个应该是最主流的方法,但是博主尝试之后效 果还是不太好,不过仍然将方法贴出来 方法方法1.添加域名映射 添加域名映射 nslookup github.global.ssl.fastly.net nslookup github.com 在终端中再执行 sudo vim /etc/hosts 将上面的域名添加上,效果如下,大家根据自己的域名添加,完成之后如下图 各自网络不同,域名Adress不同,大家自己添加 码云,不是马云,类似于github,只是将他github上的转到了国内的,下载速度会大大提高,这个方法亲测可提高下载速度,但是仍然不适合firmware的下载,它是包括分支跳转的 此方法可能不太有效,博主只是将该方法贴上,另一个码云,对,你没听错,就是 1.编译编译px4 /Firmware 选择一个版本安装,两种版本没有大区别 这里安装1.8.2版本版本 这里安装 mkdir PX4 cd PX4 git clone https://github.com/PX4/Firmware.git cd Firmware git checkout v1.8.2 git submodule update --init --recursive 这里安装1.9.2版本版本 这里安装 mkdir PX4 cd PX4 git clone https://github.com/PX4/Firmware.git cd Firmware git checkout v1.9.2
git submodule update --init --recursive 此时请一定耐心等待,正常需要4到5个小时,git clone速度大概是10~30kib左右,而你要下载的有500M左右,所以请务必要有耐心,博主是用了三天来搞定的,没办法(在家只能用 4G热点下载的,但好像用) 下面贴出博主遇到的问题: Firmware的仓库下载了,但是分支没有下载好,当你打开子模组的路径可以看到文件夹为空,中间出现过早的文件结束符都是网速太低导致的,所以一定要多试几次 git submodule update –init –recursive,他会将所缺的分支子模组补上 当所有子模块均安装后,执行git submodule update –init –recursive不会有响 应 再执行 make px4_sitl_default 33.安装安装ros(如果安装过 如果安装过ros请忽略请忽略) 教程请参考:ROS安装教程 44.mavros and mavlink 安装安装 这里使用二进制安装: 在terminal中执行 如果是Ubuntu16的执行下面代码: sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras 如果是Ubuntu18的执行下面代码: sudo apt-get install ros-melodic-mavros ros-melodic-mavros-extras 安装完成后,依次执行 wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh chmod +x install_geographiclib_datasets.sh ./install_geographiclib_datasets.sh 完毕之后执行:
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557" 如果出现如下错误 [FATAL] [1455208235.573568497]: UAS: GeographicLib exception: File not readable /usr/share/GeographicLib/geoids/egm96-5.pgm | Run install_geographiclib_dataset.sh script in order to install Geoid Model dataset! ================================================================================REQUIRED process [mavros-2] has died! process has died [pid 2396, exit code -6, cmd /home/ubuntu/catkin_ws_wyz/devel/lib/mavros/mavros_node __name:=mavros __log:=/home/ubuntu/.ros/log/c5fc1ef8-d0dc-11e5-89a3-00044b65bbf5/mavros-2.log]. log file: /home/ubuntu/.ros/log/c5fc1ef8-d0dc-11e5-89a3-00044b65bbf5/mavros-2*.log Initiating shutdown! ================================================================================ [mavros-2] killing on exit [rosout-1] killing on exit [master] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done 解决方法是: sudo /opt/ros/kinetic/lib/mavros/install_geographiclib_datasets.sh 此时仍需耐心等待,大概一个多小时才能下载完成 如果出现 Gazebo [Err] [REST.cc:205] Error in REST request 执行 # 使用文本编辑器编辑以下文件 $ sudo gedit ~/.ignition/fuel/config.yaml # url: https://api.ignitionfuel.org # 注释掉此行 url: https://api.ignitionrobotics.org # 新增此行 如果不报错,证明ok了 5. 使用使用ros装饰器启动 装饰器启动gazebo(Launching Gazebo with ROS Wrappers) 如果想要修改Gazebo仿真,使其能够将额外的传感器信息直接发布到ROS主题,例如Gazebo ROS激光传感器信息,那么必须通过适当的ROS包装器来启动Gazebo 配置环境变量 配置环境变量 sudo vim ~/.bashrc export FIRMWARE_DIR={path_to_Firmware} #path_to_Firmware是你的firmware路径,如/home/zhanqx/PX4/Firmware source $FIRMWARE_DIR/Tools/setup_gazebo.bash $FIRMWARE_DIR $FIRMWARE_DIR/build/posix_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$FIRMWARE_DIR export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$FIRMWARE_DIR/Tools/sitl_gazebo 在地图添加如上代码,path_to_Firmware是你的firmware路径,如/home/zhanqx/PX4/Firmware,请参照自己的路径添加 如下图是我的 打开新的终端,执行 roslaunch px4 mavros_posix_sitl.launch 打开的gazebo场景中会出现一架uav,至此大功告成。 如图所示:
参考链接: https://dev.px4.io/v1.9.0/en/setup/dev_env_linux_ubuntu.html https://zhuanlan.zhihu.com/p/91420855 https://github.com/PX4/Firmware 作者:weixin_43568893
分享到:
收藏