示例#1
0
    def add_agent(self,
                  agent: ip.Agent,
                  rolename: str = None,
                  blueprint: carla.ActorBlueprint = None):
        """ Add a vehicle to the simulation. Defaults to an Audi A2 for blueprints if not explicitly given.

        Args:
            agent: Agent to add.
            rolename: Unique name for the actor to spawn.
            blueprint: Optional blueprint defining the properties of the actor.

        Returns:
            The newly added actor.
        """
        if blueprint is None:
            blueprint_library = self.__world.get_blueprint_library()
            blueprint = blueprint_library.find('vehicle.audi.a2')

        if rolename is not None:
            blueprint.set_attribute('role_name', rolename)

        state = agent.state
        yaw = np.rad2deg(-state.heading)
        transform = Transform(Location(x=state.position[0], y=-state.position[1], z=0.1), Rotation(yaw=yaw))
        actor = self.__world.spawn_actor(blueprint, transform)
        actor.set_target_velocity(Vector3D(state.velocity[0], -state.velocity[1], 0.))

        carla_agent = ip.carla.CarlaAgentWrapper(agent, actor)
        self.agents[carla_agent.agent_id] = carla_agent
示例#2
0
def randomize_attributes(bp: carla.ActorBlueprint) -> None:
    """Works in-place.

    Attributes for all blueprints: https://github.com/carla-simulator/carla/blob/7f91986f6957260b33b939e1e066a9094e272087/Docs/bp_library.md
    There are more attributes, but most of them is read-only... (number_of_wheels, age, gender, size)
    """

    # Applies to vehicles only
    if bp.has_attribute("color"):
        rgb = np.random.randint(0, 255, size=3, dtype=int)
        value = ",".join(map(str, rgb))
        bp.set_attribute("color", value)
示例#3
0
 def _add_attr_to_blueprint(self, bp: carla.ActorBlueprint):
     bp.set_attribute('image_size_x', str(self.img_width))
     bp.set_attribute('image_size_y', str(self.img_height))
     bp.set_attribute('fov', str(self.fov_horizontal))