CARLA
SimpleWaypoint.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <memory.h>
10 
11 #include "carla/client/Waypoint.h"
12 #include "carla/geom/Location.h"
13 #include "carla/geom/Transform.h"
14 #include "carla/geom/Vector3D.h"
15 #include "carla/Memory.h"
16 #include "carla/road/RoadTypes.h"
17 
18 namespace carla {
19 namespace traffic_manager {
20 
21  namespace cc = carla::client;
22  namespace cg = carla::geom;
25  enum class RoadOption : uint8_t {
26  Void = 0,
27  Left = 1,
28  Right = 2,
29  Straight = 3,
30  LaneFollow = 4,
31  ChangeLaneLeft = 5,
32  ChangeLaneRight = 6,
33  RoadEnd = 7
34  };
35 
36  /// This is a simple wrapper class on Carla's waypoint object.
37  /// The class is used to represent discrete samples of the world map.
39 
40  using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>;
41 
42  private:
43 
44  /// Pointer to Carla's waypoint object around which this class wraps around.
46  /// List of pointers to next connecting waypoints.
47  std::vector<SimpleWaypointPtr> next_waypoints;
48  /// List of pointers to previous connecting waypoints.
49  std::vector<SimpleWaypointPtr> previous_waypoints;
50  /// Pointer to left lane change waypoint.
52  /// Pointer to right lane change waypoint.
54  /// RoadOption for the actual waypoint.
56  /// Integer placing the waypoint into a geodesic grid.
57  GeoGridId geodesic_grid_id = 0;
58  // Boolean to hold if the waypoint belongs to a junction
59  bool _is_junction = false;
60 
61  public:
62 
63  SimpleWaypoint(WaypointPtr _waypoint);
64  ~SimpleWaypoint();
65 
66  /// Returns the location object for this waypoint.
67  cg::Location GetLocation() const;
68 
69  /// Returns a carla::shared_ptr to carla::waypoint.
70  WaypointPtr GetWaypoint() const;
71 
72  /// Returns the list of next waypoints.
73  std::vector<SimpleWaypointPtr> GetNextWaypoint() const;
74 
75  /// Returns the list of previous waypoints.
76  std::vector<SimpleWaypointPtr> GetPreviousWaypoint() const;
77 
78  /// Returns the vector along the waypoint's direction.
79  cg::Vector3D GetForwardVector() const;
80 
81  /// Returns the unique id for the waypoint.
82  uint64_t GetId() const;
83 
84  /// This method is used to set the next waypoints.
85  uint64_t SetNextWaypoint(const std::vector<SimpleWaypointPtr> &next_waypoints);
86 
87  /// This method is used to set the previous waypoints.
88  uint64_t SetPreviousWaypoint(const std::vector<SimpleWaypointPtr> &next_waypoints);
89 
90  /// This method is used to set the closest left waypoint for a lane change.
91  void SetLeftWaypoint(SimpleWaypointPtr &waypoint);
92 
93  /// This method is used to set the closest right waypoint for a lane change.
94  void SetRightWaypoint(SimpleWaypointPtr &waypoint);
95 
96  /// This method is used to get the closest left waypoint for a lane change.
97  SimpleWaypointPtr GetLeftWaypoint();
98 
99  /// This method is used to get the closest right waypoint for a lane change.
100  SimpleWaypointPtr GetRightWaypoint();
101 
102  /// Accessor methods for geodesic grid id.
103  void SetGeodesicGridId(GeoGridId _geodesic_grid_id);
104  GeoGridId GetGeodesicGridId();
105 
106  /// Method to retreive junction id of the waypoint.
107  GeoGridId GetJunctionId() const;
108 
109  /// Calculates the distance from the object's waypoint to the passed
110  /// location.
111  float Distance(const cg::Location &location) const;
112 
113  /// Calculates the distance the other SimpleWaypoint object.
114  float Distance(const SimpleWaypointPtr &other) const;
115 
116  /// Calculates the square of the distance to given location.
117  float DistanceSquared(const cg::Location &location) const;
118 
119  /// Calculates the square of the distance to other waypoints.
120  float DistanceSquared(const SimpleWaypointPtr &other) const;
121 
122  /// Returns true if the object's waypoint belongs to an intersection.
123  bool CheckJunction() const;
124 
125  /// This method is used to set whether the waypoint belongs to a junction.
126  void SetIsJunction(bool value);
127 
128  /// Returns true if the object's waypoint belongs to an intersection (Doesn't use OpenDrive).
129  bool CheckIntersection() const;
130 
131  /// Return transform object for the current waypoint.
132  cg::Transform GetTransform() const;
133 
134  // Accessor methods for road option.
135  void SetRoadOption(RoadOption _road_option);
136  RoadOption GetRoadOption();
137  };
138 
139 } // namespace traffic_manager
140 } // namespace carla
SimpleWaypointPtr next_right_waypoint
Pointer to right lane change waypoint.
SimpleWaypointPtr next_left_waypoint
Pointer to left lane change waypoint.
WaypointPtr waypoint
Pointer to Carla&#39;s waypoint object around which this class wraps around.
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition: Memory.h:20
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
int32_t JuncId
Definition: RoadTypes.h:17
std::vector< SimpleWaypointPtr > previous_waypoints
List of pointers to previous connecting waypoints.
This is a simple wrapper class on Carla&#39;s waypoint object.
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
carla::SharedPtr< cc::Waypoint > WaypointPtr
Definition: InMemoryMap.h:45
crd::JuncId GeoGridId
Definition: InMemoryMap.h:48
std::vector< SimpleWaypointPtr > next_waypoints
List of pointers to next connecting waypoints.