Carla and Ros joint simulation planning algorithm teaching and pitfall experience

Carla and Ros joint simulation teaching and pitfall experience-autonomous driving planning algorithm (including Apollo and autoware planning algorithms)

Preface

I need to use carla for simulation and experiments, and have been studying this platform for several months.
It should be noted that I did not keep all the ros packages, but selected some for use, and others can be expanded.

Comparison between carla0.9.5 version and carla0.9.11 version

Advantages of carla-0.9.5:

(1) The memory is small, the graphics card requirements are not high, and the operation is friendly.

(2) The code framework is friendly and sufficient for learning and using traditional planning algorithms.

(3) Suitable for beginners.

Disadvantages of carla-0.9.5:

(1) The sensors are incomplete.

(2) ros-bridge cannot draw Marker in carla.

(3) ros-bridge cannot subscribe to road information such as traffic light

(4) ros-bridge only supports ROS1

Advantages of carla-0.9.11:

(1) ros-bridge can be extended to multiple agents, carla_ad_agent (this package was deleted by me during the current development)

(2) ros-bridge can subscribe to road information such as traffic light

(3) ros-bridge can draw Marker in carla

(4) ros-bridge can be extended to ROS2

(5) Sensors are more complete

Disadvantages of carla-0.9.11:

(1) If it runs for a long time, the leaderboard will crash. The reason has not been found yet... It happens randomly.

4.26.2-0+++UE4+Release-4.26 522 0
Disabling core dumps.
Signal 11 caught.
Malloc Size=65538 LargeMemoryPoolOffset=65554 
CommonUnixCrashHandler: Signal=11
Malloc Size=131160 LargeMemoryPoolOffset=196744 
Malloc Size=131160 LargeMemoryPoolOffset=327928 
Engine crash handling finished; re-raising signal 11 for the default handler. Good bye.
Segmentation fault (core dumped)

(2) The memory is greater than version 0.9.5, and the graphics card requirements are higher.

(3) There are more bugs. For example, the code you wrote to place the car is OK in version 0.9.5, but will be offset in version 0.9.11.

(4) When ros is combined with rviz to close, CarlaUE4 easily hangs.

Study suggestions

(1) If you only learn to use path planning and control algorithms, and your computer configuration is poor, it is recommended that you use carla-0.9.5 version, which has fewer bugs.

(2) If you want to learn other content such as perception fusion, positioning fusion, etc., it is recommended to use carla-0.9.11 and above versions, because the sensors are complete, but this version has more bugs.

(3) Do not use carla versions 0.9.6, 0.9.7, 0.9.8, and 0.9.9, as they have TF bugs.

carla jointly developed with ros-version 0.9.5

carla-0.9.5 source code:

https://github.com/carla-simulator/carla/tree/0.9.5

After downloading, unzip and grant permissions to the entire folder.

sudo chmod -R 777 文件夹

Code testing of Carla alone

Installation Environment

pip install pygame numpy future networkx scikit-learn
pip install networkx
sudo apt-get install -y libomp5
sudo apt-get install jstest-gtk

I am using python3.8

Configure environment and test

First add in ~/.bashrc:

export PYTHONPATH=$PYTHONPATH:/opt/carla-0.9.5/PythonAPI/carla/dist/carla-0.9.5-py3.5-linux-x86_64.egg
export PYTHONPATH=$PYTHONPATH:/opt/carla-0.9.5/PythonAPI/egg/carla-0.9.5-py3.5-linux-x86_64.egg:/opt/carla-0.9.5/PythonAPI/agents

Then:

source ~/.bashrc

have a test:
python -c 'import carla; print("Success")'

Run carla:

./CarlaUE4.sh # 电脑配置可以
./CarlaUE4.sh -prefernvidia -quality-level=Low -benchmark -fps=15  # 电脑配置可以

-prefernvidia: start with NVIDIA graphics card

-quality-level=Low: Lower the rendering level

-benchmark -fps=15: The engine runs step by step at a fixed time of 1/15 second

Configuration options available:

carla-rpc-port=N:侦听端口 N 处的客户端连接。默认情况下,流式端口 Streaming port 设置为 N+1;
carla-streaming-port=N:指定用于传感器数据流的端口。 使用 0 获取随机未使用的端口。 第二个端口将自动设置为 N + 1;
quality-level={Low,Epic}:更改图形质量级别;
-carla-server:让 carla以服务的方式运行;
-benchmark -fps=15:引擎以1/15秒的固定时间逐步运行;
-windowed -ResX=800 -ResY=600:屏幕窗口大小;

Test py script:

python PythonAPI/examples/spawn_npc.py -n 30
python PythonAPI/examples/manual_control.py  
python PythonAPI/examples/automatic_control.py
python PythonAPI/examples/dynamic_weather.py -s 5   

-s 5 means to accelerate weather changes by 5 times.

Note that when using vscode to open a folder, some py files may not be able to find the directory when running. You can modify the import directory through the following instructions:

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))

ros-bridge (version 0.9.5.1)

Source code download: https://github.com/carla-simulator/ros-bridge/tree/0.9.5.1

Unzip after downloading.

Install dependent environment

sudo apt-get install python-protobuf
sudo apt install ros-noetic-ackermann-msgs
sudo apt install ros-noetic-derived-object-msgs
sudo apt install ros-noetic-vision-msgs

(base) pip install pyyaml
(base) pip install simple_pid
(base) pip3 install pycryptodomex

compile

py does not need to be compiled:

1.catkin build carla_msgs t4ac_msgs
2.catkin build

run

Run carla in the window:

./CarlaUE4.sh -windowed -ResX=640 -ResY=480 -quality-level=Low -fps=15

add more vehicles

python PythonAPI/examples/spawn_npc.py -n 30

test

source ./devel/setup.bash
roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch
(注意:此launch文件在本人开发的工程中被本人修改)

After running the command and then loading rviz, you can see the markers of the autonomous vehicle, markers of other vehicles, images, etc. You can also view published and subscribed topics through the rostopic list.

Specific reference: https://github.com/carla-simulator/ros-bridge/tree/0.9.5.1

The ros joint simulation process implemented by me for carla-0.9.5

Note: The carla version and the ros version must correspond, otherwise it will not work.

1. Modify the python2 content of ros-bridge to python3

This is simple. There are two places where python3 reports errors at the beginning. The modification plan is:

(1) The has_key function is changed to in

(2) items() replaces iteritems()

2. Modify the source code

I have modified the source code. Apart from some minor bugs, there are mainly the following points:

(1) Only keep the following ros packages and protocols. I moved carla_msgs to my own msgs folder. I integrated carla_waypoint_publisher into carla_ego_vehicle.py in version 0.9.5. Version 0.9.11 retains carla_waypoint_publisher. For details, see the introduction of version 0.9.11.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-uqX0mXrF-1688824666285)(/home/cg/.config/Typora/typora-user-images/image-20230122094733881 .png)]

(2) Create a new folder my_py, mainly writing three scripts

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-U6pMZm1w-1688824666286)(/home/cg/.config/Typora/typora-user-images/image-20230122094831393 .png)]

The functions are: changing the map, destroying actors, and placing static vehicles as static obstacles.

(3) Modify the source code of ros-bridge/carla_ego_vehicle/src/carla_ego_vehicle/carla_ego_vehicle.py, mainly modifying the following contents:

a.修改起点发布的话题,"/carla/{}/initialpose".format(self.role_name)修改为"/initialpose"
b.增加监视器spectator
c.增加终点订阅,还有全局规划导航点的获取和显示

(4) Modify the launch file, modify the launch file in ros-bridge/carla_ros_bridge/launch/carla_ros_bridge_with_ego_vehicle.launch, and delete the redundant test launch files in the ros-bridge project.

6. The pitfalls of carla-ros-bridge-0.9.5 version

(1) Pitfalls in control instructions

I don’t know. I use "/carla/" + role_name + "/vehicle_control_cmd" to control. The car will deviate while running, and the coordinate system is reversed, which means that we originally turned the steering wheel to the left to be positive. The right side is negative, so the right side is positive and the left side is negative. So, I changed it to "/carla/" + role_name + "/ackermann_cmd" for control, and the car will not deviate. The difference between these two topics is:

/carla/" + role_name + "/vehicle_control_cmd:发送的是油门(不等同于速度)和转角,左手坐标系

/carla/" + role_name + "/ackermann_cmd:发送速度,和转角弧度,右手坐标系,同时可以发送控制加速度的指令,对目标使用PID进行跟踪。

(2) Pit in the curve

The target cannot drive a 90-degree bend, there is no problem with trajectory planning, and there is no problem with simple ros simulation. The specific reason should be due to the control method and parameter configuration, which has not been solved yet.

(3) The role_name of the autonomous vehicle can only be selected between hero and ego_vehicle, but the autonomous vehicle tracking effects of the two under ros simulation are different.

7. Compile, run and use methods

Please refer to the video content.

Common errors

1.trying to create rpc server for traffic manager; but the system failed to cr

netstat -tnlp | grep :8000
kill -9 pid

2.INTEL-MESA: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0

sudo sysctl dev.i915.perf_stream_paranoid=0

3. Report an error:

X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
Major opcode of failed request: 149 ()
Minor opcode of failed request: 4
Resource id in failed request: 0x4600041
Serial number of failed request: 388
Current serial number in output stream: 399
terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
Signal 6 caught.
Segmentation fault (core dumped)

./CarlaUE4.sh -prefernvidia

Effect

Insert image description here

If you need the code, you can send a private message

Guess you like

Origin blog.csdn.net/weixin_39735688/article/details/131616964