当前位置: 首页>>代码示例>>Python>>正文


Python carla.Vector3D方法代码示例

本文整理汇总了Python中carla.Vector3D方法的典型用法代码示例。如果您正苦于以下问题:Python carla.Vector3D方法的具体用法?Python carla.Vector3D怎么用?Python carla.Vector3D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在carla的用法示例。


在下文中一共展示了carla.Vector3D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_trafficlight_trigger_location

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def get_trafficlight_trigger_location(traffic_light):    # pylint: disable=invalid-name
        """
        Calculates the yaw of the waypoint that represents the trigger volume of the traffic light
        """
        def rotate_point(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)

        base_transform = traffic_light.get_transform()
        base_rot = base_transform.rotation.yaw
        area_loc = base_transform.transform(traffic_light.trigger_volume.location)
        area_ext = traffic_light.trigger_volume.extent

        point = rotate_point(carla.Vector3D(0, 0, area_ext.z), base_rot)
        point_location = area_loc + carla.Location(x=point.x, y=point.y)

        return carla.Location(point_location.x, point_location.y, point_location.z) 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:24,代码来源:carla_data_provider.py

示例2: draw_radar_measurement

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def draw_radar_measurement(debug_helper: carla.DebugHelper, data: carla.RadarMeasurement, velocity_range=7.5,
                           size=0.075, life_time=0.06):
    """Code adapted from carla/PythonAPI/examples/manual_control.py:
        - White: means static points.
        - Red: indicates points moving towards the object.
        - Blue: denoted points moving away.
    """
    radar_rotation = data.transform.rotation
    for detection in data:
        azimuth = math.degrees(detection.azimuth) + radar_rotation.yaw
        altitude = math.degrees(detection.altitude) + radar_rotation.pitch

        # move to local coordinates:
        forward_vec = carla.Vector3D(x=detection.depth - 0.25)
        global_to_local(forward_vec,
                        reference=carla.Rotation(pitch=altitude, yaw=azimuth, roll=radar_rotation.roll))

        # draw:
        debug_helper.draw_point(data.transform.location + forward_vec, size=size, life_time=life_time,
                                persistent_lines=False, color=carla.Color(255, 255, 255))


# -------------------------------------------------------------------------------------------------
# -- Math
# ------------------------------------------------------------------------------------------------- 
开发者ID:tensorforce,项目名称:tensorforce,代码行数:27,代码来源:env_utils.py

示例3: _reset_world

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def _reset_world(self, soft=False):
        # init actor
        if not soft:
            spawn_point = env_utils.random_spawn_point(self.map)
        else:
            spawn_point = self.spawn_point

        if self.vehicle is None:
            blueprint = env_utils.random_blueprint(self.world, actor_filter=self.vehicle_filter)
            self.vehicle = env_utils.spawn_actor(self.world, blueprint, spawn_point)  # type: carla.Vehicle

            self._create_sensors()
            self.synchronous_context = CARLASyncContext(self.world, self.sensors, fps=self.fps)
        else:
            self.vehicle.apply_control(carla.VehicleControl())
            self.vehicle.set_velocity(carla.Vector3D(x=0.0, y=0.0, z=0.0))
            self.vehicle.set_transform(spawn_point)

        # reset reward variables
        self.collision_penalty = 0.0 
开发者ID:tensorforce,项目名称:tensorforce,代码行数:22,代码来源:carla_environment.py

示例4: __init__

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def __init__(self, location=None, rotation=None, matrix=None):
        if matrix is not None:
            self.matrix = matrix
            self.location = Location(matrix[0, 3], matrix[1, 3], matrix[2, 3])

            # Forward vector is retrieved from the matrix.
            self.forward_vector = Vector3D(self.matrix[0, 0],
                                           self.matrix[1, 0], self.matrix[2,
                                                                          0])
            pitch_r = math.asin(self.forward_vector.z)
            yaw_r = math.acos(
                np.clip(self.forward_vector.x / math.cos(pitch_r), -1, 1))
            roll_r = math.asin(matrix[2, 1] / (-1 * math.cos(pitch_r)))
            self.rotation = Rotation(math.degrees(pitch_r),
                                     math.degrees(yaw_r), math.degrees(roll_r))
        else:
            self.location, self.rotation = location, rotation
            self.matrix = Transform._create_matrix(self.location,
                                                   self.rotation)

            # Forward vector is retrieved from the matrix.
            self.forward_vector = Vector3D(self.matrix[0, 0],
                                           self.matrix[1, 0], self.matrix[2,
                                                                          0]) 
开发者ID:erdos-project,项目名称:pylot,代码行数:26,代码来源:utils.py

示例5: twist_command_updated

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def twist_command_updated(self, twist):
        """
        Set angular/linear velocity (this does not respect vehicle dynamics)
        """
        if not self.vehicle_control_override:
            angular_velocity = Vector3D()
            angular_velocity.z = math.degrees(twist.angular.z)

            rotation_matrix = transforms.carla_rotation_to_numpy_rotation_matrix(
                self.carla_actor.get_transform().rotation)
            linear_vector = numpy.array([twist.linear.x, twist.linear.y, twist.linear.z])
            rotated_linear_vector = rotation_matrix.dot(linear_vector)
            linear_velocity = Vector3D()
            linear_velocity.x = rotated_linear_vector[0]
            linear_velocity.y = -rotated_linear_vector[1]
            linear_velocity.z = rotated_linear_vector[2]

            rospy.logdebug("Set velocity linear: {}, angular: {}".format(
                linear_velocity, angular_velocity))
            self.carla_actor.set_velocity(linear_velocity)
            self.carla_actor.set_angular_velocity(angular_velocity) 
开发者ID:carla-simulator,项目名称:ros-bridge,代码行数:23,代码来源:ego_vehicle.py

示例6: run_step

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def run_step(self):
        """
        Execute on tick of the controller's control loop

        The control loop is very simplistic:
            If the actor speed is below the _target_speed, set throttle to 1.0,
            otherwise, set throttle to 0.0
        Note, that this is a longitudinal controller only.

        If _init_speed is True, the control command is post-processed to ensure that
        the initial actor velocity is maintained independent of physics.
        """

        control = self._actor.get_control()

        velocity = self._actor.get_velocity()
        current_speed = math.sqrt(velocity.x**2 + velocity.y**2)
        if current_speed < self._target_speed:
            control.throttle = 1.0
        else:
            control.throttle = 0.0

        self._actor.apply_control(control)

        if self._init_speed:
            if abs(self._target_speed - current_speed) > 3:
                yaw = self._actor.get_transform().rotation.yaw * (math.pi / 180)
                vx = math.cos(yaw) * self._target_speed
                vy = math.sin(yaw) * self._target_speed
                self._actor.set_velocity(carla.Vector3D(vx, vy, 0)) 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:32,代码来源:vehicle_longitudinal_control.py

示例7: run_step

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def run_step(self):
        """
        Execute on tick of the controller's control loop

        If _waypoints are provided, the vehicle moves towards the next waypoint
        with the given _target_speed, until reaching the final waypoint. Upon reaching
        the final waypoint, _reached_goal is set to True.

        If _waypoints is empty, the vehicle moves in its current direction with
        the given _target_speed.

        If _init_speed is True, the control command is post-processed to ensure that
        the initial actor velocity is maintained independent of physics.
        """
        self._reached_goal = False
        self._local_planner.set_speed(self._target_speed * 3.6)

        if self._waypoints_updated:
            self._waypoints_updated = False
            self._update_plan()

        control = self._local_planner.run_step(debug=False)

        # Check if the actor reached the end of the plan
        # @TODO replace access to private _waypoints_queue with public getter
        if not self._local_planner._waypoints_queue:  # pylint: disable=protected-access
            self._reached_goal = True

        self._actor.apply_control(control)

        if self._init_speed:
            current_speed = math.sqrt(self._actor.get_velocity().x**2 + self._actor.get_velocity().y**2)

            if abs(self._target_speed - current_speed) > 3:
                yaw = self._actor.get_transform().rotation.yaw * (math.pi / 180)
                vx = math.cos(yaw) * self._target_speed
                vy = math.sin(yaw) * self._target_speed
                self._actor.set_velocity(carla.Vector3D(vx, vy, 0)) 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:40,代码来源:npc_vehicle_control.py

示例8: _set_new_velocity

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def _set_new_velocity(self, next_location):
        """
        Calculate and set the new actor veloctiy given the current actor
        location and the _next_location_

        Args:
            next_location (carla.Location): Next target location of the actor

        returns:
            direction (carla.Vector3D): Normalized direction vector of the actor
        """

        # set new linear velocity
        velocity = carla.Vector3D(0, 0, 0)
        direction = next_location - CarlaDataProvider.get_location(self._actor)
        direction_norm = math.sqrt(direction.x**2 + direction.y**2)
        velocity.x = direction.x / direction_norm * self._target_speed
        velocity.y = direction.y / direction_norm * self._target_speed
        self._actor.set_velocity(velocity)

        # set new angular velocity
        current_yaw = CarlaDataProvider.get_transform(self._actor).rotation.yaw
        new_yaw = CarlaDataProvider.get_map().get_waypoint(next_location).transform.rotation.yaw
        delta_yaw = new_yaw - current_yaw

        if math.fabs(delta_yaw) > 360:
            delta_yaw = delta_yaw % 360

        if delta_yaw > 180:
            delta_yaw = delta_yaw - 360
        elif delta_yaw < -180:
            delta_yaw = delta_yaw + 360

        angular_velocity = carla.Vector3D(0, 0, 0)
        angular_velocity.z = delta_yaw / (direction_norm / self._target_speed)
        self._actor.set_angular_velocity(angular_velocity)

        return direction_norm 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:40,代码来源:simple_vehicle_control.py

示例9: rotate_point

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
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) 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:9,代码来源:atomic_criteria.py

示例10: initialise

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def initialise(self):

        super(ActorTransformSetterToOSCPosition, self).initialise()

        if self._actor.is_alive:
            self._actor.set_velocity(carla.Vector3D(0, 0, 0))
            self._actor.set_angular_velocity(carla.Vector3D(0, 0, 0)) 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:9,代码来源:atomic_behaviors.py

示例11: use_sample

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def use_sample(self, sample):
        print('Sample:', sample)

        init_conds = sample.init_conditions
        self.target_speed = init_conds.target_speed[0]

        # Ego vehicle physics parameters
        com = carla.Vector3D(
            init_conds.center_of_mass[0],
            init_conds.center_of_mass[1],
            init_conds.center_of_mass[2],
        )
        wheels = [
            carla.WheelPhysicsControl(tire_friction=init_conds.tire_friction[0])
            for _ in range(4)
        ]
        self.vehicle_mass = init_conds.mass[0]
        physics = carla.VehiclePhysicsControl(
            mass=self.vehicle_mass,
            max_rpm=init_conds.max_rpm[0],
            center_of_mass=com,
            drag_coefficient=init_conds.drag_coefficient[0],
            wheels=wheels
        )

        # PID controller parameters
        opt_dict = {
            'target_speed': self.target_speed
        }

        # Deterministic blueprint, spawnpoint.
        blueprint = self.world.world.get_blueprint_library().find('vehicle.tesla.model3')
        spawn = self.world.map.get_spawn_points()[0]

        self.world.add_vehicle(PIDAgent, control_params=opt_dict,
                               blueprint=blueprint, spawn=spawn,
                               physics=physics, has_collision_sensor=True,
                               has_lane_sensor=True, ego=True) 
开发者ID:BerkeleyLearnVerify,项目名称:VerifAI,代码行数:40,代码来源:pid_control_simulator.py

示例12: vector_norm

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def vector_norm(vec: carla.Vector3D) -> float:
    """Returns the norm/magnitude (a scalar) of the given 3D vector."""
    return math.sqrt(vec.x**2 + vec.y**2 + vec.z**2) 
开发者ID:tensorforce,项目名称:tensorforce,代码行数:5,代码来源:env_utils.py

示例13: dot_product

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def dot_product(a: carla.Vector3D, b: carla.Vector3D) -> float:
    return a.x * b.x + a.y * b.y + a.z * b.z 
开发者ID:tensorforce,项目名称:tensorforce,代码行数:4,代码来源:env_utils.py

示例14: cosine_similarity

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def cosine_similarity(a: carla.Vector3D, b: carla.Vector3D) -> float:
    """-1: opposite vectors (pointing in the opposite direction),
        0: orthogonal,
        1: exactly the same (pointing in the same direction)
    """
    return dot_product(a, b) / (vector_norm(a) * vector_norm(b)) 
开发者ID:tensorforce,项目名称:tensorforce,代码行数:8,代码来源:env_utils.py

示例15: from_angular_velocity

# 需要导入模块: import carla [as 别名]
# 或者: from carla import Vector3D [as 别名]
def from_angular_velocity(cls, angular_velocity, dt):
        """Creates a Quaternion from an angular velocity vector and the time
        delta to apply it for.

        Args:
            angular_velocity (:py:class:`.Vector3D`): The vector representing
                the angular velocity of the object in the body-frame.
            dt (float): The time delta to apply the angular velocity for.

        Returns:
            :py:class:`.Quaternion`: The quaternion representing the rotation
                undergone by the object with the given angular velocity in the
                given delta time.
        """
        angular_velocity_np = angular_velocity.as_numpy_array() * dt
        magnitude = np.linalg.norm(angular_velocity_np)

        w = np.cos(magnitude / 2.0)
        if magnitude < 1e-50:
            # To avoid instabilities and nan.
            x, y, z = 0, 0, 0
        else:
            imaginary = angular_velocity_np / magnitude * np.sin(
                magnitude / 2.0)
            x, y, z = imaginary
        return cls(w, x, y, z) 
开发者ID:erdos-project,项目名称:pylot,代码行数:28,代码来源:utils.py


注:本文中的carla.Vector3D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。