当前位置:网站首页>Carla notes (04) - client and world (create client, connect world, batch object, set weather, set lights, world snapshots)
Carla notes (04) - client and world (create client, connect world, batch object, set weather, set lights, world snapshots)
2022-07-27 14:07:00 【wohu1104】
World and Client yes CARLA The two basic elements of , It is a necessary abstract concept of operational simulation and its participants .
Client It is a module that users request information or change state from the simulation server , Client The runtime requires a connection to the server IP and port, There can be multiple at the same time Client End operation , More advanced multi client management requires in-depth understanding Carla And synchronization .
World It is an object that represents simulation . It acts as an abstraction layer , Include build roles 、 Change the weather 、 Get the current state of the world and other main methods . Each simulation has only one world . When the map changes , It will be destroyed and a new World replaced .
1. Client
client yes CARLA One of the main elements in the architecture . They're connected to server、 Retrieve information and send commands , This is done through scripts . The client and world Connect , Then with the operation simulation. besides ,client You can also access advanced CARLA modular 、 characteristic , You can also use batch commands .
1.1 establish Client
Two parameters are required , The first is IP Address , The second is for connecting server Of TCP port , The third is an optional parameter to set the number of worker threads , The default setting is all(0).
client = carla.Client('localhost', 2000)
By default ,CARLA Use local host IP And port 2000 Connect , But these can be changed at will . The second port is often N+1, Be similar to 2001 .
Once the client client Established , You need to set its timeout timeout . This limits all network operations , So that these operations will not block the client forever . If the connection fails , An error will be returned .
client.set_timeout(10.0) # seconds
Can connect multiple clients , Because there are usually multiple scripts running at the same time . With advanced CARLA Feature works in a multi client solution , Such as traffic manager, It will inevitably make communication more complex .
The client and server are different
libcarlamodular . If the versions are different , There may be problems . This can be done separately byget_client_version()andget_server_version()Method to check their version numbers .
1.2 Connect World
client The object is to follow Carla The only way to interact with the environment , With client After object , We can get Carla The world in the environment (World) 了 ,World The object represents Carla The world in the environment , You want to create anything in the world , All to this World Add to object .
If we want to make any changes in the simulation world , All have to get for this world To operate .Client You can easily connect to... Through the following command world.
world = client.get_world()
You can get a lot from the client maps To change the currently selected , So the current world Will be destroyed and a new world
print(client.get_available_maps())
Output
['/Game/Carla/Maps/Town01', '/Game/Carla/Maps/Town01_Opt',
'/Game/Carla/Maps/Town02', '/Game/Carla/Maps/Town02_Opt',
'/Game/Carla/Maps/Town03', '/Game/Carla/Maps/Town03_Opt',
'/Game/Carla/Maps/Town04', '/Game/Carla/Maps/Town04_Opt',
'/Game/Carla/Maps/Town05', '/Game/Carla/Maps/Town05_Opt',
'/Game/Carla/Maps/Town10HD_Opt', '/Game/Carla/Maps/Town10HD',
]
Loading the map
world = client.load_world('Town01')
#client.reload_world() creates a new instance of the world with the same map.
Every world All objects in have one id. Every time the client calls load_world() or reload_world() when , Previous one world One will be destroyed . A new world Start from scratch , Unreal Engine UE There was no restart in the process .
1.3 Use batch
The command line has some of the most common CARLA Method adaptation , It can also be applied in batch . for example ,command.SetAutopilot Equate to vehicle. set_autopilot(), Enable automatic driving of the vehicle . You can also use batch Client Method . Such as apply_batch or Client.apply_batch_sync(), You can process multiple commands in one simulation step .
The following example uses a batch process to destroy a vehicle list at one time .
client.apply_batch([carla.command.DestroyActor(x) for x in vehicles_list])
1.4 Other client components
client The main purpose of the object is to get or change the world , And apply the command . however , It also provides some additional features .
Traffic manager: This module is responsible for every self driving vehicle , To recreate urban traffic .Recorder: Allows reproduction of previous simulations , Use snapshots to summarize the simulation status of each frame .
2. World
simulation The main controller of . Its examples are client retrieval . It does not contain world Its own model , These models are Map Part of class . contrary , Most information and general settings can be accessed from this class , for example :
Actors in the simulation and the spectatorBlueprint libraryMapSimulation settingsSnapshotsWeather and light manager
2.1 Actors
stay world There are different methods related to participants in , These methods allow different functions .
Spawn actors (but not destroy them)Get every actor on scene, or find one in particularAccess the blueprint libraryAccess the spectator actor, the simulation’s point of viewRetrieve a random location that is fitting to spawn an actor
2.2 Weather
weather Itself is not a class , It's a set of parameters available from the world . Parameters include the direction of the sun 、 cloud 、 wind 、 Fog, etc .
weather = carla.WeatherParameters(
cloudiness=80.0,
precipitation=30.0,
sun_altitude_angle=70.0)
world.set_weather(weather)
print(world.get_weather())
Some weather parameters can be preset in world in
world.set_weather(carla.WeatherParameters.WetCloudySunset)
stay Carla You can also customize your own weather, This involves two scripts :
environment.py( stayPythonAPI/utilin ) Provides access to weather and light parameters , So that these parameters can be changed in real time . The optional parameters of this script are :
-h, --help show this help message and exit
--host H IP of the host server (default: 127.0.0.1)
-p P, --port P TCP port to listen to (default: 2000)
--sun SUN Sun position presets [sunset | day | night]
--weather WEATHER Weather condition presets [clear | overcast | rain]
--altitude A, -alt A Sun altitude [-90.0, 90.0]
--azimuth A, -azm A Sun azimuth [0.0, 360.0]
--clouds C, -c C Clouds amount [0.0, 100.0]
--rain R, -r R Rain amount [0.0, 100.0]
--puddles Pd, -pd Pd Puddles amount [0.0, 100.0]
--wind W, -w W Wind intensity [0.0, 100.0]
--fog F, -f F Fog intensity [0.0, 100.0]
--fogdist Fd, -fd Fd Fog Distance [0.0, inf)
--wetness Wet, -wet Wet
Wetness intensity [0.0, 100.0]
dynamic_weather.py( stayPythonAPI/examplesin ) Enable by developers for eachCARLASpecific weather cycles for map preparation . The optional parameters of this script are :
-h, --help show this help message and exit
--host H IP of the host server (default: 127.0.0.1)
-p P, --port P TCP port to listen to (default: 2000)
-s FACTOR, --speed FACTOR
rate at which the weather changes (default: 1.0)
Be careful : Changes in the weather will not affect the physical world . They are just the visual effects that camera sensors can capture .
When sun_altitude_angle < 0 when , Night mode starts , This is known as sunset . This is when light becomes particularly important .
2.3 Lights
When the simulation enters night mode , The street lights will turn on automatically . The light is placed by the developer of the map , And can be used as carla.Light Object access . Properties such as color and intensity can be changed at will . carla.LightState Variable of type light_state Allows you to set all of these in one call .
Street lamps use carla.LightGroup Properties of type light_group To classify . This allows the lamp to be classified as a street lamp 、 Architectural lights …… Can retrieve carla.LightManager To handle a set of lights in a single call .
# Get the light manager and lights
lmanager = world.get_lightmanager()
mylights = lmanager.get_all_lights()
# Custom a specific light
light01 = mylights[0]
light01.turn_on()
light01.set_intensity(100.0)
state01 = carla.LightState(200.0,red,carla.LightGroup.Building,True)
light01.set_light_state(state01)
# Custom a group of lights
my_lights = lmanager.get_light_group(carla.LightGroup.Building)
lmanager.turn_on(my_lights)
lmanager.set_color(my_lights,carla.Color(255,0,0))
lmanager.set_intensities(my_lights,list_of_intensities)
Vehicle lights Must be opened by the user / close . Each car has a group in carla.VehicleLightState Lights listed in . up to now , Not all vehicles have integrated lighting . Here's a list of things that are available at the time of writing .
Bikes: They all have a front and rear position lightMotorcycles: Yamaha and Harley Davidson modelsCars: audi TT、 Chevrolet 、 The dodgers ( The police car )、Etron、 Lincoln 、 Wild horses 、 tesla 3S、 The public T2
You can use methods carla.Vehicle.get_light_state and carla.Vehicle.set_light_state Get and update the vehicle's lights at any time , These use binary operations to customize light settings .
# Turn on position lights
current_lights = carla.VehicleLightState.NONE
current_lights |= carla.VehicleLightState.Position
vehicle.set_light_state(current_lights)
You can also use
environment.pySet real-time lights .
2.4 Debugging
World The object has a carla.DebugHelper Object as a public property . It allows different shapes to be drawn during the simulation , Used to track what's happening . The following example will be in the actor Actor Draw a red box at the position and rotation of .
debug = world.debug
debug.draw_box(carla.BoundingBox(actor_snapshot.get_transform().location,carla.Vector3D(0.5,0.5,2)),
actor_snapshot.get_transform().rotation,
0.05,
carla.Color(255,0,0,0),0)
This example is in carla Has been extended in a fragment of . It shows how to draw a box for each participant in the world snapshot .
2.5 World snapshots
The state of each character in a single frame in the simulation is a still image . The information comes from the same simulation step , Even in asynchronous mode .
# Retrieve a snapshot of the world at current frame.
world_snapshot = world.get_snapshot()
carla.WorldSnapshot Contains a carla.Timestamp And a carla.ActorSnapshot list . have access to Actor Of ID Search for Actor Snapshot . The snapshot lists the Actor Of ID.
timestamp = world_snapshot.timestamp # Get the time reference
for actor_snapshot in world_snapshot: # Get the actor and the snapshot information
actual_actor = world.get_actor(actor_snapshot.id)
actor_snapshot.get_transform()
actor_snapshot.get_velocity()
actor_snapshot.get_angular_velocity()
actor_snapshot.get_acceleration()
actor_snapshot = world_snapshot.find(actual_actor.id) # Get an actor's snapshot
2.6 World settings
World You can access some advanced configurations for simulation . These determine the rendering conditions 、 Simulate time steps and synchronization between client and server . They can be from helper classes carla.WorldSettings Medium visit .
边栏推荐
- CARLA 笔记(04)— Client 和 World (创建 Client、连接 World 、批处理对象、设置 Weather、设置 Lights、World snapshots)
- Small program completion work wechat campus laundry small program graduation design finished product (2) small program function
- See if you are on the shortlist of each division
- [luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging
- Matlab digital image processing experiment 2: single pixel spatial image enhancement
- Interview secrets are widely distributed, and the exclusive secrets of editing, testing and learning are leaked?!
- Ncnn compilation and use pnnx compilation and use
- 【2022-07-25】
- 面试八股文之·TCP协议
- Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers
猜你喜欢

Flat die cutting machine

Thinkphp+ pagoda operation environment realizes scheduled tasks

RSS tutorial: aggregate your own information collection channels, rshub, freshrss, NetNewsWire

关于max做动画的一些关键信息(shift+v)

What are the benefits of taking NPDP

A Keypoint-based Global Association Network for Lane Detection

SQL tutorial: introduction to SQL aggregate functions

NoSQL —— NoSQL 三大理论基石 —— CAP —— BASE—— 最终一致性

redis集群搭建-使用docker快速搭建一个测试redis集群

Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
随机推荐
【图论】负环
Small program completion work wechat campus laundry small program graduation design finished product (2) small program function
纯c手写线程池
Vscode -- create template file
this指向问题,闭包以及递归
【多线程的相关内容】
Mining enterprise association based on Enterprise Knowledge Map
Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers
[training day4] anticipating [expected DP]
认知篇----硬件工程师的成才之路之经典
Windows10 installing SQL Server 2019
Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
Converter registration of easyexcel
592. Fraction addition and subtraction
Sword finger offer II 041. Average value of sliding window
There is no need for semantic segmentation of annotation data! Eth & Leuven University proposed maskdistill, using transformer for unsupervised semantic segmentation, SOTA
开源版思源怎么私有部署
致尚科技IPO过会:年营收6亿 应收账款账面价值2.7亿
阿里最新股权曝光:软银持股23.9% 蔡崇信持股1.4%
Experience sharing of system architecture designers preparing for the exam: a tough battle for nearly three months