当前位置:网站首页>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 .
边栏推荐
- There is no need for semantic segmentation of annotation data! Eth & Leuven University proposed maskdistill, using transformer for unsupervised semantic segmentation, SOTA
- The finished product of wechat campus laundry applet graduation design (1) development outline
- Recommended collection, confusing knowledge points of PMP challenge (2)
- The universe has no end. Can utonmos shine the meta universe into reality?
- Redis cluster setup - use docker to quickly build a test redis cluster
- Experience sharing of system architecture designers preparing for the exam: a tough battle for nearly three months
- 认知篇----硬件工程师的成才之路之经典
- 【2022-07-25】
- Chapter 3 business function development (add clues and remarks, and automatically refresh the added content)
- Schematic diagram of C measuring tool
猜你喜欢

13、用户web层服务(一)

Wechat campus laundry applet graduation design finished product (5) assignment

10 practical uses of NFT

Shell编程规范与变量

592. 分数加减运算

Matlab digital image processing experiment 2: single pixel spatial image enhancement

建议收藏,PMP应战篇(2)之易混淆知识点

Realize the basic operations such as the establishment, insertion, deletion and search of linear tables based on C language

Application layer World Wide Web WWW
![[related contents of multithreading]](/img/2d/c8bde21f13a5305ba54e9b52bd1e89.png)
[related contents of multithreading]
随机推荐
HDU4565 So Easy!【矩阵连乘】【推导】
为什么会出现Script file ‘D:\Anaconda3\envs\paddle_env\Scripts\pip-script.py‘ is not present.
Vscode -- create template file
WPF visifire.charts4.6.1 tutorial with source code
记账软件如何查看收入支出
Matlab digital image processing experiment 2: single pixel spatial image enhancement
JWT login expiration - automatic refresh token scheme introduction
Shell编程规范与变量
HDU4496 D-City【并查集】
13. User web layer services (I)
Flexible and easy to use WYSIWYG visual report
NoSQL -- three theoretical cornerstones of NoSQL -- cap -- Base -- final consistency
[training day4] sequence transformation [thinking]
[x for x in list_a if not np.isnan(x)]和[x if not np.isnan(x) else None for x in list_a]的区别
CARLA 笔记(04)— Client 和 World (创建 Client、连接 World 、批处理对象、设置 Weather、设置 Lights、World snapshots)
[idea] set to extract serialVersionUID
认知篇----硬件工程师的成才之路之经典
Alibaba's latest equity exposure: Softbank holds 23.9% and caichongxin holds 1.4%
[note] logistic regression
面试八股文之·TCP协议