How to use the carla.Vector3D function in carla

To help you get started, we’ve selected a few carla examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github carla-simulator / scenario_runner / manual_control_json.py View on Github external
pygame.font.init()
    world = None

    try:
        client = carla.Client(args.host, args.port)
        client.set_timeout(20.0)

        display = pygame.display.set_mode(
            (args.width, args.height),
            pygame.HWSURFACE | pygame.DOUBLEBUF)

        hud = HUD(args.width, args.height)
        world = World(client.get_world(), hud, args)
        controller = KeyboardControl(world, args.autopilot)
        control = carla.VehicleControl()
        velocity = carla.Vector3D()
        angular_velocity = carla.Vector3D()

        carla_world = client.get_world()
        clock = pygame.time.Clock()

        # totalSteps = 0
        # while True:
        #     clock.tick_busy_loop(60)
        #     totalSteps += 1
        #     world.tick(clock)
        #     world.render(display)
        #     pygame.display.flip()
        #     if (totalSteps >=30*2):
        #         break
        
        time.sleep(2)
github rohjunha / language-grounded-driving / data / types.py View on Github external
transform = carla.Transform()
        transform.location.x = float(words[0])
        transform.location.y = float(words[1])
        transform.location.z = float(words[2])
        transform.rotation.pitch = float(words[3])
        transform.rotation.yaw = float(words[4])
        transform.rotation.roll = float(words[5])
        velocity = carla.Vector3D()
        velocity.x = float(words[6])
        velocity.y = float(words[7])
        velocity.z = float(words[8])
        angular_velocity = carla.Vector3D()
        angular_velocity.x = float(words[9])
        angular_velocity.y = float(words[10])
        angular_velocity.z = float(words[11])
        acceleration = carla.Vector3D()
        acceleration.x = float(words[12])
        acceleration.y = float(words[13])
        acceleration.z = float(words[14])
        return CarState(transform, velocity, angular_velocity, acceleration)
github carla-simulator / scenario_runner / srunner / metrics / tools / metrics_parser.py View on Github external
def parse_bounding_box(info):
    """
    Parses a list into a carla.BoundingBox

    Args:
        info (list): list corresponding to a row of the recorder
    """
    location = carla.Location(
        float(info[3][1:-1])/100,
        float(info[4][:-1])/100,
        float(info[5][:-1])/100,
    )

    extent = carla.Vector3D(
        float(info[7][1:-1])/100,
        float(info[8][:-1])/100,
        float(info[9][:-1])/100,
    )

    bbox = carla.BoundingBox(location, extent)

    return bbox
github flying-cabbage / drift_drl / code / environment.py View on Github external
def velocity_local2world(self, velocity_local, yaw):
		vx = velocity_local[0]
		vy = velocity_local[1]

		world_x = vx * math.cos(yaw) - vy * math.sin(yaw)
		world_y = vy * math.cos(yaw) + vx * math.sin(yaw)

		return carla.Vector3D(world_x,world_y,0)
github carla-simulator / scenario_runner / srunner / scenariomanager / scenarioatomics / atomic_criteria.py View on Github external
def rotate_point(self, point, angle):
        """
        rotate a given point by a given angle
        """
        x_ = math.cos(math.radians(angle)) * point.x - math.sin(math.radians(angle)) * point.y
        y_ = math.sin(math.radians(angle)) * point.x - math.cos(math.radians(angle)) * point.y
        return carla.Vector3D(x_, y_, point.z)
github carla-simulator / scenario_runner / srunner / scenariomanager / scenarioatomics / atomic_criteria.py View on Github external
"""
        Check if the actor is running a red light
        """
        new_status = py_trees.common.Status.RUNNING

        transform = CarlaDataProvider.get_transform(self._actor)
        location = transform.location
        if location is None:
            return new_status

        veh_extent = self._actor.bounding_box.extent.x

        tail_close_pt = self.rotate_point(carla.Vector3D(-0.8 * veh_extent, 0.0, location.z), transform.rotation.yaw)
        tail_close_pt = location + carla.Location(tail_close_pt)

        tail_far_pt = self.rotate_point(carla.Vector3D(-veh_extent - 1, 0.0, location.z), transform.rotation.yaw)
        tail_far_pt = location + carla.Location(tail_far_pt)

        for traffic_light, center, waypoints in self._list_traffic_lights:

            if self.debug:
                z = 2.1
                if traffic_light.state == carla.TrafficLightState.Red:
                    color = carla.Color(155, 0, 0)
                elif traffic_light.state == carla.TrafficLightState.Green:
                    color = carla.Color(0, 155, 0)
                else:
                    color = carla.Color(155, 155, 0)
                self._world.debug.draw_point(center + carla.Location(z=z), size=0.2, color=color, life_time=0.01)
                for wp in waypoints:
                    text = "{}.{}".format(wp.road_id, wp.lane_id)
                    self._world.debug.draw_string(
github carla-simulator / scenario_runner / srunner / metrics / tools / metrics_parser.py View on Github external
def parse_velocity(info):
    """
    Parses a list into a carla.Vector3D with the velocity

    Args:
        info (list): list corresponding to a row of the recorder
    """
    velocity = carla.Vector3D(
        float(info[3][1:-1]),
        float(info[4][:-1]),
        float(info[5][:-1])
    )

    return velocity
github carla-simulator / scenario_runner / srunner / tools / openscenario_parser.py View on Github external
if lane_pos.find('Orientation') is not None:
                orientation = rel_pos.find('Orientation')
                dyaw = math.degrees(float(orientation.attrib.get('h', 0)))
                dpitch = math.degrees(float(orientation.attrib.get('p', 0)))
                droll = math.degrees(float(orientation.attrib.get('r', 0)))

                if not OpenScenarioParser.use_carla_coordinate_system:
                    dyaw = dyaw * (-1.0)

                transform.rotation.yaw = transform.rotation.yaw + dyaw
                transform.rotation.pitch = transform.rotation.pitch + dpitch
                transform.rotation.roll = transform.rotation.roll + droll

            if offset != 0:
                forward_vector = transform.rotation.get_forward_vector()
                orthogonal_vector = carla.Vector3D(x=-forward_vector.y, y=forward_vector.x, z=forward_vector.z)
                transform.location.x = transform.location.x + offset * orthogonal_vector.x
                transform.location.y = transform.location.y + offset * orthogonal_vector.y

            return transform
        elif position.find('RoutePosition') is not None:
            raise NotImplementedError("Route positions are not yet supported")
        else:
            raise AttributeError("Unknown position")