Raspberry pie 4B (4G/8G) with Ubuntu 18.04 desktop + ROS(Melodic)+Realsense SDK (T265+D400 series)

Raspberry pie 4B (4G/8G) with Ubuntu 18.04 desktop + ROS(Melodic)+Realsense SDK (T265+D400 series)


Nothing to say, just record your own track here, only to ensure that the following content has been practiced by yourself. There are not too many principles in the following content. It is estimated that I am walking around with a lot of articles read by other bloggers, and I will not introduce them either.

win computer software, can transfer files with each other in the same LAN through IP address, raspberry-derived user name, password.
Attached disc link:https://pan.baidu.com/s/1Kw09GvhxD7o871dY0FA-0w
Extraction Code: 0000

win computer software, can login to the Raspberry Pie desktop remotely within the same LAN through IP address, Raspberry Pie user name, password.
Attached disc link:https://pan.baidu.com/s/18_tvVH8Q-FTJOjQIGBZdyg
Extraction Code: 0000

LAN IP Scanner
win computer software, sweeps all IP addresses in LAN
Attached disc link:https://pan.baidu.com/s/1hxQVjk5dq_X45CSroEVFoQ
Extraction Code: 0000

1. Download and install the raspberry pie 4B image (Ubuntu-mate-18.04)

1. Raspberry pie 4B server mirror

Attached my Baidu link
Extraction Code: 0000

Raspberry Pie 4B Universal Server Mirror, Post Install Desktop

2. Prepare items

2.1 flash memory card larger than or equal to 32G
2.2 raspberry pie 4B (4G/8G)

Pit Avoidance Strategy: Prefer flash memory card, or other large brands, or after a period of time, unknown can not turn on normally or other problems

3. Mirror burning

3.1 Software Download

Extraction Code: 0000
Extraction Code: 0000

3.2 Memory card needs to be formatted before use!!!

After opening the software SDFormatter to display the characters, click Formatter directly, and other parameters do not need to be modified. Make sure you select the characters you want to format. If you format other disks sideways, you will feel uncomfortable.

3.3 Open the burning software balenaEtcher to select the image you want to burn and click Flash
It will be burned in about three or four minutes, depending on your memory card reading and writing speed, no operation is required after burning, just pull out the memory card directly., the top left is green, indicating that burning is normal, if it is red, you have to format it with software and re-burn it

3.4 The memory card is inserted into the raspberry pie. The first power-on requires an external monitor, keyboard, mouse and a network cable. (If the first power-on does not display properly, disconnect the power and power it up again.)

Here are two lights next to the raspberry pie, which are suitable for partners who can't turn it on properly.
The status represented by the raspberry pie ACT LED flashing mode

4. Install desktop software

Networking is very simple. The network cable is plugged directly into the router.

4.1 Change account password after raspberry pie starts
You will be prompted to enter an account: ubuntu.
Enter password: ubuntu
Enter the current password: ubuntu,
The password you want to set (like the lowest 8 characters, just a simple point, which I will use frequently in the future, 123456789 for myself)
Confirm your password again

4.2 First check to see if you are connected to the Internet (many ways, see your hobbies)

Here's the recommended input:


Here you can see some useful information. Under wlan0 you can see your IP address, which you can use later through a ssh Remote connection.
4.3 Raspberry Pie Update Software
1) Enter the command:

sudo apt-get update && sudo apt-get dist-upgrade -y

(Command parsing: sudo apt-get update is to read the list of software and save it on the local computer;
sudo apt-get upgrade locally installed software, compared with the software just downloaded in the list of corresponding software, if found that the installed software version is too low, it will prompt you to update, generally about half an hour, will prompt you if you update, YES/NO, select y)
2) Enter after installation:

sudo reboot 

(Command resolution: After the update, you need to restart the operation, just like King pesticides, so it makes sense to reopen it after the update.)
3) Enter the command:

sudo apt-get install ubuntu-mate-desktop

(Command parsing: Install desktop environment, just one command is needed, then wait quietly for about half an hour, network speed, raspberry pie speed have a lot to do)

4) Enter after installation:

sudo reboot 

4.4 Change source (you can also follow other online tutorials) can be done or not!!
Be careful:(Change is OK, the little partner who can ride the ladder does not need operation, the little partner without ladder suggests changing source. The reason for changing source is that the server of Ubuntu is in a foreign country, you will visit very slowly and download things slowly, so you need to change the mirror source in China, such as Ali, Tsinghua, etc. There is a saying on the Internet that choosing the right source according to the geographical distribution, the little partner can find itFind resources.)

Input Command

sudo nano /etc/apt/sources.list 

Replace the contents with the mirror source you want to change

deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe

Enter Confirmation
Ctrl+x Exit

sudo apt update 
sudo apt dist-upgrade 
sudo apt clean

Most often there will be a lot of errors after changing the source, such as no key found
You can Baidu sudo apt uodate can not find the key
It's probably this

sudo apt-key adv --keyserver 'hkp://Keyserver.ubuntu.com:80'-- recv-key // followed by a key indicating you are missing, about a dozen digits, mixed with upper case English

4.5 Install raspi-config

Its purpose is to configure your raspberry pie system. Since the Ubuntu system is not installed, you need to install it manually yourself.

4.5.1 Input Command Installation Dependency:

sudo apt install whiptail parted lua5.1 alsa-utils psmisc

4.5.2 Enter command to download raspi-config


4.5.3 Installation:

sudo dpkg -i raspi-config_20200727_all.deb

4.5.4 Check for lack of dependencies

sudo apt-get -f -y install

4.5.5 Input:

sudo raspi-config 

4.5.6 Select by arrow keys: Interfacing Options Enter Confirm Selection SSH Confirm YES OK
Finally select < Finish >

4.5.7 and restart:

sudo reboot 

5. To prevent the raspberry pie from running out of memory, you need to increase the swap space.

5.1 Check existing memory

free -m

5.2 Establishing swap space

cd /opt/
sudo mkdir swap
cd swap
sudo touch swap

5.3 Set the swap memory size. Depending on the size of my own memory card, the 64G card I use has 8G swap space (my 8G swap size, 1G=1024, which is suitable for me)

sudo dd if=/dev/zero of=/opt/swap/swap bs=1024 count=8162000

It will take a long time to get back to the results. Don't think it's stuck.


sudo mkswap /opt/swap/swap    ///There will be warnings, no fear, normal phenomena

5.5 Enable swap space

sudo swapon /opt/swap/swap

5.6 Is Query Enabled Normally

free -m

Display established, write partition next

sudo nano /etc/fstab
 Join on the last line
/opt/swap/sawp    /swap     swap    defaults    0    0

Ctrl + O save, ctrl + x exit

Fuck, I'm not set up to manually open the swap space each time I restart.
sudo su 
swapon /opt/swap/swap     open
swapoff /opt/swap/swap     Close

Now the raspberry pie has been mirrored.

2. Install ROS (Melodic Binary Installation)

1 Download ROS

Official website: http://wiki.ros.org/melodic/Installation/Ubuntu

1.1 Download and install:

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

Set key:
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key 	C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

Refresh the installation list:
sudo apt update

install ROS Desktop Full Edition:
sudo apt install ros-melodic-desktop-full

install ROS Common software:
sudo apt install python-rosdep python-rosinstall 	python-rosinstall-generator python-wstool 	build-essential
sudo apt-get install ros-melodic-rqt*
sudo apt-get install rosdep

1.2ROS Initialization
ROS update is the most difficult step, because it requires connecting to foreign servers and then comparing with the ROS files you just downloaded. Are you missing files and lack of dependency, because the servers are abroad, they often can't be connected. Let's check through the command, which web addresses do you want to connect to?


sudo nano /etc/ros/rosdep/sources.list.d/20-default.list

There are five Web addresses here: raw.githubusercontent.com

Ctrl+x Exit
Then, we Baidu searched for the IP address of raw.githubusercontent.com as follows: As of the time I wrote this tutorial, the current IP address of this website was
So enter the command:

sudo nano /etc/hosts raw.githubusercontent.com     //Add a sentence at the end
 Enter Confirmation
Ctrl+x  Sign out

2 I recommend three ways to summarize

2.1 Wall Flip

Wallpaper buddies directly

sudo rosdep init 

Initialize finish as prompted

sudo rosdep update 

that will do

2.2 Find a router with high network bandwidth.

For example, school networks, big business networks, or mobile phone hotspots are all possible. This method may depend on luck, success at one time, or three or four hours or more. To sum up, it is watch! This is a theology! The best time period is after 10 p.m. to before 8:30 p.m. on the next day!!!! Try to change another person's hotspot one time, and tryAnd switch back to your hotspot, which is a little more efficient
When we run sudo rosdep init several times, we get an error as follows:
Then enter the command:

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list 

Delete this file and re-enter:

sudo rosdep init

When the initialization is finished, type sudo rosdep update as prompted. 99% of the runs will not succeed at one time. That's OK. Try a few more times and keep typing: sudo rosdep update
Try about ten times, you can see your implementation. It is mentioned above that when ROS is updated, you need to connect to five Web addresses abroad. You have a record of commands from your program. Every time you run an update, there will be several web addresses that can be connected to three or four web addresses. That way, you can go on and keep commanding updates.Until you succeed. If you can only connect one or two web addresses per update, then don't go down and try the third way.

2.3 Replace Target File

Explain how to install this method first
First download the latest ROS list file, then modify / etc/ros/rosdep/sources
So how good is that? Read the explanation and consider it yourself
Advantages: No long wait, half an hour,
Disadvantage: If you update it later, it will not compare with the official latest directory, unless you modify the file again.
I suggest: the first two methods are the best, it is really not possible to use this method again, but also to leave a way for yourself.

It is important to note that the path to your files must be written and that you carefully look at the folders of the files you download. This author has written in great detail.

2.4 Check if ROS is installed successfully, routine check

The code is as follows

                                             Open three terminals and command them separately:
roscore                                    start-up ros core
rosrun turtlrsim turtlesim_node           Run the Tortoise routine
rosrun turtlrsim turtle_teleop_key       Run the Tortoise Control Program

Then place the cursor on the last port and use the arrow keys to control the direction of the tortoise's movement. q"Exit the program

3. Binary Installation of MAVROS

1.Binary Installation MAVROS

The code is as follows

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

Add Key
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

Update Software Library
sudo apt update

install MAVROS And feature packs
sudo apt install ros-melodic-mavros ros-melodic-mavros-extras -y
sudo apt-get install python-catkin-tools python-rosinstall-generator -y
sudo apt install libpcl1 ros-melodic-octomap-*

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

2. Install the vision_to_mavros package

The code is as follows

Create a workspace
mkdir -p ~/xxx_ws/src   (xxx Plan for yourself)
cd ~/xxx_ws/src

Download Documents
git clone https://github.com/hoangthien94/vision_to_mavros.git

cd ~/xxx_ws



echo "source ~/xxx_ws/devel/setup.bash" >> ~/.bashrc

source ~/.bashrc

3. Source Installation MAVROS

Look at this section, no action required

mkdir -p ~/px4_tools/catkin_ws/src
cd ~/px4_tools/catkin_ws

## Install dependencies
sudo apt-get install python-wstool python-rosinstall-generator python-catkin-tools -y

## Initialise wstool
wstool init ~/px4_tools/catkin_ws/src

## Build MAVROS
### Get source (upstream - released)
rosinstall_generator --upstream mavros | tee /tmp/mavros.rosinstall
### Get latest released mavlink package
rosinstall_generator mavlink | tee -a /tmp/mavros.rosinstall
### Setup workspace & install deps
wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src
rosdep install --from-paths src --ignore-src --rosdistro melodic -y

## Build!
catkin build
## Re-source environment to reflect new packages/build environment
echo "source ~/px4_tools/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

4.MAVROS and Flight Control Communication

There are many methods for MAVROS to communicate with flight control. There are two kinds of records here: data line direct insertion, tty serial port

4.1 Data Line Direct Interpolation
Connect Flight Control with Raspberry Pie directly using a common data line, just like Flight Control downloads firmware
Raspberry pie query port

cd /dev
See if there is any port display, mostly yes   ttyACM0,During this period, it is not recommended to plug in other devices besides the mouse and keyboard, in order to avoid your confusion.

4.2tty to Serial Port
Prepare a USB to TTL module, ask your boss before you buy it to support 921600 bit rate, 57600 baud rate will also be used, but after a large amount of data communication, a lot of errors will occur.

cd /dev
See if there is any port display, mostly yes   ttyUSB0,During this period, it is not recommended to plug in other devices besides the mouse and keyboard, in order to avoid your confusion.

4.3 Modify launch file

roscd mavros/launch
ls You can see a lot launch file

If you use APM Firmware, just
sudo vim apm.launch

If you use PX4 Firmware, just
sudo vim px4.launch

Modify the phrase "Circle the photo". For example, I use a data line to insert directly.
In the front unchanged, change ttyUSB0 to ttyACM0 (based on the port number you find above) and change the baud rate to the same as you fly empty settings, otherwise you can not communicate, after modification is completed,:wq!Save Exit

Open a new terminal, enter

roslaunch mavros px4.launch
roslaunch mavros apm.launch

This is the communication success, the red error is to prompt me that the flight control is not adjusted correctly, the prompt content is the same as the prompt error you see in the ground station.

If you often use a direct cable connection and occasionally use a USB serial connection, you can use this command below without having to modify the file as above

roslaunch mavros px4.launch fcu_url:=/dev/ttyUSB0:921600
 Same as  apm firmware
roslaunch mavros apm.launch fcu_url:=/dev/ttyUSB0:921600

You must use your own port number

IV. Installation of Intel Realsense SDK

1. Check your own GCC version with gcc-v first, usually gcc-7, if not gcc-6 you need to install gcc-6 first

Install as follows

sudo apt-get update 
sudo apt-get install build-essential software-properties-common -y 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y  
sudo apt-get install gcc-snapshot -y 
sudo apt-get install gcc-6 g++-6 -y 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6

2. Below is the installation of the Realsense SDK (a binary installation is recommended)

2.1 Installation Dependency

sudo apt-get install git cmake libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
sudo apt install git libssl-dev libusb-1.0-0-dev pkg-config -y
sudo apt install cmake python3-dev raspberrypi-kernel-headers -y

2.2 Add Mirror Source

secret key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

image source
sudo add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" -u

2.3 Installation

sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils
sudo apt-get install librealsense2-dev
sudo apt-get install librealsense2-dbg

2.4 New Terminal Checks for Successful Installation



Plug in to switch between 2D or 3D

3.Intel Realsense SDK source installation (recommended)

The code is as follows (example):

cd ~
git clone https://github.com/IntelRealSense/librealsense.git
cd librealsense

# Install udev rules
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger

# Create the destination directory

mkdir build
cd build

# Remove extra files if this is not your first run
xarg sudo rm < install_manifest.txt
rm CMakeCache.txt
export CC=/usr/bin/gcc-6
export CXX=/usr/bin/g++-6

Copy one of the following lines \Remove
cmake -D CMAKE_BUILD_TYPE="Release"\          
-DBUILD_WITH_TM2=false \

sudo make uninstall 
make clean
sudo make install   #Executor 1 will have some errors, temporarily regardless, I do not know if there is any impact on the later use, temporarily first such, there are problems to say again
sudo ldconfig

# Finally, reboot the pi:
sudo reboot

4. Use ROS package to read T265 data

4.1 Installation Dependency

sudo apt-get install ros-melodic-ddynamic-reconfigure

4.2 Download the ROS realsense-ros package

Create a workspace
mkdir -p ~/xxx_ws/src   (xxx Plan for yourself)
cd ~/xxx_ws/src
git clone https://github.com/IntelRealSense/realsense-ros.git
cd realsense-ros/
git checkout `git tag | sort -V | grep -P "^2.\d+\.\d+" | tail -1`
cd ..
 Start test demo,You can see that T265 Posture data of

4.3 Check that the t265 data is working (using two terminals)
The code is as follows (example):

roslaunch realsense2_camera rs_t265.launch
rostopic echo /tf    (Red circle is a three-dimensional coordinate, pick up t265 Move and see if the data is accurate. The unit is  M   )

4.4 Mapping-related Dependencies
Mapping Module Dependency Installation

sudo apt-get install ros-melodic-rqt ros-melodic-rqt-common-plugins ros-melodic-rqt-robot-plugins -y

install rtabmap: 
sudo apt-get install ros-melodic-rtabmap*

install Octomap:
sudo apt-get install ros-melodic-octomap-*

install cartographer
sudo apt-get install ros-melodic-cartographer*

5. A command starts the communication between T265 and Raspberry Pie and Flight Control

These commands generally need to be run to communicate between the three modules

Open three ports separately
roslaunch realsense2_camera rs_t265.launch
roslaunch vision_to_mavros t265_tf_to_mavros.launch
sudo chmod a+rw /dev/ttyUSB0      /Before using ports, assign values
roslaunch mavros apm.launch  fcu_url:=/dev/ttyUSB0:57600

have access to
roslaunch vision_to_mavros t265_all_nodes.launch
 Starting these three commands at once saves you a lot of effort


Certainly some commands are wrong. If there are any errors, please correct them. Thank you.

Tags: Ubuntu

Posted on Thu, 14 Oct 2021 12:32:55 -0400 by roxiroxi