12
12
from enum import Enum
13
13
14
14
try :
15
- import queue
15
+ import queue
16
16
except ImportError :
17
- import Queue as queue
18
-
17
+ import Queue as queue
18
+
19
19
from carla_ros_bridge .actor import Actor
20
20
from carla_ros_bridge .spectator import Spectator
21
21
from carla_ros_bridge .traffic import Traffic , TrafficLight
@@ -72,7 +72,7 @@ def __init__(self, node, world, sync_mode=False):
72
72
73
73
self ._task_queue = queue .Queue ()
74
74
self ._last_task = None
75
- self ._known_actor_ids = [] # used to immediately reply to spawn_actor/destroy_actor calls
75
+ self ._known_actor_ids = [] # used to immediately reply to spawn_actor/destroy_actor calls
76
76
77
77
self .lock = Lock ()
78
78
self .spawn_lock = Lock ()
@@ -128,15 +128,15 @@ def update_available_objects(self):
128
128
task = self ._task_queue .get ()
129
129
if task [0 ] == ActorFactory .TaskType .SPAWN_PSEUDO_ACTOR :
130
130
pseudo_object = task [1 ]
131
- self ._create_object (pseudo_object [0 ], pseudo_object [1 ].type , pseudo_object [1 ].id , pseudo_object [1 ].attach_to , pseudo_object [1 ].transform )
131
+ self ._create_object (pseudo_object [0 ], pseudo_object [1 ].type , pseudo_object [1 ].id ,
132
+ pseudo_object [1 ].attach_to , pseudo_object [1 ].transform )
132
133
elif task [0 ] == ActorFactory .TaskType .DESTROY_ACTOR :
133
134
actor_id = task [1 ]
134
135
self ._destroy_object (actor_id , delete_actor = True )
135
136
elif task [0 ] == ActorFactory .TaskType .SYNC :
136
137
break
137
138
self .lock .release ()
138
139
139
-
140
140
def update_actor_states (self , frame_id , timestamp ):
141
141
"""
142
142
update the state of all known actors
@@ -152,7 +152,7 @@ def update_actor_states(self, frame_id, timestamp):
152
152
153
153
def clear (self ):
154
154
for _ , actor in self .actors .items ():
155
- actor .destroy ()
155
+ actor .destroy ()
156
156
self .actors .clear ()
157
157
158
158
def spawn_actor (self , req ):
@@ -164,7 +164,7 @@ def spawn_actor(self, req):
164
164
"""
165
165
with self .spawn_lock :
166
166
if "pseudo" in req .type :
167
- #only allow spawning pseudo objects if parent actor already exists in carla
167
+ # only allow spawning pseudo objects if parent actor already exists in carla
168
168
if req .attach_to != 0 :
169
169
carla_actor = self .world .get_actor (req .attach_to )
170
170
if carla_actor is None :
@@ -189,7 +189,7 @@ def _destroy_actor(self, uid):
189
189
if uid in self ._known_actor_ids :
190
190
objects_to_destroy .append (uid )
191
191
self ._known_actor_ids .remove (uid )
192
-
192
+
193
193
# remove actors that have the actor to be removed as parent.
194
194
for actor in list (self .actors .values ()):
195
195
if actor .parent is not None and actor .parent .uid == uid :
@@ -225,7 +225,6 @@ def _spawn_carla_actor(self, req):
225
225
carla_actor = self .world .spawn_actor (blueprint , transform , attach_to )
226
226
return carla_actor .id
227
227
228
-
229
228
def _create_object_from_actor (self , carla_actor ):
230
229
"""
231
230
create a object for a given carla actor
@@ -239,9 +238,12 @@ def _create_object_from_actor(self, carla_actor):
239
238
else :
240
239
parent = self ._create_object_from_actor (carla_actor .parent )
241
240
# calculate relative transform
242
- actor_transform_matrix = trans .ros_pose_to_transform_matrix (trans .carla_transform_to_ros_pose (carla_actor .get_transform ()))
243
- parent_transform_matrix = trans .ros_pose_to_transform_matrix (trans .carla_transform_to_ros_pose (carla_actor .parent .get_transform ()))
244
- relative_transform_matrix = np .matrix (parent_transform_matrix ).getI () * np .matrix (actor_transform_matrix )
241
+ actor_transform_matrix = trans .ros_pose_to_transform_matrix (
242
+ trans .carla_transform_to_ros_pose (carla_actor .get_transform ()))
243
+ parent_transform_matrix = trans .ros_pose_to_transform_matrix (
244
+ trans .carla_transform_to_ros_pose (carla_actor .parent .get_transform ()))
245
+ relative_transform_matrix = np .matrix (
246
+ parent_transform_matrix ).getI () * np .matrix (actor_transform_matrix )
245
247
relative_transform = trans .transform_matrix_to_ros_pose (relative_transform_matrix )
246
248
247
249
parent_id = 0
@@ -251,10 +253,10 @@ def _create_object_from_actor(self, carla_actor):
251
253
name = carla_actor .attributes .get ("role_name" , "" )
252
254
if not name :
253
255
name = str (carla_actor .id )
254
- obj = self ._create_object (carla_actor .id , carla_actor .type_id , name , parent_id , relative_transform , carla_actor )
256
+ obj = self ._create_object (carla_actor .id , carla_actor .type_id , name ,
257
+ parent_id , relative_transform , carla_actor )
255
258
return obj
256
259
257
-
258
260
def _destroy_object (self , actor_id , delete_actor ):
259
261
if actor_id not in self .actors :
260
262
return
@@ -283,12 +285,11 @@ def _create_object(self, uid, type_id, name, attach_to, spawn_pose, carla_actor=
283
285
if attach_to != 0 :
284
286
if attach_to not in self .actors :
285
287
raise IndexError ("Parent object {} not found" .format (attach_to ))
286
-
288
+
287
289
parent = self .actors [attach_to ]
288
290
else :
289
291
parent = None
290
292
291
-
292
293
if type_id == TFSensor .get_blueprint_name ():
293
294
actor = TFSensor (uid = uid , name = name , parent = parent , node = self .node )
294
295
0 commit comments