Hanjie's Blog

一只有理想的羊驼

Tshock1是一个第三方的terraria开服工具。在这里,我们尝试在VPS搭建Tshock服务。

SWAP

查看系统内存:

1
free -h
1
2
3
4
             total       used       free     shared    buffers     cached
Mem: 489M 441M 48M 404K 55M 159M
-/+ buffers/cache: 227M 262M
Swap: 0B 0B 0B

由于Tshock建议需要2GB的内存,但我的VPS只有489M的物理内存。幸好有人测试使用swap也可以2,于是根据指南3尝试对Swap进行设置。

注意,只有XEN、KVM架构的VPS可以设置SWAP交换分区

创建swap文件

1
dd if=/dev/zero of=/swapfile count=2048 bs=1M

bs是每块的大小,count是块的数量,bs * count,就是swap文件的大小了,这里就是1M * 2048=2G。

测试:

1
2
ls / | grep swapfile
swapfile
激活swap文件

设置权限:

1
chmod 600 /swapfile

配置:

1
mkswap /swapfile

开启:

1
swapon /swapfile

测试:

1
2
3
4
5
6
free -m

total used free shared buffers cached
Mem: 489 481 7 0 36 213
-/+ buffers/cache: 231 258
Swap: 2047 0 2047

开机启动:

1
nano /etc/fstab

文件添加:

1
/swapfile   none    swap    sw    0   0

Mono4

1
2
3
4
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu $(lsb_release -c --short) main" | sudo tee /etc/apt/sources.list.d/mono-official.list
sudo apt-get update
sudo apt-get install -y mono-complete mono-devel

Tshock

下载TShock中文版5

1
2
wget -O tshock.zip 'https://github.com/mistzzt/TShock/releases/download/cn-v3.1/tshock_cn_release.zip'
unzip tshock.zip -d ~/tshock

运行:

1
2
cd shock
MONO_THREADS_PER_CPU=50 mono TerrariaServer.exe

  1. https://tshock.readme.io/docs↩︎

  2. https://www.kickshaw.me/set-up-a-terraria-server-on-linux-with-tshock↩︎

  3. https://www.vultr.com/docs/setup-swap-file-on-linux↩︎

  4. https://www.kickshaw.me/set-up-a-terraria-server-on-linux-with-tshock↩︎

  5. https://github.com/mistzzt/TShock/releases↩︎

  • 型号:Thinkpad T460p
  • 显卡:GeForce 940MX
  • 系统:Ubuntu 16.04.4 LTS
  • 内核:4.13.0-45-generic

为SLAM系统开发配置环境,使用ZED MINI CAMERA。

Ubuntu 16.04

1
2
3
4
5
6
7
8
9
uname -r
4.13.0-36-generic

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
换源
1
2
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
sudo gedit /etc/apt/sources.list

填入:

1
2
3
4
5
6
7
8
9
10
deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse

终端:

1
2
sudo apt-get update
sudo apt-get upgrade
1
sudo apt-get install build-essential vim
安装NVIDIA驱动
1
2
3
4
5
sudo apt-get remove --purge nvidia*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C
sudo apt-get update
sudo apt-get install nvidia-396

重启电脑,终端执行:

1
2
3
ls /dev/nvidia*

/dev/nvidia0 /dev/nvidiactl /dev/nvidia-modeset /dev/nvidia-uvm
1
2
3
4
cat /proc/driver/nvidia/version

NVRM version: NVIDIA UNIX x86_64 Kernel Module 396.24 Thu Apr 26 00:10:09 PDT 2018
GCC version: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)

安装CUDA 9.1

官网下载CUDA cuda_9.1.85_387.26_linux.run。

1
2
chmod +x cuda_9.1.85_387.26_linux.run
sudo sh ./cuda_9.1.85_387.26_linux.run

只安装CUDA 9.1 Toolkit。

重启,配置环境:

1
sudo gedit ~/.bashrc

添加:

1
2
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

刷新:

1
source /etc/profile

重启:

1
2
3
4
5
6
nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
Building Samples (optional)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
cd /NVIDIA_CUDA-9.1_Samples/1_Utilities/deviceQuery
make
./deviceQuery

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce 940MX"
CUDA Driver Version / Runtime Version 9.2 / 9.1
CUDA Capability Major/Minor version number: 5.0
Total amount of global memory: 2004 MBytes (2101870592 bytes)
( 3) Multiprocessors, (128) CUDA Cores/MP: 384 CUDA Cores
GPU Max Clock rate: 1242 MHz (1.24 GHz)
Memory Clock rate: 1001 Mhz
Memory Bus Width: 64-bit
L2 Cache Size: 1048576 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 1 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Supports Cooperative Kernel Launch: No
Supports MultiDevice Co-op Kernel Launch: No
Device PCI Domain ID / Bus ID / location ID: 0 / 2 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.2, CUDA Runtime Version = 9.1, NumDevs = 1
Result = PASS

安装OpenCV 3.4.0

官网下载sources。

1
2
3
4
5
6
7
8
9
10
sudo apt-get install build-essential git cmake git yasm libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev python-dev python-numpy python-tk libtbb2 libtbb-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libdc1394-22-dev libswscale-dev libopenexr-dev libeigen2-dev libeigen3-dev libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_EXAMPLES=OFF -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_GTK_2_X=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j8
sudo make install

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

安装ROS Kinetic (optional)

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://pool.sks-keyservers.net --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

sudo apt-get update
sudo apt-get install ros-kinetic-desktop-full

sudo rosdep init
rosdep update

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

sudo apt-get install python-rosinstall

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc之后,系统的opencv版本会变成Kinetic自带的3.3版本,所以必要时不要添加此句。

安装ZED SDK

官网下载ZED_SDK_Linux_Ubuntu16_v2.4.0.run。

1
2
chmod +x ZED_SDK_Linux_Ubuntu16_v2.4.0.run
./ZED_SDK_Linux_Ubuntu16_v2.4.0.run

输入 q 退出 license agreement。

To accept the license simply press Tab key until the 'O.k.' is highlighted when installing the ttf-mscorefonts-installer

测试:

1
/usr/local/zed/tools/ZED\ Explorer

zed camera test

为了测试新的双目SLAM系统,需要带有ground truth,depth信息的dataset。但寻找后发现这类dataset不多,于是尝试搭建AirSim仿真平台,希望能自己生成一些具有深度的双目数据。

系统环境:

  • 型号:Thinkpad T460p
  • 显卡:GeForce 940MX
  • 系统:Ubuntu 16.04.4 LTS
  • 内核:4.13.0-36-generic
  • CUDA: 9.1

显卡驱动

太新或太久的驱动都不行1,我尝试过使用396,但是场景会一片白,更换为384版本:

1
2
3
4
5
sudo apt-get remove --purge nvidia*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C
sudo apt-get update
sudo apt-get install nvidia-384

Install and Build2

根据这里注册Epic Games帐号,并且关联github账号。

We use the same compiler that Unreal Engine uses, Clang 5.0, and stdlib, libc++.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
sudo apt-get install build-essential mono-mcs mono-devel mono-xbuild mono-dmcs mono-reference-assemblies-4.0 libmono-system-data-datasetextensions4.0-cil libmono-system-web-extensions4.0-cil libmono-system-management4.0-cil libmono-system-xml-linq4.0-cil cmake dos2unix clang-5.0 libfreetype6-dev libgtk-3-dev libmono-microsoft-build-tasks-v4.0-4.0-cil xdg-user-dirs

sudo ln -s /usr/bin/clang-5.0 /usr/bin/clang
sudo ln -s /usr/bin/clang++-5.0 /usr/bin/clang++

clang -v
clang version 5.0.0-3~16.04.1 (tags/RELEASE_500/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version unknown

安装UnrealEngine

1
2
3
4
5
6
# go to the folder where you clone GitHub projects
git clone -b 4.18 https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine
./Setup.sh
./GenerateProjectFiles.sh
make

安装AirSim.git

1
2
3
4
5
# go to the folder where you clone GitHub projects
git clone https://github.com/Microsoft/AirSim.git
cd AirSim
./setup.sh
./build.sh

如果遇到mono-devel : Depends: libmono-cil-dev (= 3.2.8+dfsg-4ubuntu1.1) but it is not going to be installed 错误,将源换成mirrors.163.com的就可以了。

Built-in Blocks Environment3

为了测试安装结果,运行自带的Blocks Environment作测试。

RunUnrealEngine/Engine/Binaries/Linux/UE4Editor, Click on Projects tab, Browse button and then navigate to AirSim/Unreal/Environments/Blocks/Blocks.uproject

If you get prompted for incompatible version and conversion, select In-place conversion which is usually under "More" options. If you get prompted for missing modules, make sure to select No so you don't exit.

Press the Play button in Unreal Editor and you will see something like in below(use F1 to see help on keys).

Blocks Environment

"Computer Vision" Mode4

You can use AirSim in so-called "Computer Vision" mode. In this mode, physics engine is disabled and there is no vehicle, just cameras. You can move around using keyboard (use F1 to see help on keys). You can press Record button to continuously generate images. Or you can call APIs to move cameras around and take images.

To active this mode, edit settings.json that you can find in your Documentsfolder (or ~/Documents/AirSim on Linux) and make sure following values exist at root level(更多settings.json设置参考5):

1
2
3
4
{
"SettingsVersion": 1.2,
"SimMode": "ComputerVision"
}

设置好后,按Play button,效果如下。

Computer Vision

AirSim APIs6

1
2
sudo pip install msgpack-rpc-python
sudo pip install airs

在设置好Computer Vision Mode情况下,按下Play键运行仿真,然后打开一个终端(主要不要在IDE中运行,有可能会出现termios.error: (25, 'Inappropriate ioctl for device')错误),输入:

1
2
cd AirSim/PythonClient/
python cv_mode.py

会输出:

1
2
3
4
5
6
7
8
Connected!
Client Ver:1 (Min Req: 1), Server Ver:1 (Min Req: 1)

Press any key to set camera-0 gamble to 15-degree pitch
Press any key to get camera parameters
<instance> { u'fob': 90.0,
u'pose': <instance> { u'orientation':
...

Create Your Own Unreal Environment

以Modular Neighborhood Pack7为例。New Project > C++ > Basic Code,将项目名改为Neighborhood,注意设置no Starter Content。将包含Modular Neighborhood Pack数据的文件夹放置到Neighborhood项目文件夹的Content文件夹内。

Edit > Project Settings > Maps & Modes > Editor Startup Map设置为Demp_Map8

关掉,重启项目,等待场景打开后,Blueprints > Open level Blueprint,右击MatineeActor  Event BeginPlay,选择Break Link(s),然后关掉窗口。

If the environment comes with MatineeActor, delete it to avoid any startup demo sequences. There might be other ways to remove it as well, for example, click on Blueprints button, then Level Blueprint and then look at Begin Play event in Event Graph. You might want to disconnect any connections that may be starting "matinee"9.

Own Unreal Environment

From the File menu select New C++ class, leave default None on the type of class, click Next, leave default name MyClass, and click Create Class.

1
rsync -a --delete AirSim/Unreal/Plugins path/to/Project

Save Current,关闭软件。使用文本编辑器打开项目文件Neighborhood.uproject,编辑为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"FileVersion": 3,
"EngineAssociation": "4.18",
"Category": "Samples",
"Description": "",
"Modules": [
{
"Name": "LandscapeMountains",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"AirSim"
]
}
],
"TargetPlatforms": [
"MacNoEditor",
"WindowsNoEditor"
],
"Plugins": [
{
"Name": "AirSim",
"Enabled": true
}
]
}

重新运行Neighborhood.uproject,在World Settings > Game Mode中选择AirSimGameMode

gamemode

在Multi rotor模式下10,按play键运行场景,然后打开一个终端,输入:

1
2
cd AirSim/PythonClient/
python hello_drone.py

会输出:

1
2
3
4
5
6
7
Connected!
Client Ver:1 (Min Req: 1), Server Ver:1 (Min Req: 1)

state: <instance> { u'collision': <instance> { u'has_collided': False,
u'impact_point': <instance> { u'x_val': 0.0,

...
hello_drone

运行结束后,在\tmp\airsim_drone文件夹中,会有一些输出数据。

dronw_test_0
dronw_test_2
dronw_test_3.greene

  1. https://blog.csdn.net/CSDNhuaong/article/details/79147365↩︎

  2. https://github.com/Microsoft/AirSim/blob/master/docs/build_linux.md↩︎

  3. https://github.com/Microsoft/AirSim/blob/master/docs/unreal_blocks.md↩︎

  4. https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode-1↩︎

  5. https://github.com/Microsoft/AirSim/blob/master/docs/settings.md#simmode↩︎

  6. https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode-1↩︎

  7. https://www.unrealengine.com/marketplace/modular-neighborhood-pack↩︎

  8. https://github.com/1508189250/AirSim/blob/master/docs/build.md↩︎

  9. https://github.com/1508189250/AirSim/blob/master/docs/build.md↩︎

  10. https://github.com/Microsoft/AirSim/blob/master/docs/settings.md#simmode↩︎

0%