PX4学习(1)——PX4固件版本开发环境(ROS+mavros版本)

参考px4官网流程:

https://dev.px4.io/en/setup/dev_env_linux_ubuntu.html

https://dev.px4.io/en/setup/building_px4.html

配置过程中网速一定要好!!!!一定要好!!!!最好翻墙!!!不然会出很多莫名其妙的bug的!!!!!

 

----------------------------------------------------------------------分割线-----------------------------------------------------------------

   如果觉得手动配置比较麻烦的,可以直接在官网下载脚本来运行,并且非常方便,会直接把ROS、mavros等也给直接装上。脚本的使用官网上说的也很清楚,本文主要写手动配置,脚本方面的去官网看一下就OK了。网址:https://dev.px4.io/en/setup/dev_env_linux_ubuntu.html

--------------------------------------------------------------------分割线--------------------------------------------------------------------

 

手动配置:

1、我是之前实现配好的ROS和mavros的,所以这一点的顺序和官网不太一样。

安装ROS-kinetic版本:http://wiki.ros.org/kinetic/Installation/Ubuntu

这里就直接贴命令了,具体解释之前的博客和ROS官网解释的都很好

 
  1. sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

  2. sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

  3. sudo apt-get update

  4. sudo apt-get install ros-kinetic-desktop-full

  5. apt-cache search ros-kinetic

  6. sudo rosdep init

  7. rosdep update

  8. echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc

  9. source ~/.bashrc

  10. sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

安装mavros:https://github.com/mavlink/mavros/blob/master/mavros/README.md#installation

(1)二进制安装,比较简单(不想麻烦的话推荐)

 
  1. sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras

  2. wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh

  3. ./install_geographiclib_datasets.sh

(2)源码编译

    安装编译工具:

sudo apt-get install python-catkin-tools python-rosinstall-generator -y

   创建存放mavros的工作空间,这里推荐放在一个新建的单独的工作空间,因为按照这个教程走下去后,该工作空间只能用catkin build指令编译而不能用catkin_make了。
 

 
  1. mkdir -p ~/mavros_ws/src

  2. cd ~/mavros_ws

  3. catkin init

  4. wstool init src

  更新保证获取到最新的稳定版mavlink和mavros:
 

 
  1. rosinstall_generator --rosdistro kinetic mavlink | tee /tmp/mavros.rosinstall

  2. rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall

   归并工作链,准备开始安装: 

 
  1. wstool merge -t src /tmp/mavros.rosinstall

  2. wstool update -t src -j12

  3. rosdep install --from-paths src --ignore-src -y

  其中第二行命令的-j多少,后面的数字最好是你cpu的线程数

  这个过程中网速一定要好,不然clone源码这一步会卡住,会一直出现mavros | mavlink active啥啥的。

 

   安装GeographicLib datasets: 

 ./src/mavros/mavros/scripts/install_geographiclib_datasets.sh

   编译源码(在工作空间下):

catkin build

 如果你想每个终端都常用的话,"source ~/mavros_ws/devel/setup.bash"`这句话添加到~/.bashrc文件中,否则就只在这个终端里source一下就行了。

 

2、解决用户权限问题和删掉linux下的那个串口管理器

官方说法:永远不要用sudo去解决这里的权限问题!否则会越来越乱

 
  1. sudo usermod -a -G dialout $USER

  2. sudo apt-get remove modemmanager

3、安装通用依赖:
所需的Python包、其他东西等等

 
  1. sudo apt-get update -y

  2. sudo apt-get install git zip cmake build-essential genromfs ninja-build -y

  3. # Required python packages

  4. sudo apt-get install python-argparse python-empy python-toml python-numpy python-dev python-pip -y

  5. sudo -H pip install --upgrade pip

  6. sudo -H pip install pandas jinja2 pyserial

  7. # optional python tools

  8. sudo -H pip install pyulog

4、安装Ninja编译工具:

sudo apt-get install ninja-build -y

5、安装FastRTPS开发环境:

 
  1. wget http://www.eprosima.com/index.php/component/ars/repository/eprosima-fast-rtps/eprosima-fast-rtps-1-5-0/eprosima_fastrtps-1-5-0-linux-tar-gz -O eprosima_fastrtps-1-5-0-linux.tar.gz

  2. tar -xzf eprosima_fastrtps-1-5-0-linux.tar.gz eProsima_FastRTPS-1.5.0-Linux/

  3. tar -xzf eprosima_fastrtps-1-5-0-linux.tar.gz requiredcomponents

  4. tar -xzf requiredcomponents/eProsima_FastCDR-1.0.7-Linux.tar.gz

  5.  
  6. cd eProsima_FastCDR-1.0.7-Linux

  7. ./configure --libdir=/usr/lib

  8. make -j12

  9. sudo make install

  10. cd ..

  11. cd eProsima_FastRTPS-1.5.0-Linux

  12. ./configure --libdir=/usr/lib

  13. make -j12

  14. sudo make install

  15. cd ..

  16. rm -rf requiredcomponents eprosima_fastrtps-1-5-0-linux.tar.gz

 make后面的j后的数字改为你cpu的线程数

6、安装jMAVSim仿真依赖:

sudo apt-get install ant openjdk-8-jdk openjdk-8-jre -y

7、配置Nuttx开发环境:

sudo apt-get install python-serial openocd flex bison libncurses5-dev autoconf texinfo  libftdi-dev libtool zlib1g-dev -y

配置arm gcc编译器:

 
  1. sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi gcc-arm-embedded

  2. sudo add-apt-repository --remove ppa:team-gcc-arm-embedded/ppa

运行下面这个脚本:(写成脚本或者你看分号一行一行在bash输命令都可以)

 
  1. pushd .

  2. cd ~

  3. wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2

  4. tar -jxf gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2

  5. exportline="export PATH=$HOME/gcc-arm-none-eabi-7-2017-q4-major/bin:\$PATH"

  6. if grep -Fxq "$exportline" ~/.profile; then echo nothing to do ; else echo $exportline >> ~/.profile; fi

  7. popd

然后重启电脑

检查是否安装成功:

arm-none-eabi-gcc --version

如果输出了像下面这样的:

arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

你成功了!

 

8、安装QGC(QGroundControl)地面站:

直接去官网下下来,直接给权限就可以运行了。

 

--------------编译源码分割线-------------

9、编译源码:

官方推荐:如果你想给px4做贡献的话,就去github把它fork下来,然后再clone到本地。这个是我的:

https://github.com/XueKH/Firmware.git

gitclone https://github.com/XueKH/Firmware.git  ~/Firmware

然后cd到Firmware下面:

第一次编译,用jMAVSim仿真器:

make posix jmavsim

过程中会再clone一些东西,不要急,等一会儿就OK了,成功后会出现一个小飞机,可以通过命令来控制它,

 
  1. commander takeoff #起飞

  2. commander land #降落

玩一下就关掉吧,下面生成可以烧在pixhawk板子上的:

在Firware文件夹下面:

make px4fmu-v4_default

过程中也会下载很多东西,等一会儿就OK

最终没有报错,输出:

-- Build files have been written to: /home/youruser/src/Firmware/build/nuttx_px4fmu-v4_default
[954/954] Creating /home/youruser/src/Firmware/build/nuttx_px4fmu-v4_default/px4fmu-v4_default.px4

就OK了!恭喜你配完了!

(过程中的报错基本全是网速的锅,一定要找个网速好的地方!或者翻墙!)

###关于build的固件版本:

    Pixhawk 4: make px4fmu-v5_default
    Pixracer: make px4fmu-v4_default
    Pixhawk 3 Pro: make px4fmu-v4pro_default
    Pixhawk Mini: make px4fmu-v3_default
    Pixhawk 2: make px4fmu-v3_default
    mRo Pixhawk: make px4fmu-v3_default (supports 2MB Flash)
    HKPilot32: make px4fmu-v2_default
    Pixfalcon: make px4fmu-v2_default
    Dropix: make px4fmu-v2_default
    MindPX/MindRacer: make mindpx-v2_default
    mRo X-2.1: make auav-x21_default
    Crazyflie 2.0: make crazyflie_default
    Intel® Aero Ready to Fly Drone: make aerofc-v1_default
    Pixhawk 1: make px4fmu-v2_default

###

 

10、烧录在板子上:

make px4fmu-v4_default upload

  成功的话会显示:

  Erase  : [====================] 100.0%
  Program: [====================] 100.0%
  Verify : [====================] 100.0%
  Rebooting.

  [100%] Built target upload

 

11、搭建Qt开发环境:

在与Firmware平级的目录下,

 
  1. mkdir Firmware-build

  2. cd Firmware-build

  3. cmake ../Firmware -G "CodeBlocks - Unix Makefiles"

然后在Qt中open a project,选择这个Firmware的CMakeLists.txt,打开就OK了,就可以看到整个工程了。

  • 5
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
以下是Ubuntu 18.04上安装ROS(Robot Operating System)Gazebo、MAVROS和PX4的教程: 1. 首先,确保你的Ubuntu 18.04系统已经更新到最新版本。打开终端并运行以下命令来更新系统: ``` sudo apt update sudo apt upgrade ``` 2. 安装必要的依赖项。在终端中运行以下命令: ``` sudo apt install build-essential cmake curl git sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool python-catkin-tools sudo rosdep init rosdep update ``` 3. 创建并初始化一个catkin工作空间。在终端中运行以下命令: ``` mkdir -p ~/catkin_ws/src cd ~/catkin_ws catkin init ``` 4. 下载PX4代码和模拟器。在终端中运行以下命令: ``` cd ~/catkin_ws/src git clone https://github.com/PX4/Firmware.git --recursive ``` 5. 安装PX4依赖项。在终端中运行以下命令: ``` cd ~/catkin_ws/src/Firmware ./Tools/setup/ubuntu.sh --no-nuttx ``` 6. 编译PX4。在终端中运行以下命令: ``` cd ~/catkin_ws catkin build px4 -j4 ``` 7. 安装Gazebo和相关插件。在终端中运行以下命令: ``` sudo apt install gazebo9 libgazebo9-dev sudo apt install ros-melodic-gazebo-ros-pkgs ros-melodic-gazebo-ros-control ``` 8. 安装Mavros。在终端中运行以下命令: ``` sudo apt install ros-melodic-mavros ros-melodic-mavros-extras ``` 9. 配置序列设备。在终端中运行以下命令: ``` wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh chmod +x install_geographiclib_datasets.sh sudo ./install_geographiclib_datasets.sh ``` 10. 测试安装是否成功。在终端中运行以下命令,启动Gazebo仿真环境和Mavros节点: ``` roslaunch px4 mavros_posix_sitl.launch ``` 希望以上教程对你有所帮助!如果有任何问题,请在评论中提问。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值