/etc/apt/sources.list.d/ros-latest_ros px4 mavros安装">
赞
踩
只能说怀着沉重的心情,本来不想写的,但是又还是害怕后续出什么幺蛾子,就记录一下,希望自己永远没有机会在看这篇文章。
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
4.1
sudo apt update
4.2(这里有多个版本,可以自己去查,一般安装下面这个最完整)
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init
这里需要注意的是:第二条命令容易出错。
根据我多次的经验,先多试几次第二条命令,多试几次就会好。如何不行,就去查查吧,记得好像可以手动添加这步下载的文件。
当第二条通过后,先修改以下文件:
①
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list
运行上述命令,打开一个文件,替换内容如下:
# os-specific listings first rosdep update
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/base.yaml
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/python.yaml
yaml https://gitee.com/wybros/rosdistro/raw/master/rosdep/ruby.yaml
gbpdistro https://gitee.com/wybros/rosdistro/raw/master/releases/fuerte.yaml fuerte
②
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py
替换 FUERTE_GBPDISTRO_URL 如下:
FUERTE_GBPDISTRO_URL = 'https://gitee.com/wybros/rosdistro/raw/' \
'master/releases/fuerte.yaml'
③
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit rep3.py
替换 REP3_TARGETS_URL 如下:
REP3_TARGETS_URL = 'https://gitee.com/wybros/rosdistro/raw/master/releases/targets.yaml'
④
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit sources_list.py
替换 DEFAULT_SOURCES_LIST_URL 如下:
DEFAULT_SOURCES_LIST_URL = 'https://gitee.com/wybros/rosdistro/raw/master/rosdep/sources.list.d/20-default.list'
⑤
cd /usr/lib/python2.7/dist-packages/rosdistro/
sudo gedit __init__.py
替换 DEFAULT_INDEX_URL 如下:
DEFAULT_INDEX_URL = 'https://gitee.com/wybros/rosdistro/raw/master/index-v4.yaml'
最后执行:
rosdep update
注意:上述所有命令一定要保证全部成功,不然可能会在后期出一些问题。
//打开一个终端:
roscore
//打开第二个终端(上面终端别关)
rosrun turtlesim turtlesim_node
//打开第三个终端
rosrun turtlesim turtle_teleop_key
如下图就算成功了。
主要有两种安装方式,但是我要和PX4结合起来用。就源码安装(安装包就不在我们自己建的工作空间)
sudo apt install ros-melodic-mavros ros-melodic-mavros-extras
roscd mavros
sudo wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh
注意:一定要有耐心,出错,就多试几次。直到成功。
git clone https://gitee.com/robin_shaun/PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1
bash ./Tools/setup/ubuntu.sh //--no-nuttx --no-sim-tools
替换PX4_Firware目录下的 .gitmodules 如下:
[submodule "mavlink/include/mavlink/v2.0"]
path = mavlink/include/mavlink/v2.0
url = https://gitee.com/robin_shaun/c_library_v2.git
branch = master
[submodule "src/drivers/uavcan/libuavcan"]
path = src/drivers/uavcan/libuavcan
url = https://gitee.com/robin_shaun/uavcan.git
branch = px4
[submodule "Tools/jMAVSim"]
path = Tools/jMAVSim
url = https://gitee.com/robin_shaun/jMAVSim.git
branch = master
[submodule "Tools/sitl_gazebo"]
path = Tools/sitl_gazebo
url = https://gitee.com/robin_shaun/sitl_gazebo.git
branch = master
[submodule "src/lib/matrix"]
path = src/lib/matrix
url = https://gitee.com/robin_shaun/Matrix.git
branch = master
[submodule "src/lib/ecl"]
path = src/lib/ecl
url = https://gitee.com/robin_shaun/ecl.git
branch = master
[submodule "boards/atlflight/cmake_hexagon"]
path = boards/atlflight/cmake_hexagon
url = https://gitee.com/robin_shaun/cmake_hexagon.git
branch = px4
[submodule "src/drivers/gps/devices"]
path = src/drivers/gps/devices
url = https://gitee.com/robin_shaun/GpsDrivers.git
branch = master
[submodule "src/modules/micrortps_bridge/micro-CDR"]
path = src/modules/micrortps_bridge/micro-CDR
url = https://gitee.com/robin_shaun/micro-CDR.git
branch = px4
[submodule "platforms/nuttx/NuttX/nuttx"]
path = platforms/nuttx/NuttX/nuttx
url = https://gitee.com/robin_shaun/NuttX.git
branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/nuttx/NuttX/apps"]
path = platforms/nuttx/NuttX/apps
url = https://gitee.com/robin_shaun/NuttX-apps.git
branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/qurt/dspal"]
path = platforms/qurt/dspal
url = https://gitee.com/robin_shaun/dspal.git
[submodule "Tools/flightgear_bridge"]
path = Tools/flightgear_bridge
url = https://gitee.com/robin_shaun/PX4-FlightGear-Bridge.git
branch = master
[submodule "Tools/jsbsim_bridge"]
path = Tools/jsbsim_bridge
url = https://gitee.com/robin_shaun/px4-jsbsim-bridge.git
[submodule "src/examples/gyro_fft/CMSIS_5"]
path = src/examples/gyro_fft/CMSIS_5
url = https://gitee.com/mirrors/CMSIS_5
执行如下操作:
git submodule update --init --recursive
注意:这个命令可能也会出错,也是多试几次,网上有需要修改子目录文件的方法或者自己下载相应的文件夹,但是,虽然那样操作,这个命令可以通过,但是,到最后就一直有问题。经过我数十次的安装,就一直在这里执行,直到成功(可能晚上成功率高?)。
编译:
make px4_sitl_default gazebo
//or
make px4_fmu-v5_default gazebo
//上面的v5可以是其他,看自己固件版本,如果只是仿真,就第一句吧。
关于gazebo的错误,可以去查一下,若报参数无效,就在.bashrc文件最后添加
export SVGA_VGPU10=0
打开主目录下的 .bashrc文件,在最后添加如下语句:
source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware/Tools/sitl_gazebo
运行下面launch文件:
roslaunch px4 mavros_posix_sitl.launch
如果顺利打开,先别急高兴,看一看有没有红色error,有的话,就麻烦了。
如果没有,在终端内,按回车
,出现pxh
> 输入 commander takeoff
观察gazebo的飞机会不会起飞。
再打开一个终端,
rostopic list
//正常应该有好多话题
rostopic echo /mavros/state
//这句执行完,出现如下,就算成功了
到这就算结束了。为什么会写这个网上都有的教程呢,主要还是某一天早上发现我的px4突然打开就报错了,就各种操作都不好,一直断断续续从早上10点吧,到第二天早上3点多才好,期间按照各种教程安装了可能数十次吧,就一模一样的操作,但是就是最后有问题,要么make编译不能通过,要么就是最后的launch文件运行,报各种错误。最后重新安装了一个ubuntu18.04,重新一步一步安装了ros,mavros,px4才好,但是也还是心情沉重吧,毕竟我不知道它原来是为什么会出问题的,就还是害怕后续会突然坏了。希望好运。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。