Exemplo n.º 1
0
    def __set_random_frame(self, spectator, vehicle):
        r = random.uniform(self.near_r, 5)
        theta = random.uniform(0, 2 * math.pi)
        phi = random.uniform((5 / 14) * math.pi, (1 / 6) * math.pi)
        near_frac = vehicle.bounding_box.extent.x
        ratio_f = near_frac / self.near_r
        strafe_amt = r * ratio_f - near_frac
        right_strafe = random.uniform(-strafe_amt, strafe_amt)
        above_strafe = random.uniform(-strafe_amt, strafe_amt)

        transform = carlautil.spherical_to_camera_watcher_transform(
            r, theta, phi, location=vehicle.get_location())
        transform = carlautil.strafe_transform(transform,
                                               right=right_strafe,
                                               above=above_strafe)
        spectator.set_transform(transform)
Exemplo n.º 2
0
 def demo_shift(self, spectator, vehicle):
     iterations = 100
     theta = math.pi / 2
     phi = math.pi / 4
     r = np.linspace(self.near_r, 5, iterations)
     near_frac = vehicle.bounding_box.extent.x
     ratio_f = near_frac / self.near_r
     for jdx in range(iterations):
         transform = carlautil.spherical_to_camera_watcher_transform(
                     r[jdx], theta, phi, location=vehicle.get_location())
         transform = carlautil.strafe_transform(transform,
             right=r[jdx]*ratio_f - near_frac,
             above=r[jdx]*ratio_f - near_frac)
         spectator.set_transform(transform)
         if jdx == 0 or jdx == iterations - 1:
             for _ in range(50): self.world.wait_for_tick()
         else:
             self.world.wait_for_tick()
Exemplo n.º 3
0
    def demo_all_lights(self, spectator, vehicle):
        iterations = 150
        theta = np.linspace(-math.pi / 2, math.pi / 2, iterations)
        phi = math.pi / 4
        r = (self.near_r + self.far_r) / 2.
        sun_altitude_angles = np.linspace(1, -19, iterations)
        original_lightstate = vehicle.get_light_state()
        light_types = [
            "Position", "LowBeam", "HighBeam", "Brake", "RightBlinker",
            "LeftBlinker", "Reverse", "Fog", "Interior", "Special1",
            "Special2", "All"
        ]
        for light_type in light_types:
            print(f"Demonstrating vehicle {light_type} lights.")
            vehicle.set_light_state(
                getattr(carla.VehicleLightState, light_type))
            for jdx in range(iterations):
                # set spectator orientation and position
                transform = carlautil.spherical_to_camera_watcher_transform(
                    r, theta[jdx], phi, location=vehicle.get_location())
                transform = carlautil.strafe_transform(transform,
                                                       right=0,
                                                       above=0)
                spectator.set_transform(transform)
                # set weather
                weather = self.world.get_weather()
                weather.sun_altitude_angle = sun_altitude_angles[jdx]
                self.world.set_weather(weather)
                # wait for server before continuing
                if jdx == 0 or jdx == iterations - 1:
                    for _ in range(50):
                        self.world.wait_for_tick()
                else:
                    self.world.wait_for_tick()

        vehicle.set_light_state(original_lightstate)