From fe1472ca6eb2751240979990c78e508e9d3d3b31 Mon Sep 17 00:00:00 2001 From: corkyw10 Date: Thu, 11 Feb 2021 11:34:36 +0100 Subject: [PATCH] Add code snippets to Python API for toggling env objects and map layers. Corrected spelling of snippets on buttons and headers --- Docs/python_api.md | 173 ++++++++++++++---- PythonAPI/docs/doc_gen.py | 2 +- PythonAPI/docs/doc_gen_snipets.py | 4 +- .../carla.World.enable_environment_objects.py | 15 ++ .../snipets/carla.World.load_map_layer.py | 22 +++ .../snipets/carla.World.unload_map_layer.py | 22 +++ 6 files changed, 199 insertions(+), 39 deletions(-) create mode 100644 PythonAPI/docs/snipets/carla.World.enable_environment_objects.py create mode 100644 PythonAPI/docs/snipets/carla.World.load_map_layer.py create mode 100644 PythonAPI/docs/snipets/carla.World.unload_map_layer.py diff --git a/Docs/python_api.md b/Docs/python_api.md index 3c12d3046..f204b834c 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -193,7 +193,7 @@ Returns the actor's attribute with `id` as identifier if existing. - **Setter:** _[carla.ActorBlueprint.set_attribute](#carla.ActorBlueprint.set_attribute)_ ##### Setters -- **set_attribute**(**self**, **id**, **value**) +- **set_attribute**(**self**, **id**, **value**) If the `id` attribute is modifiable, changes its value to `value`. - **Parameters:** - `id` (_str_) – The identifier for the attribute that is intended to be changed. @@ -391,7 +391,7 @@ The Client connects CARLA to the server which runs the simulation. Both server a The client also has a recording feature that saves all the information of a simulation while running it. This allows the server to replay it at will to obtain information and experiment with it. [Here](adv_recorder.md) is some information about how to use this recorder. ### Methods -- **\__init__**(**self**, **host**=127.0.0.1, **port**=2000, **worker_threads**=0) +- **\__init__**(**self**, **host**=127.0.0.1, **port**=2000, **worker_threads**=0) Client constructor. - **Parameters:** - `host` (_str_) – IP address where a CARLA Simulator instance is running. Default is localhost (127.0.0.1). @@ -401,7 +401,7 @@ Client constructor. Executes a list of commands on a single simulation step and retrieves no information. If you need information about the response of each command, use the __apply_batch_sync()__ method. [Here](https://github.com/carla-simulator/carla/blob/10c5f6a482a21abfd00220c68c7f12b4110b7f63/PythonAPI/examples/spawn_npc.py#L126) is an example on how to delete the actors that appear in [carla.ActorList](#carla.ActorList) all at once. - **Parameters:** - `commands` (_list_) – A list of commands to execute in batch. Each command is different and has its own parameters. They appear listed at the bottom of this page. -- **apply_batch_sync**(**self**, **commands**, **due_tick_cue**=False) +- **apply_batch_sync**(**self**, **commands**, **due_tick_cue**=False) Executes a list of commands on a single simulation step, blocks until the commands are linked, and returns a list of command.Response that can be used to determine whether a single command succeeded or not. [Here](https://github.com/carla-simulator/carla/blob/10c5f6a482a21abfd00220c68c7f12b4110b7f63/PythonAPI/examples/spawn_npc.py#L112-L116) is an example of it being used to spawn actors. - **Parameters:** - `commands` (_list_) – A list of commands to execute in batch. The commands available are listed right above, in the method **apply_batch()**. @@ -636,7 +636,7 @@ Draws an arrow from `begin` to `end` pointing in that direction. - `arrow_size` (_float – meters_) – Size of the tip of the arrow. - `color` (_[carla.Color](#carla.Color)_) – RGB code to color the object. Red by default. - `life_time` (_float – seconds_) – Shape's lifespan. By default it only lasts one frame. Set this to 0 for permanent shapes. -- **draw_box**(**self**, **box**, **rotation**, **thickness**=0.1, **color**=(255,0,0), **life_time**=-1.0) +- **draw_box**(**self**, **box**, **rotation**, **thickness**=0.1, **color**=(255,0,0), **life_time**=-1.0) Draws a box, ussually to act for object colliders. - **Parameters:** - `box` (_[carla.BoundingBox](#carla.BoundingBox)_) – Object containing a location and the length of a box for every axis. @@ -659,7 +659,7 @@ Draws a point `location`. - `size` (_float – meters_) – Density of the point. - `color` (_[carla.Color](#carla.Color)_) – RGB code to color the object. Red by default. - `life_time` (_float – seconds_) – Shape's lifespan. By default it only lasts one frame. Set this to 0 for permanent shapes. -- **draw_string**(**self**, **location**, **text**, **draw_shadow**=False, **color**=(255,0,0), **life_time**=-1.0) +- **draw_string**(**self**, **location**, **text**, **draw_shadow**=False, **color**=(255,0,0), **life_time**=-1.0) Draws a string in a given location of the simulation which can only be seen server-side. - **Parameters:** - `location` (_[carla.Location](#carla.Location) – meters_) – Spot in the simulation where the text will be centered. @@ -1443,7 +1443,7 @@ Returns a list of recommendations made by the creators of the map to be used as - **get_topology**(**self**) Returns a list of tuples describing a minimal graph of the topology of the OpenDRIVE file. The tuples contain pairs of waypoints located either at the point a road begins or ends. The first one is the origin and the second one represents another road end that can be reached. This graph can be loaded into [NetworkX](https://networkx.github.io/) to work with. Output could look like this: [(w0, w1), (w0, w2), (w1, w3), (w2, w3), (w0, w4)]. - **Return:** _list(tuple([carla.Waypoint](#carla.Waypoint), [carla.Waypoint](#carla.Waypoint)))_ -- **get_waypoint**(**self**, **location**, **project_to_road**=True, **lane_type**=[carla.LaneType.Driving](#carla.LaneType.Driving)) +- **get_waypoint**(**self**, **location**, **project_to_road**=True, **lane_type**=[carla.LaneType.Driving](#carla.LaneType.Driving)) Returns a waypoint that can be located in an exact location or translated to the center of the nearest lane. Said lane type can be defined using flags such as `LaneType.Driving & LaneType.Shoulder`. The method will return None if the waypoint is not found, which may happen only when trying to retrieve a waypoint for an exact location. That eases checking if a point is inside a certain road, as otherwise, it will return the corresponding waypoint. - **Parameters:** @@ -1914,7 +1914,7 @@ Iterate over the [carla.SemanticLidarDetection](#carla.SemanticLidarDetection) r When True the sensor will be waiting for data. ### Methods -- **listen**(**self**, **callback**) +- **listen**(**self**, **callback**) The function the sensor will be calling to every time a new measurement is received. This function needs for an argument containing an object type [carla.SensorData](#carla.SensorData) to work with. - **Parameters:** - `callback` (_function_) – The called function with one argument containing the sensor data. @@ -2038,7 +2038,7 @@ Sets a given time for the red state to be active. - **Parameters:** - `red_time` (_float – seconds_) - **Getter:** _[carla.TrafficLight.get_red_time](#carla.TrafficLight.get_red_time)_ -- **set_state**(**self**, **state**) +- **set_state**(**self**, **state**) Sets a given state to a traffic light actor. - **Parameters:** - `state` (_[carla.TrafficLightState](#carla.TrafficLightState)_) @@ -2522,7 +2522,7 @@ Sets the destination that the pedestrian will reach. - `destination` (_[carla.Location](#carla.Location) – meters_) - **start**(**self**) Enables AI control for its parent walker. -- **stop**(**self**) +- **stop**(**self**) Disables AI control for its parent walker. ##### Setters @@ -2781,7 +2781,7 @@ Casts a ray from the specified initial_location to final_location. The function - `initial_location` (_[carla.Location](#carla.Location)_) – The initial position of the ray. - `final_location` (_[carla.Location](#carla.Location)_) – The final position of the ray. - **Return:** _list([carla.LabelledPoint](#carla.LabelledPoint))_ -- **enable_environment_objects**(**self**, **env_objects_ids**, **enable**) +- **enable_environment_objects**(**self**, **env_objects_ids**, **enable**) Enable or disable a set of EnvironmentObject identified by their id. These objects will appear or disappear from the level. - **Parameters:** - `env_objects_ids` (_set(int)_) – Set of EnvironmentObject ids to change. @@ -2796,7 +2796,7 @@ Projects the specified point downwards in the scene. The functions casts a ray f - `location` (_[carla.Location](#carla.Location)_) – The point to be projected. - `search_distance` (_float_) – The maximum distance to perform the projection. - **Return:** _[carla.LabelledPoint](#carla.LabelledPoint)_ -- **load_map_layer**(**self**, **map_layers**) +- **load_map_layer**(**self**, **map_layers**) Loads the selected layers to the level. If the layer is already loaded the call has no effect. - **Parameters:** - `map_layers` (_[carla.MapLayer](#carla.MapLayer)_) – Mask of level layers to be loaded. @@ -2819,7 +2819,7 @@ Stops the callback for `callback_id` started with __on_tic - `callback_id` (_callback_) – The callback to be removed. The ID is returned when creating the callback. - **reset_all_traffic_lights**(**self**) Resets the cycle of all traffic lights in the map to the initial state. -- **spawn_actor**(**self**, **blueprint**, **transform**, **attach_to**=None, **attachment**=Rigid) +- **spawn_actor**(**self**, **blueprint**, **transform**, **attach_to**=None, **attachment**=Rigid) The method will create, return and spawn an actor into the world. The actor will need an available blueprint to be created and a transform (location and rotation). It can also be attached to a parent with a certain attachment type. - **Parameters:** - `blueprint` (_[carla.ActorBlueprint](#carla.ActorBlueprint)_) – The reference from which the actor will be created. @@ -2842,7 +2842,7 @@ Same as __spawn_actor()__ but returns None o - `attach_to` (_[carla.Actor](#carla.Actor)_) – The parent object that the spawned actor will follow around. - `attachment` (_[carla.AttachmentType](#carla.AttachmentType)_) – Determines how fixed and rigorous should be the changes in position according to its parent object. - **Return:** _[carla.Actor](#carla.Actor)_ -- **unload_map_layer**(**self**, **map_layers**) +- **unload_map_layer**(**self**, **map_layers**) Unloads the selected layers to the level. If the layer is already unloaded the call has no effect. - **Parameters:** - `map_layers` (_[carla.MapLayer](#carla.MapLayer)_) – Mask of level layers to be unloaded. @@ -2894,7 +2894,7 @@ Returns an object containing some data about the simulation such as synchrony be - **get_snapshot**(**self**) Returns a snapshot of the world at a certain moment comprising all the information about the actors. - **Return:** _[carla.WorldSnapshot](#carla.WorldSnapshot)_ -- **get_spectator**(**self**) +- **get_spectator**(**self**) Returns the spectator actor. The spectator is a special type of actor created by Unreal Engine, usually with ID=0, that acts as a camera and controls the view in the simulator window. - **Return:** _[carla.Actor](#carla.Actor)_ - **get_traffic_light**(**self**, **landmark**) @@ -3318,9 +3318,81 @@ document.getElementById("snipets-container").innerHTML = null; } +