-
Notifications
You must be signed in to change notification settings - Fork 9
/
debug.py
executable file
·225 lines (191 loc) · 6.48 KB
/
debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env python
# Copyright (c) 2018 Christoph Pilz
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
import carla
import time
import pprint
ipAddress = "172.20.0.207"
killCount = 0
def main():
print("# This script is for debug only")
print("Connecting to", ipAddress)
client = carla.Client(ipAddress, 2000)
client.set_timeout(2.0)
print("Client version", client.get_client_version())
print("Server version", client.get_server_version())
print("Getting world")
world = client.get_world()
print(world)
time.sleep(.1)
print("Getting actors")
actors = world.get_actors()
print("Found", len(actors), "actors")
while(True):
print("--- --- ---")
print("0 ... exit")
print("1 ... reload actors")
print("2 ... display actors")
print("3 ... actor kill menu")
print("4 ... actor pose menu")
print("5 ... toggle sync")
selection = input("Selection: ")
print("--- --- ---")
try:
s = int(selection)
except:
s = -1
if s == 0:
exit()
elif s == 1:
print("Reloading actors")
actors = world.get_actors()
print("Found", len(actors), "actors")
elif s == 2:
print("Displaying actors")
for actor in actors:
print(actor)
elif s == 3:
killMenu(actors)
elif s == 4:
poseMenu(actors)
elif s == 5:
settings = world.get_settings()
print("synchronous_mode was", settings.synchronous_mode)
settings.synchronous_mode = not settings.synchronous_mode
world.apply_settings(settings)
print("synchronous_mode is", settings.synchronous_mode)
else:
print("")
continue
def killMenu(actors):
actorID = input("Provide ActorID to kill (0 to abort): ")
try:
actorID = int(actorID)
except:
actorID = 0
if(actorID != 0):
try:
for actor in actors:
if(actor.id == actorID):
actor.destroy()
except Exception as e:
print("Killing gone wrong:", e)
global killCount
killCount += 1
if killCount == 5:
print("killing spree")
else:
print("Killing aborted ... for now")
def poseMenu(actors):
while(True):
print("--- Pose Menu ---")
print("0 ... exit to main menu")
print("1 ... get pose from actor")
print("2 ... set pose for actor (free)")
print("3 ... set pose for actor (defaults)")
selection = input("Selection: ")
print("--- --- ---")
try:
s = int(selection)
except:
s = -1
if s == 0:
return
elif s == 1:
actorID = input("Provide ActorID to print pose (0 to abort): ")
try:
actorID = int(actorID)
except:
actorID = 0
if(actorID != 0):
try:
for actor in actors:
if(actor.id == actorID):
print(actor.get_transform())
except Exception as e:
print("Error during pose retrieval:", e)
else:
print("Aborted pose retrieval")
elif s == 2:
print("Provide actor ID and pose, then confirm settings")
actorID = input("Provide ActorID: ")
x = input("x: ")
y = input("y: ")
z = input("z: ")
roll = input("roll(°): ")
pitch = input("pitch(°): ")
yaw = input("yaw(°): ")
try:
actorID = int(actorID)
x = int(x)
y = int(y)
z = int(z)
roll = int(roll)
pitch = int(pitch)
yaw = int(yaw)
except Exception as e:
print("Input error:", e)
continue
try:
for actor in actors:
if(actor.id == actorID):
transform = actor.get_transform()
print("old pose:", transform)
transform.location.x = x
transform.location.y = y
transform.location.z = z
transform.rotation.roll = roll
transform.rotation.pitch = pitch
transform.rotation.yaw = yaw
print("new pose:", transform)
decision = input("confirm pose change (y/n)")
if(decision == "y"):
actor.set_transform(transform)
else:
print("actor ID", actorID, "not found")
continue
except Exception as e:
print("Error during pose retrieval/setting:", e)
elif s == 3:
actorID = input("Provide ActorID: ")
actorForPose = None
try:
actorID = int(actorID)
for actor in actors:
if(actor.id == actorID):
actorForPose = actor
if(actorForPose == None):
print("Couldn't find actor")
continue
except Exception as e:
print("Input error:", e)
continue
transform1 = carla.Transform()
transform1.location.x = 80.0
transform1.location.y = 0.0
transform1.location.z = 60.0
transform1.rotation.roll = -88.0
transform1.rotation.pitch = -88.0
transform1.rotation.yaw = 0.0
print("Select Transform:")
print("0 ... abort")
print("1 ...", transform1)
option = input("Select Pose:")
try:
o = int(option)
except:
o = -1
if o == 1:
try:
actor.set_transform(transform1)
except Exception as e:
print("Error during pose setting:", e)
else:
print("Aborted")
else:
print("")
continue
if __name__ == '__main__':
main()