CARLA
Loading...
Searching...
No Matches
Misc.h
Go to the documentation of this file.
1// Copyright (c) 2018-2020 CVC.
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "carla/Memory.h"
9
10#include <array>
11#include <optional>
12#include <utility>
13#include <vector>
14
15namespace carla {
16
17namespace client {
18 class Actor;
19 class TrafficLight;
20 class Waypoint;
21 class World;
22} // namespace client
23
24namespace geom {
25 struct Location;
26 class Transform;
27} // namespace geom
28
29namespace agents {
30namespace navigation {
31
32 /// Compute speed of an actor in km/h.
34
35 /// Compute the world-space trigger location of a traffic light, mirroring
36 /// the helper in `agents.tools.misc.get_trafficlight_trigger_location`.
39
40 /// Returns true when @a target is within @a max_distance of @a reference.
41 /// When @a angle_interval is provided, the angle (in degrees) between the
42 /// reference's forward vector and the vector reference -> target must lie
43 /// in the open interval (min, max).
45 const geom::Transform &target,
46 const geom::Transform &reference,
47 float max_distance,
48 std::optional<std::pair<float, float>> angle_interval = std::nullopt);
49
50 /// Returns the (distance, angle in degrees) from @a current to @a target
51 /// relative to a forward orientation @a orientation_deg in degrees.
52 std::pair<float, float> ComputeMagnitudeAngle(
53 const geom::Location &target,
54 const geom::Location &current,
55 float orientation_deg);
56
57 /// 2-D distance between a waypoint and a vehicle transform.
58 float DistanceVehicle(
60 const geom::Transform &vehicle_transform);
61
62 /// Unit vector going from @a a to @a b, including the z component.
63 std::array<float, 3> UnitVector(
64 const geom::Location &a,
65 const geom::Location &b);
66
67 /// Euclidean distance between two locations (matches numpy's regularised
68 /// version that adds an epsilon to avoid 0).
69 float ComputeDistance(
70 const geom::Location &a,
71 const geom::Location &b);
72
73 /// Clamp @a v at zero. Inline because it's tiny.
74 inline float Positive(float v) { return v > 0.0f ? v : 0.0f; }
75
76 /// Draw the supplied waypoints in the world for a fixed lifetime.
77 void DrawWaypoints(
79 const std::vector<SharedPtr<client::Waypoint>> &waypoints,
80 float z = 0.5f);
81
82} // namespace navigation
83} // namespace agents
84} // namespace carla
float z
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
bool IsWithinDistance(const geom::Transform &target, const geom::Transform &reference, float max_distance, std::optional< std::pair< float, float > > angle_interval)
Returns true when target is within max_distance of reference.
Definition Misc.cpp:78
float ComputeDistance(const geom::Location &a, const geom::Location &b)
Euclidean distance between two locations (matches numpy's regularised version that adds an epsilon to...
Definition Misc.cpp:150
void DrawWaypoints(SharedPtr< client::World > world, const std::vector< SharedPtr< client::Waypoint > > &waypoints, float z)
Draw the supplied waypoints in the world for a fixed lifetime.
Definition Misc.cpp:159
geom::Location GetTrafficLightTriggerLocation(SharedPtr< client::TrafficLight > traffic_light)
Compute the world-space trigger location of a traffic light, mirroring the helper in agents....
Definition Misc.cpp:45
float Positive(float v)
Clamp v at zero. Inline because it's tiny.
Definition Misc.h:74
float GetSpeed(SharedPtr< client::Actor > actor)
Compute speed of an actor in km/h.
Definition Misc.cpp:37
std::pair< float, float > ComputeMagnitudeAngle(const geom::Location &target, const geom::Location &current, float orientation_deg)
Returns the (distance, angle in degrees) from current to target relative to a forward orientation ori...
Definition Misc.cpp:109
float DistanceVehicle(SharedPtr< client::Waypoint > waypoint, const geom::Transform &vehicle_transform)
2-D distance between a waypoint and a vehicle transform.
Definition Misc.cpp:130
std::array< float, 3 > UnitVector(const geom::Location &a, const geom::Location &b)
Unit vector going from a to b, including the z component.
Definition Misc.cpp:139
carla::SharedPtr< cc::Actor > Actor
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15