主要参考ubuntu mate 18.04官网下载,烧录及安装 SSH VNC ROS MAVROS librealsense realsense-ros vision_to_mavros
略过在树莓派上安装Ubuntu mate18.04这一过程。
一、Ubuntu系统调整
1.换源
打开文件
sudo pluma /etc/apt/sources.list
将源修改为
http://mirrors.ustc.edu.cn/ubuntu-ports/
2.扩大交换空间
查看swap空间大小的命令
free -m
创建交换空间并激活
mkdir /swap cd /swap sudo dd if=/dev/zero of=swapfile bs=1024 count=2000000 sudo mkswap swapfile sudo swapon swapfile
一直保持这个swap空间
sudo pluma /etc/fstab
在最后一行加入
/swap/swapfile /swap swap defaults 0 0
3.ssh服务
启动ssh服务
sudo raspi-config
查看IP地址的命令
ifconfig
putty连接时遇到remote side unexpected closed network-connection问题
输入sudo /etc/init.d/ssh status查看是否缺少key文件
如果缺少,则
sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key sudo ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
4.VNC服务
参考文章树莓派ubuntu18.04 mate 安装VNC
安装VNC server
sudo apt-get -y install vnc4server
启动vncserver,生成一个~/.vnc/xstartup文件
打开~/.vnc/xstartup文件后在末尾添加:
unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS mate-session & mate-panel &
重启vnc服务,我直接reboot
配置vnc树莓派开机自启动部分参考给出的链接
二、安装ROS
sudo pip install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple pip pip --default-timeout=600 install django
#!/bin/bash # Ubuntu Config echo "Remove modemmanager" sudo apt-get remove modemmanager -y echo "Add user to dialout group for serial port access (reboot required)" sudo usermod -a -G dialout $USER # Common dependencies echo "Installing common dependencies" sudo apt-get update -y sudo apt-get install git zip 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 sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 sudo apt-get update sudo apt install ros-melodic-desktop -y sudo pip install rosdepc ## Initialize rosdep sudo rosdec init rosdepc update ## Setup environment variables rossource="source /opt/ros/melodic/setup.bash" if grep -Fxq "$rossource" ~/.bashrc; then echo ROS setup.bash already in .bashrc; else echo "$rossource" >> ~/.bashrc; fi eval $rossource ## Install rosinstall and other dependencies sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential -y ## Install dependencies sudo apt-get install python-catkin-tools python-rosinstall-generator -y ## Create catkin workspace mkdir -p ~/catkin_ws/src cd ~/catkin_ws ## Build! catkin build ## Re-source environment to reflect new packages/build environment catkin_ws_source="source ~/catkin_ws/devel/setup.bash" if grep -Fxq "$catkin_ws_source" ~/.bashrc; then echo ROS catkin_ws setup.bash already in .bashrc; else echo "$catkin_ws_source" >> ~/.bashrc; fi eval $catkin_ws_source
三、二进制安装MAVROS
由于树莓派build MAVROS功能包时卡死,干脆直接二进制安装
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 sudo bash install_geographiclib_datasets.sh
四、OFFBOARD
1.创建offb功能包
cd ~/catkin_ws/src/ catkin_create_pkg offb roscpp mavros geometry_msgs cd ~/catkin_ws/src/offb/src/ pluma offb_node.cpp
修改Cmakelists文件后
catkin build
2.运行
找到串口
ls -l /dev/ttyACM*
或者
ls -l /dev/ttyUSB*
启动mavros节点
仿真:
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"
实际:
roslaunch mavros px4.launch fcu_url:=serial:///dev/ttyACM0=921600
具体要看哪个串口
打印/mavros/state话题
rostopic echo /mavros/state



