|
21 | 21 |
|
22 | 22 | state = lgsvl.AgentState() |
23 | 23 | state.transform = spawns[0] |
24 | | -state.velocity = lgsvl.Vector(0, 0, 20) |
| 24 | +state.transform.position.z += 20 |
| 25 | +# state.velocity = lgsvl.Vector(0, 0, 20) |
25 | 26 | ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) |
26 | 27 |
|
27 | 28 | print("Python API Quickstart #27: How to Control Traffic Light") |
28 | 29 |
|
29 | | -# Get a list of controllable objects |
30 | | -controllables = sim.get_controllables() |
| 30 | +# # Get a list of controllable objects |
| 31 | +controllables = sim.get_controllables("signal") |
31 | 32 | print("\n# List of controllable objects in {} scene:".format(scene_name)) |
32 | 33 | for c in controllables: |
33 | 34 | print(c) |
34 | 35 |
|
35 | | -# Pick a traffic light of intrest |
36 | | -signal = controllables[2] |
| 36 | +signal = sim.get_controllable(lgsvl.Vector(19, 5, 21), "signal") |
| 37 | +print("\n# Signal of interest:") |
| 38 | +print(signal) |
37 | 39 |
|
38 | 40 | # Get current controllable states |
39 | 41 | print("\n# Current control policy:") |
40 | 42 | print(signal.control_policy) |
41 | 43 |
|
42 | 44 | # Create a new control policy |
43 | | -control_policy = "trigger=50;green=1;yellow=1.5;red=2;green=5;loop" |
| 45 | +control_policy = "trigger=50;green=3;yellow=2;red=1;loop" |
44 | 46 |
|
45 | 47 | # Control this traffic light with a new control policy |
46 | 48 | signal.control(control_policy) |
|
52 | 54 | print("\n# Current signal state before simulation:") |
53 | 55 | print(signal.current_state) |
54 | 56 |
|
55 | | -seconds = 10 |
| 57 | +seconds = 18 |
56 | 58 | input("\nPress Enter to run simulation for {} seconds".format(seconds)) |
57 | 59 | print("\nRunning simulation for {} seconds...".format(seconds)) |
58 | 60 | sim.run(seconds) |
|
0 commit comments