Table of contents
- 1. Increase pedestrian flow and vehicle flow
- 2. Change the server time, light, weather
- 3. Manually control the vehicle
- 4. Automated driving of vehicles
- 5. Example of a client-side bounding box with basic car controls
- 6. Startup without rendering mode
- Seven. Logitech G29 steering wheel control carla
- 8. Vehicle display
- Nine. Display different pulse and force application effects
- 10. Visualization of multiple sensors
1. Increase pedestrian flow and vehicle flow
The execution file is the generate_traffic.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
open carla first
./CarlaUE4.sh
Then switch to the /home/car/CARLA_0.9.13/PythonAPI/examples path
python generate_traffic.py -w 10 -n 10
It can be seen that there are many moving vehicles and pedestrians on the streets in the carla server. The following parameters -n 10 -w 10 represent the number of vehicles and pedestrians respectively. This script has many other parameters:
'--host', #主机服务器ip
'-p', '--port',#端口
'-n', '--number-of-vehicles',#车辆数量
'-w', '--number-of-walkers',#行人数量
'--safe',#避免碰撞
'--filterv',#车辆滤波器
'--filterw',#行人滤波器
'--generationv',#限制某些车辆生成
'--generationw',#限制某些行人生成
等等
2. Change the server time, light, weather
The execution file is the dynamic_weather.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python dynamic_weather.py -s 5
The parameter -s 5 means to speed up the weather change by 5 times.
This script modifies the weather parameter
carla.WeatherParameters in the server according to the simulation time, and automatically adjusts the lighting and weather of the system in a certain order.
The lighting conditions include: the height of the sun And the sun angle.
Weather conditions include: cloud, rain, puddles, wind, fog, humidity.
Let's briefly analyze how the script modifies the weather.
# 设置更新频率
speed_factor = args.speed
update_freq = 0.1 / speed_factor
# 创建一个客户端
client = carla.Client(args.host, args.port)
# 获取世界变量
world = client.get_world()
# 创建天气变量
weather = Weather(world.get_weather())
# 在while循环中,不断修改weather
while True:
timestamp = world.wait_for_tick(seconds=30.0).timestamp
elapsed_time += timestamp.delta_seconds
if elapsed_time > update_freq:
weather.tick(speed_factor * elapsed_time)
# 把修改后的wheather载入世界变量.
world.set_weather(weather.weather)
sys.stdout.write('\r' + str(weather) + 12 * ' ')
sys.stdout.flush()
elapsed_time = 0.0)
Foggy weather
daytime
night
For more weather parameter settings, please refer to carla.WeatherParameters in /pythonAPI/python_api.md.
3. Manually control the vehicle
The execution file is the manual_control.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python manual_control.py
Keyboard B button can switch between automatic control and manual control
The pygame operation manual is as follows:
W : 前进。↑ 键也可以前进。
S : 刹车。↓ 键也可以 刹车
A/D : A 左转 D 右转。← 也可以左转,→ 也可以右转。
Q : Q 倒车标志。Q+W 可以倒车。
Space : 空格是手刹。和 S 不同。
P : 开启/关闭自动驾驶模式。
M : 自动档/手动档
,/. : 加减挡。,减档 . 加档
CTRL + W : 同时按下 CTRL + W ,在放开 CTRL + W ,车会一直以 60 km/h 的速度前进
L : 控制车灯切换。雾灯、近光灯等切换。
SHIFT + L : 切换远光灯
Z/X : 转向灯。Z 左转向,X 右转向。
I : 车内照明灯。
TAB : 切换视角
N : 切换不同类型的 camera 和 lidar
[1-9] : 切换不同类型的 camera 和 lidar,和 N 不同,N 每按下一次,sensor 顺序切换。按下数字键,可直接切换到对应 sensor
G : 打开/关闭 毫米波雷达
C : 切换天气,(Shift+C ,天气有多种,切换顺序和C相反)
Backspace : 换车型
V : 选地图图层 (Shift+V ,地图有多个图层,切换顺序和V 相反)
B : 加载当前的地图图层(Shift+B 卸载当前的地图图层)
O : 打开/关闭所有车门
T : 切换到车辆的自动测量记录传导,在carla客户端界面显示
R : 记录车辆走行情况
CTRL + R : 切换到 R做的记录 (replacing any previous)
CTRL + P : 回放R的记录
CTRL + + : increments the start time of the replay by 1 second (+SHIFT = 10 seconds)
CTRL + - : decrements the start time of the replay by 1 second (+SHIFT = 10 seconds)
F1 : 显示/不显示页面左侧和sensor相关的一些信息,例如加速度,陀螺仪,GNSS等
H : 可以弹出帮助命令
ESC : 退出pygame
4. Automated driving of vehicles
The execution file is the automatic_control.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python automatic_control.py
A pygame window will pop up, the vehicle is driving automatically
After reaching the end point, it will automatically close
5. Example of a client-side bounding box with basic car controls
The execution file is the client_bounding_boxes.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python client_bounding_boxes.py
A window pops up with the vehicle's basic controls (forward, reverse, steering, brakes).
6. Startup without rendering mode
The execution file is the no_rendering_mode.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python no_rendering_mode.py
At this point, a window without rendering mode will open, and
the movement of the framed vehicle can be manually controlled
Seven. Logitech G29 steering wheel control carla
The execution file is the manual_control_steeringwheel.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python manual_control_steeringwheel.py --host <服务器地址>
If the machine is running, there is no need to add the server address
Pop up the pygame window
At this point the vehicle can already be controlled with the steering wheel, buttons and brakes.
8. Vehicle display
The execution file is the vehicle_gallery.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python vehicle_gallery.py
At this point, you can see that the carla server is displaying different models of vehicles in a loop
Nine. Display different pulse and force application effects
The execution file is the vehicle_physics.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python vehicle_physics.py
You can see that there is a car at the specified location bouncing on the carla server
10. Visualization of multiple sensors
Script to render multiple sensors in the same pygame window
By default it renders four cameras, one lidar and one semantic lidar.
It can be easily configured for any different number of sensors.
The execution file is the visualize_multiple_sensors.py file under the path of /home/car/CARLA_0.9.13/PythonAPI/examples
python visualize_multiple_sensors.py
At this point, a pygame window pops up, and you can see the default rendered sensors (camera, lidar, semantic lidar)