def destroy(self): """ Function (override) to destroy this object. Terminate ROS subscriptions Finally forward call to super class. :return: """ self.node.logdebug("Destroy Vehicle(id={})".format(self.get_id())) self.node.destroy_subscription(self.control_subscriber) self.node.destroy_subscription(self.enable_autopilot_subscriber) self.node.destroy_subscription(self.control_override_subscriber) self.node.destroy_subscription(self.manual_control_subscriber) self.node.destroy_publisher(self.vehicle_status_publisher) self.node.destroy_publisher(self.vehicle_info_publisher) Vehicle.destroy(self)
def _create_object(self, uid, type_id, name, attach_to, spawn_pose, carla_actor=None): # check that the actor is not already created. if carla_actor is not None and carla_actor.id in self.actors: return None if attach_to != 0: if attach_to not in self.actors: raise IndexError( "Parent object {} not found".format(attach_to)) parent = self.actors[attach_to] else: parent = None if type_id == TFSensor.get_blueprint_name(): actor = TFSensor(uid=uid, name=name, parent=parent, node=self.node) elif type_id == OdometrySensor.get_blueprint_name(): actor = OdometrySensor(uid=uid, name=name, parent=parent, node=self.node) elif type_id == SpeedometerSensor.get_blueprint_name(): actor = SpeedometerSensor(uid=uid, name=name, parent=parent, node=self.node) elif type_id == MarkerSensor.get_blueprint_name(): actor = MarkerSensor(uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors) elif type_id == ActorListSensor.get_blueprint_name(): actor = ActorListSensor(uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors) elif type_id == ObjectSensor.get_blueprint_name(): actor = ObjectSensor( uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors, ) elif type_id == TrafficLightsSensor.get_blueprint_name(): actor = TrafficLightsSensor( uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors, ) elif type_id == OpenDriveSensor.get_blueprint_name(): actor = OpenDriveSensor(uid=uid, name=name, parent=parent, node=self.node, carla_map=self.world.get_map()) elif type_id == ActorControl.get_blueprint_name(): actor = ActorControl(uid=uid, name=name, parent=parent, node=self.node) elif carla_actor.type_id.startswith('traffic'): if carla_actor.type_id == "traffic.traffic_light": actor = TrafficLight(uid, name, parent, self.node, carla_actor) else: actor = Traffic(uid, name, parent, self.node, carla_actor) elif carla_actor.type_id.startswith("vehicle"): if carla_actor.attributes.get('role_name')\ in self.node.parameters['ego_vehicle']['role_name']: actor = EgoVehicle( uid, name, parent, self.node, carla_actor, self.node._ego_vehicle_control_applied_callback) else: actor = Vehicle(uid, name, parent, self.node, carla_actor) elif carla_actor.type_id.startswith("sensor"): if carla_actor.type_id.startswith("sensor.camera"): if carla_actor.type_id.startswith("sensor.camera.rgb"): actor = RgbCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.camera.depth"): actor = DepthCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith( "sensor.camera.semantic_segmentation"): actor = SemanticSegmentationCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.camera.dvs"): actor = DVSCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) else: actor = Camera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.lidar"): if carla_actor.type_id.endswith("sensor.lidar.ray_cast"): actor = Lidar(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.endswith( "sensor.lidar.ray_cast_semantic"): actor = SemanticLidar(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.radar"): actor = Radar(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.gnss"): actor = Gnss(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.imu"): actor = ImuSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.collision"): actor = CollisionSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.rss"): actor = RssSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.lane_invasion"): actor = LaneInvasionSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) else: actor = Sensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("spectator"): actor = Spectator(uid, name, parent, self.node, carla_actor) elif carla_actor.type_id.startswith("walker"): actor = Walker(uid, name, parent, self.node, carla_actor) else: actor = Actor(uid, name, parent, self.node, carla_actor) self.actors[actor.uid] = actor self.node.loginfo("Created {}(id={})".format(actor.__class__.__name__, actor.uid)) return actor
def _create_actor(self, carla_actor): # pylint: disable=too-many-branches,too-many-statements """ create an actor """ parent = None if carla_actor.parent: if carla_actor.parent.id in self.actors: parent = self.actors[carla_actor.parent.id] else: parent = self._create_actor(carla_actor.parent) actor = None pseudo_actors = [] if carla_actor.type_id.startswith('traffic'): if carla_actor.type_id == "traffic.traffic_light": actor = TrafficLight(carla_actor, parent, self.comm) else: actor = Traffic(carla_actor, parent, self.comm) elif carla_actor.type_id.startswith("vehicle"): if carla_actor.attributes.get('role_name')\ in self.parameters['ego_vehicle']['role_name']: ego_vehicle = EgoVehicle(carla_actor, parent, self.comm) actor = ego_vehicle pseudo_actors.append( ObjectSensor(parent=ego_vehicle, communication=self.comm, actor_list=self.actors, filtered_id=carla_actor.id)) else: actor = Vehicle(carla_actor, parent, self.comm) elif carla_actor.type_id.startswith("sensor"): if carla_actor.type_id.startswith("sensor.camera"): if carla_actor.type_id.startswith("sensor.camera.rgb"): actor = RgbCamera(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith("sensor.camera.depth"): actor = DepthCamera(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith( "sensor.camera.semantic_segmentation"): actor = SemanticSegmentationCamera( carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) else: actor = Camera(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith("sensor.lidar"): actor = Lidar(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith("sensor.other.gnss"): actor = Gnss(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith("sensor.other.collision"): actor = CollisionSensor(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith("sensor.other.lane_invasion"): actor = LaneInvasionSensor( carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) else: actor = Sensor(carla_actor, parent, self.comm, self.carla_settings.synchronous_mode) elif carla_actor.type_id.startswith("spectator"): actor = Spectator(carla_actor, parent, self.comm) elif carla_actor.type_id.startswith("walker"): actor = Walker(carla_actor, parent, self.comm) else: actor = Actor(carla_actor, parent, self.comm) rospy.loginfo("Created {}(id={}, parent_id={}," " type={}, prefix={}, attributes={})".format( actor.__class__.__name__, actor.get_id(), actor.get_parent_id(), carla_actor.type_id, actor.get_prefix(), carla_actor.attributes)) with self.update_lock: self.actors[carla_actor.id] = actor for pseudo_actor in pseudo_actors: rospy.loginfo("Created {}(parent_id={}, prefix={})".format( pseudo_actor.__class__.__name__, pseudo_actor.get_parent_id(), pseudo_actor.get_prefix())) with self.update_lock: self.pseudo_actors.append(pseudo_actor) return actor
def _create_object(self, uid, type_id, name, parent, spawn_pose, carla_actor=None): if type_id == TFSensor.get_blueprint_name(): actor = TFSensor(uid=uid, name=name, parent=parent, node=self.node) elif type_id == OdometrySensor.get_blueprint_name(): actor = OdometrySensor(uid=uid, name=name, parent=parent, node=self.node) elif type_id == SpeedometerSensor.get_blueprint_name(): actor = SpeedometerSensor(uid=uid, name=name, parent=parent, node=self.node) elif type_id == MarkerSensor.get_blueprint_name(): actor = MarkerSensor(uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors) elif type_id == ActorListSensor.get_blueprint_name(): actor = ActorListSensor(uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors) elif type_id == ObjectSensor.get_blueprint_name(): actor = ObjectSensor( uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors, ) elif type_id == TrafficLightsSensor.get_blueprint_name(): actor = TrafficLightsSensor( uid=uid, name=name, parent=parent, node=self.node, actor_list=self.actors, ) elif type_id == OpenDriveSensor.get_blueprint_name(): actor = OpenDriveSensor(uid=uid, name=name, parent=parent, node=self.node, carla_map=self.world.get_map()) elif type_id == ActorControl.get_blueprint_name(): actor = ActorControl(uid=uid, name=name, parent=parent, node=self.node) elif carla_actor.type_id.startswith('traffic'): if carla_actor.type_id == "traffic.traffic_light": actor = TrafficLight(uid, name, parent, self.node, carla_actor) else: actor = Traffic(uid, name, parent, self.node, carla_actor) elif carla_actor.type_id.startswith("vehicle"): if carla_actor.attributes.get('role_name')\ in self.node.parameters['ego_vehicle']['role_name']: actor = EgoVehicle( uid, name, parent, self.node, carla_actor, self.node._ego_vehicle_control_applied_callback) else: actor = Vehicle(uid, name, parent, self.node, carla_actor) elif carla_actor.type_id.startswith("sensor"): if carla_actor.type_id.startswith("sensor.camera"): if carla_actor.type_id.startswith("sensor.camera.rgb"): actor = RgbCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.camera.depth"): actor = DepthCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith( "sensor.camera.semantic_segmentation"): actor = SemanticSegmentationCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.camera.dvs"): actor = DVSCamera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) else: actor = Camera(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.lidar"): if carla_actor.type_id.endswith("sensor.lidar.ray_cast"): actor = Lidar(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.endswith( "sensor.lidar.ray_cast_semantic"): actor = SemanticLidar(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.radar"): actor = Radar(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.gnss"): actor = Gnss(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.imu"): actor = ImuSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.collision"): actor = CollisionSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.rss"): actor = RssSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("sensor.other.lane_invasion"): actor = LaneInvasionSensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) else: actor = Sensor(uid, name, parent, spawn_pose, self.node, carla_actor, self.sync_mode) elif carla_actor.type_id.startswith("spectator"): actor = Spectator(uid, name, parent, self.node, carla_actor) elif carla_actor.type_id.startswith("walker"): actor = Walker(uid, name, parent, self.node, carla_actor) else: actor = Actor(uid, name, parent, self.node, carla_actor) return actor