bash
sudo apt-get update &&
sudo apt-get install wget software-properties-common &&
sudo add-apt-repository ppa:ubuntu-toolchain-r/test &&
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add
bash
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main"
sudo apt-get update
sudo apt-get install build-essential clang-10 lld-10 g++-7 cmake ninja-build libvulkan1 python python-dev python3-dev python3-pip libpng-dev libtiff5-dev libjpeg-dev tzdata sed curl unzip autoconf libtool rsync libxml2-dev git
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-10/bin/clang++ 180 &&
sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-10/bin/clang 180
bash
pip install --user setuptools &&
pip3 install --user -Iv setuptools==47.3.1 &&
pip install --user distro &&
pip3 install --user distro &&
pip install --user wheel &&
pip3 install --user wheel auditwheel
关联github和UE4的账号:
由于 Carla 是基于 UE4 引擎进行开发的,所以在安装 Carla 前最终要的一步就是安装 UE4 ,这里在 CALAR 0.9.12 以后的版本使用的引擎是 Unreal Engine 4.26 。在安装 Carla 之前要安装好 Unreal Engine 4.26 。安装之前需要保证你的 github 账户和 Unreal Engine 账户连接。 连接方法可以参考下面链接:
https://www.unrealengine.com/en-US/ue-on-github
然后在这里我们需要点击 Follow:
如果这里没有点击,就不显示 UE4 源码仓库,无法 git clone 下载
除了两个账户之间的连接之外,还需要注意的是 git clone 过程中需要用 github 账户登入,但 github 从 2021 年开始不支持这种登入方式,需要设置个人密钥。
保存好这个秘钥,他只会显示一次,关闭网页就看不到了,需要重新去生成。
开始下载UE4:
git clone --depth 1 -b carla https://github.com/CarlaUnreal/UnrealEngine.git ~/UnrealEngine_4.26
输入自己的github账号和前面保存的秘钥:
2.添加unreal engine补丁
由于补丁较早,无法自动打补丁,需要手动修改。
绿色是需要修改的文件,红色是修改位置的前一个函数名,由于UE4的更新,行数仅能提供大概位置作为参考。+号是要添加的代码,-号是要删除的代码。+号前的代码(比如#endif })对应于UE4的位置,后面添加带+号的代码,还可以参考后面没有+号的代码,依此确定修改代码的位置。
记得把+号去除,添加完如图:
其它代码依照修改。
我这边最后一项不用修改。
cd ~/UnrealEngine_4.26
./Setup.sh
./GenerateProjectFiles.sh
make
cd ~/UnrealEngine_4.26/Engine/Binaries/Linux && ./UE4Editor
报错:
error1:/Engine/Source/Runtime/Engine/Private/CubemapUnwrapUtils.cpp,类内未定义GetVertexShader()函数、GetPixelShader()函数
使用
RHICmdList.GetBoundVertexShader() 代替 GetVertexShader()。
RHICmdList.GetBoundPixelShader() 代替GetPixelShader()。
cpp
GraphicsPSOInit.BoundShaderState.VertexShaderRHI = VertexShader.GetVertexShader()
GraphicsPSOInit.BoundShaderState.PixelShaderRHI = PixelShader.GetPixelShader()
报错:
error:marked "override' but does not override any member functions virtual bool Serialize(FArchive& Ar) override
解决:
直接删除或注释
报错:
Assertion failed: Alignedoffset == TypeLayout.size [File: /home/shao/unrealEngine_4.26/Engine/source/Runtime/core/Private/Serialization/MemoryImage.cpp] [Line: 224]
[FCubemapTexturePropertiesVsFisheye] calculated size: 280, Real size: 288
解决:
在Engine/Source/Runtime/Engine/Public/CubemapUnwrapUtils.h文件修改以下内容,添加LAYOUT_FIELD().
再次运行
make
cd ~/UnrealEngine_4.26/Engine/Binaries/Linux && ./UE4Editor
成功
Carla下载地址:
git clone https://github.com/carla-simulator/carla
首先更新
./Update.sh
设置虚幻引擎的变量位置
echo "export UE4_ROOT=~/UnrealEngine_4.26" >> ~/.bashrc
source ~/.bashrc
编译客户端PythonAPI
make PythonAPI
编译服务器
make launch
测试
cd carla-master/PythonAPI/examples
python3 maunaul_control.py
可能缺少pygame和numpy,安装即可
pip3 install pygame
pip3 install numpy
点击运行 ,然后等待.........
生成交通车辆
python3 -m pip install -r requirements.txt
python3 generate_traffic.py
这样就有车在动了。
后面就是安装ROS和carla ros bridge了。
1.carla_ros_bridge功能包下的camera.py添加魚眼相机
python
class FisheyeCamera(Camera):
"""
Camera implementation details for fisheye camera
"""
def __init__(self, uid, name, parent, relative_spawn_pose, node, carla_actor, synchronous_mode):
super(
FisheyeCamera, self).__init__(uid=uid,
name=name,
parent=parent,
relative_spawn_pose=relative_spawn_pose,
node=node,
synchronous_mode=synchronous_mode,
carla_actor=carla_actor)
self.listen()
def get_carla_image_data_array(self, carla_image):
carla_image_data_array = numpy.ndarray(shape=(carla_image.height, carla_image.width, 4),
dtype=numpy.uint8, buffer=carla_image.raw_data)
return carla_image_data_array, 'bgra8'
设置相机内参camera_info的话题,应为鱼眼相机参数不同于普通相机参数,所以需要修改才能编译通过。
python
if self.__class__.__name__ == "FisheyeCamera":
camera_info.width = int(self.carla_actor.attributes['x_size'])
camera_info.height = int(self.carla_actor.attributes['y_size'])
camera_info.distortion_model = 'plumb_bob'
cx = float(self.carla_actor.attributes['c_x'])
cy = float(self.carla_actor.attributes['c_y'])
fx = float(self.carla_actor.attributes['f_x'])
fy = float(self.carla_actor.attributes['f_y'])
else:
camera_info.width = int(self.carla_actor.attributes['image_size_x'])
camera_info.height = int(self.carla_actor.attributes['image_size_y'])
camera_info.distortion_model = 'plumb_bob'
cx = camera_info.width / 2.0
cy = camera_info.height / 2.0
fx = camera_info.width / (
2.0 * math.tan(float(self.carla_actor.attributes['fov']) * math.pi / 360.0))
fy = fx
2.actor_factory.py中导入鱼眼相机类。
python
from carla_ros_bridge.camera import Camera, RgbCamera, DepthCamera, SemanticSegmentationCamera, DVSCamera,FisheyeCamera
创建模型及初始化鱼眼相机,发布carla/ego_vehicle/fisheye/image的话题topic。
python
elif carla_actor.type_id.startswith("sensor.camera.fisheye"):
actor = FisheyeCamera(uid, name, parent, spawn_pose, self.node,
carla_actor, self.sync_mode)
相机绑定车辆
spawn_actor功能包中,依附于vehicle模型,object.json加入四个魚眼相机模型,以下是左相机的內外参数。
python
{
"type": "sensor.camera.fisheye",
"id": "fisheye_left",
"spawn_point": {"x": 0.0, "y": 1.05, "z": 1.05, "roll": 0.0, "pitch": 30.0, "yaw": 90.0},
"x_size": 960,
"y_size": 640,
"max_angle": 190,
"d_1": -3.5510560636666778e-02,
"d_2": -1.9848228876245811e-02,
"d_3": 2.6080053057044101e-02,
"d_4": -9.7183762742328750e-03,
"f_x": 3.0334009006384287e+02,
"f_y": 3.2229678244636966e+02,
"c_x": 4.8649280066241465e+02,
"c_y": 3.2388095214561167e+02
},
未完