Esempio n. 1
0
 def destroy_object(self, req, response=None):
     response = roscomp.get_service_response(DestroyObject)
     destroyed_actors = self.actor_factory.destroy_actor(req.id)
     response.success = bool(destroyed_actors)
     for actor in destroyed_actors:
         if actor in self._registered_actors:
             self._registered_actors.remove(actor)
     return response
    def execute_scenario(self, req, response=None):
        """
        Execute a scenario
        """
        self.loginfo("Scenario Execution requested...")

        response = get_service_response(ExecuteScenario)
        response.result = True
        if not os.path.isfile(req.scenario.scenario_file):
            self.logwarn("Requested scenario file not existing {}".format(
                req.scenario.scenario_file))
            response.result = False
        else:
            self._request_queue.put(req.scenario)
        return response
Esempio n. 3
0
    def get_blueprints(self, req):
        response = roscomp.get_service_response(GetBlueprints)
        if req.filter:
            bp_filter = req.filter
        else:
            bp_filter = "*"

        response.blueprints = [
            bp.id for bp in self.carla_world.get_blueprint_library().filter(
                bp_filter)
        ]
        response.blueprints.extend(
            self.actor_factory.get_pseudo_sensor_types())
        response.blueprints.sort()
        return response
Esempio n. 4
0
 def spawn_object(self, req, response=None):
     response = roscomp.get_service_response(SpawnObject)
     if not self.shutdown.is_set():
         try:
             id_ = self.actor_factory.spawn_actor(req)
             self._registered_actors.append(id_)
             response.id = id_
         except Exception as e:
             self.logwarn("Error spawning object '{}': {}".format(
                 req.type, e))
             response.id = -1
             response.error_string = str(e)
     else:
         response.id = -1
         response.error_string = 'Bridge is shutting down, object will not be spawned.'
     return response
    def get_waypoint(self, req, response=None):
        """
        Get the waypoint for a location
        """
        carla_position = carla.Location()
        carla_position.x = req.location.x
        carla_position.y = -req.location.y
        carla_position.z = req.location.z

        carla_waypoint = self.map.get_waypoint(carla_position)

        response = get_service_response(GetWaypoint)
        response.waypoint.pose = trans.carla_transform_to_ros_pose(carla_waypoint.transform)
        response.waypoint.is_junction = carla_waypoint.is_junction
        response.waypoint.road_id = carla_waypoint.road_id
        response.waypoint.section_id = carla_waypoint.section_id
        response.waypoint.lane_id = carla_waypoint.lane_id
        return response
    def get_actor_waypoint(self, req, response=None):
        """
        Convenience method to get the waypoint for an actor
        """
        # self.loginfo("get_actor_waypoint(): Get waypoint of actor {}".format(req.id))
        actor = self.world.get_actors().find(req.id)

        response = get_service_response(GetActorWaypoint)
        if actor:
            carla_waypoint = self.map.get_waypoint(actor.get_location())
            response.waypoint.pose = trans.carla_transform_to_ros_pose(carla_waypoint.transform)
            response.waypoint.is_junction = carla_waypoint.is_junction
            response.waypoint.road_id = carla_waypoint.road_id
            response.waypoint.section_id = carla_waypoint.section_id
            response.waypoint.lane_id = carla_waypoint.lane_id
        else:
            self.logwarn("get_actor_waypoint(): Actor {} not valid.".format(req.id))
        return response
    def get_waypoint(self, req, response=None):
        """
        Get the waypoint for a location
        """
        carla_position = carla.Location()
        carla_position.x = req.location.x
        carla_position.y = -req.location.y
        carla_position.z = req.location.z

        carla_waypoint = self.map.get_waypoint(carla_position)

        response = get_service_response(GetWaypoint)
        response.waypoint.pose.position.x = carla_waypoint.transform.location.x
        response.waypoint.pose.position.y = -carla_waypoint.transform.location.y
        response.waypoint.pose.position.z = carla_waypoint.transform.location.z
        response.waypoint.is_junction = carla_waypoint.is_junction
        response.waypoint.road_id = carla_waypoint.road_id
        response.waypoint.section_id = carla_waypoint.section_id
        response.waypoint.lane_id = carla_waypoint.lane_id
        #self.logwarn("Get waypoint {}".format(response.waypoint.pose.position))
        return response