Skip to content
Snippets Groups Projects
Commit 572b8e1d authored by David Uhm's avatar David Uhm Committed by Martins Mozeiko
Browse files

Update docs for controllable objects

parent 464118f1
No related branches found
No related tags found
No related merge requests found
......@@ -30,4 +30,5 @@ This document describes the example Python scripts that use the LGSVL Simulator
* [24-ego-drive-straight-non-realtime.py](https://github.com/lgsvl/PythonAPI/tree/master/Api/24-ego-drive-straight-non-realtime.py): How to run the simulator at non-realtime.
* [25-waypoint-flying-npc.py](https://github.com/lgsvl/PythonAPI/tree/master/Api/25-waypoint-flying-npc.py): How to use waypoints to define customized motion for npc.
* [26-npc-trigger-waypoints.py](https://github.com/lgsvl/PythonAPI/tree/master/Api/26-npc-trigger-waypoints.py): How to use trigger waypoints that pause npc motion until an ego vehicle approaches.
* [27-control-traffic-lights.py](https://github.com/lgsvl/PythonAPI/tree/master/Api/27-control-traffic-lights.py): How to control controllable objects (e.g., changing a traffic light signal)
* [99-utils-examples.py](https://github.com/lgsvl/PythonAPI/tree/master/Api/quickstart/99-utils-examples.py): How to use several of the utility scripts to transform an arbitrary point to the coordinate system of a local transform (relative to sensor)
......@@ -521,6 +521,53 @@ sim.set_time_of_day(10, fixed=True)
This will set current time of day to 10am. The optional bool argument `fixed` indicates whether the simulation
should advance this time automatically or freeze it and not change it (`fixed=True`).
## Controllable Objects <sub><sup>[top](#top)</sup></sub> {: #controllable-objects data-toc-label='Controllable Objects'}
A controllable object is an object that you can control by performing an action using Python APIs. Each controllable object has its own `valid actions` (e.g., green, yellow, red, trigger, wait, loop) that it can take and is controlled based on `control policy`, which defines rules for control actions.
For example, a traffic light is a controllable object, and you can change its behavior by updating control policy: `"trigger=50;green=1;yellow=1.5;red=2;loop"`
* `trigger=50` - Wait until an ego vehicle approaches this controllable object within 50 meters
* `green=1` - Change current state to `green` and wait for 1 second
* `yellow=1.5` - Change current state to `yellow` and wait for 1.5 second
* `red=2` - Change current state to `red` and wait for 2 second
* `loop` - Loop over this control policy from the beginning
Available controllable object types:
* **signal**
To get a list of controllable objects in a scene:
```python
controllables = sim.get_controllables()
```
For a controllable object of interest, you can get following information:
```python
signal = controllables[0]
print("Type:", signal.type)
print("Transform:", signal.transform)
print("Current state:", signal.current_state)
print("Valid actions:", signal.valid_actions)
```
For control policy, each controllable object always has default control policy (read-only). When you load a scene for the first time or reset a scene to the initial state, a controllable object resets current control policy to default one follows it.
You can get default control policy and current control policy as follows:
```python
print("Default control policy:", signal.default_control_policy)
print("Current control policy:", signal.control_policy)
```
To change a current control policy, you can create a new control policy and call `control` function as below:
```python
control_policy = "trigger=50;green=1;yellow=1.5;red=2;loop"
signal.control(control_policy)
```
## Helper Functions <sub><sup>[top](#top)</sup></sub> {: #helper-functions data-toc-label='Helper Functions'}
Simulator class offers following helper functions:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment