树莓派4B+Raspbian-buster系统+安装ROS环境 版本melodic+串口配置

安装xrdp (使用电脑远程连接树莓派,进行可视化操作

sudo apt-get install xrdp
sudo apt-get install vim

更改树莓派源

sudo vim /etc/apt/sources.list

加入

deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib
non-free rpi

安装ROS环境

Step 1: Install Dependecies and Download the Packages

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-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake

Then initialize rosdep and update it

sudo rosdep init
rosdep update

如果出现问题:ERROR: cannot download default sources list from:https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list Website may be down.
解决方法sudo vim /etc/hosts增加:

151.101.76.133    raw.githubusercontent.com

重新开启终端尝试
原文链接https://blog.csdn.net/u010539624/article/details/106785549

When that’s done let’s create a dedicated catkin workspace for building ROS and move to that directory.

mkdir ~/ros_catkin_wscd ~/ros_catkin_ws

Desktop Install: includes GUI tools, such as rqt, rviz, and robot-generic libraries.

rosinstall_generator desktop --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall
wstool init -j8 src melodic-desktop-wet.rosinstall

The command will take a few minutes to download all of the core ROS packages into the src folder. If wstool init fails or is interrupted, you can resume the download by running:

wstool update -j 4 -t src

Step 2: Fix the Issues
Let’s install the compatible version of Assimp (Open Asset Import Library) to fix collada_urdf dependency problem.

mkdir -p ~/ros_catkin_ws/external_srccd ~/ros_catkin_ws/external_src
wget http://sourceforge.net/projects/assimp/files/assimp-3.1/assimp-3.1.1_no_test_models.zip/download -O assimp-3.1.1_no_test_models.zip
unzip assimp-3.1.1_no_test_models.zip
cd assimp-3.1.1
cmake .
make
sudo make install

Let’s also install OGRE for rviz

sudo apt-get install libogre-1.9-dev

Next we use the rosdep tool for installing all the rest of the dependencies:

rosdep install --from-paths src --ignore-src --rosdistro melodic -y

Step 3: Build and Source the Installation
Once it has completed downloading the packages and resolving the dependencies you are ready to build the catkin packages.

sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j2

Now ROS Melodic should be installed on your Raspberry Pi 4. We’ll source the new installation with following command:

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

Try launching roscore to check if everything was successful.

roscore

Step 4:ROS Driver Compile

sudo apt-get install libudev-dev
sudo apt remove gccsudo apt install -y g++-5 gcc-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gccsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

Before doing the following, make sure that the Kinetic version ROS environment and wiringPi are installed correctly. wiringPi updated to 2.52 for the Raspberry Pi 4B.

cd /tmp
 wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb

Check with

gpio -v

Step 5:启用串口ttyS0

sudo raspi-config

打开系统配置界面
选择Inerfacing Options
然后选择 serial
然后选择Yes

最后选择保存,退出即可。
reboot重启树莓派

查看串口映射关系

ls -l /dev

serial0是GPIO引脚对应的串口,serial1是蓝牙对应的串口。

因此代码中写 /dev/ttyS0

你可能感兴趣的:(ROS)