Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
WorldModel.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <exception>
20#include <memory>
21#include <tuple>
22#include <optional>
23#include <lanelet2_core/LaneletMap.h>
24#include <lanelet2_core/primitives/Area.h>
25#include <lanelet2_core/primitives/Lanelet.h>
26#include <lanelet2_core/primitives/Point.h>
27#include <lanelet2_routing/Route.h>
28#include <lanelet2_routing/RoutingGraph.h>
29#include <lanelet2_traffic_rules/TrafficRules.h>
30#include <lanelet2_core/utility/Optional.h>
31#include <carma_perception_msgs/msg/roadway_obstacle.hpp>
32#include <carma_perception_msgs/msg/roadway_obstacle_list.hpp>
33#include <carma_perception_msgs/msg/external_object.hpp>
34#include <carma_perception_msgs/msg/external_object_list.hpp>
35#include <lanelet2_extension/regulatory_elements/CarmaTrafficSignal.h>
36#include <lanelet2_extension/regulatory_elements/SignalizedIntersection.h>
37#include <lanelet2_core/primitives/BasicRegulatoryElements.h>
38#include "carma_wm/TrackPos.hpp"
39#include <lanelet2_extension/regulatory_elements/BusStopRule.h>
40
41
42
43namespace carma_wm
44{
45
46// Helpful using declarations which are not defined by lanelet::routing module
47using LaneletRoutePtr = std::shared_ptr<lanelet::routing::Route>;
48using LaneletRouteConstPtr = std::shared_ptr<const lanelet::routing::Route>;
49using LaneletRouteUPtr = std::unique_ptr<lanelet::routing::Route>;
50using LaneletRouteUConstPtr = std::unique_ptr<const lanelet::routing::Route>;
51
52using LaneletRoutingGraphPtr = std::shared_ptr<lanelet::routing::RoutingGraph>;
53using LaneletRoutingGraphConstPtr = std::shared_ptr<const lanelet::routing::RoutingGraph>;
54using LaneletRoutingGraphUPtr = std::unique_ptr<lanelet::routing::RoutingGraph>;
55using LaneletRoutingGraphConstUPtr = std::unique_ptr<const lanelet::routing::RoutingGraph>;
56
57using TrafficRulesConstPtr = std::shared_ptr<const lanelet::traffic_rules::TrafficRules>;
58using TrafficRulesUConstPtr = std::unique_ptr<const lanelet::traffic_rules::TrafficRules>;
59
60// Helpful enums for dividing lane into sections of interest.
62{
66};
67
75{
76 public:
81 virtual ~WorldModel() {};
82
97 virtual std::pair<TrackPos, TrackPos> routeTrackPos(const lanelet::ConstArea& area) const = 0;
98
99
112 virtual TrackPos routeTrackPos(const lanelet::ConstLanelet& lanelet) const = 0;
113
125 virtual TrackPos routeTrackPos(const lanelet::BasicPoint2d& point) const = 0;
126
142 virtual std::vector<lanelet::ConstLanelet> getLaneletsBetween(double start, double end, bool shortest_path_only = false,
143 bool bounds_inclusive = true) const = 0;
144
165 virtual std::vector<lanelet::BasicPoint2d> sampleRoutePoints(double start_downtrack, double end_downtrack,
166 double step_size) const = 0;
167
168
180 virtual boost::optional<lanelet::BasicPoint2d> pointFromRouteTrackPos(const TrackPos& route_pos) const = 0;
181
187 virtual lanelet::LaneletMapConstPtr getMap() const = 0;
188
195 virtual LaneletRouteConstPtr getRoute() const = 0;
196
201 virtual std::string getRouteName() const = 0;
202
207 virtual TrackPos getRouteEndTrackPos() const = 0;
208
216
221 virtual std::vector<carma_perception_msgs::msg::RoadwayObstacle> getRoadwayObjects() const = 0;
222
231 virtual lanelet::Optional<TrafficRulesConstPtr>
232 getTrafficRules(const std::string& participant) const = 0;
233
239 virtual lanelet::Optional<TrafficRulesConstPtr>
240 getTrafficRules() const = 0;
241
253 virtual lanelet::Optional<carma_perception_msgs::msg::RoadwayObstacle>
254 toRoadwayObstacle(const carma_perception_msgs::msg::ExternalObject& object) const = 0;
255
268 virtual lanelet::Optional<lanelet::Lanelet> getIntersectingLanelet(const carma_perception_msgs::msg::ExternalObject& object) const = 0;
269
280 virtual std::vector<lanelet::BusStopRulePtr> getBusStopsAlongRoute(const lanelet::BasicPoint2d& loc) const = 0;
281
295 virtual std::vector<carma_perception_msgs::msg::RoadwayObstacle> getInLaneObjects(const lanelet::ConstLanelet& lanelet,
296 const LaneSection& section = LANE_AHEAD) const = 0;
297
309 virtual lanelet::Optional<double> distToNearestObjInLane(const lanelet::BasicPoint2d& object_center) const = 0;
310
325 virtual lanelet::Optional<std::tuple<TrackPos, carma_perception_msgs::msg::RoadwayObstacle>>
326 nearestObjectAheadInLane(const lanelet::BasicPoint2d& object_center) const = 0;
327
342 virtual lanelet::Optional<std::tuple<TrackPos, carma_perception_msgs::msg::RoadwayObstacle>>
343 nearestObjectBehindInLane(const lanelet::BasicPoint2d& object_center) const = 0;
344
357 virtual std::vector<lanelet::ConstLanelet> getLane(const lanelet::ConstLanelet& lanelet,
358 const LaneSection& section = LANE_AHEAD) const = 0;
359
366 virtual size_t getMapVersion() const = 0;
367
377 virtual std::vector<lanelet::ConstLanelet> getLaneletsFromPoint(const lanelet::BasicPoint2d& point, const unsigned int n = 10) const = 0;
378
389 virtual std::vector<lanelet::CarmaTrafficSignalPtr> getSignalsAlongRoute(const lanelet::BasicPoint2d& loc) const = 0;
390
400 virtual boost::optional<std::pair<lanelet::ConstLanelet, lanelet::ConstLanelet>> getEntryExitOfSignalAlongRoute(const lanelet::CarmaTrafficSignalPtr& traffic_signal) const = 0;
401
412 virtual std::vector<std::shared_ptr<lanelet::AllWayStop>> getIntersectionsAlongRoute(const lanelet::BasicPoint2d& loc) const = 0;
413
424 virtual std::vector<lanelet::SignalizedIntersectionPtr> getSignalizedIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const = 0;
425
440 virtual std::vector<lanelet::ConstLanelet> nonConnectedAdjacentLeft(const lanelet::BasicPoint2d& input_point, const unsigned int n = 10) const = 0;
441
450 virtual std::optional<lanelet::ConstLanelet> getFirstLaneletOnShortestPath(const std::vector<lanelet::ConstLanelet>& lanelets_to_filter) const = 0;
451
452};
453// Helpful using declarations for carma_wm classes
454using WorldModelConstPtr = std::shared_ptr<const WorldModel>;
455} // namespace carma_wm
Position in a track based coordinate system where the axis are downtrack and crosstrack....
Definition: TrackPos.hpp:35
An interface which provides read access to the semantic map and route. This class is not thread safe....
Definition: WorldModel.hpp:75
virtual boost::optional< std::pair< lanelet::ConstLanelet, lanelet::ConstLanelet > > getEntryExitOfSignalAlongRoute(const lanelet::CarmaTrafficSignalPtr &traffic_signal) const =0
Returns the entry and exit lanelet of the signal along the SHORTEST PATH of route....
virtual std::vector< lanelet::CarmaTrafficSignalPtr > getSignalsAlongRoute(const lanelet::BasicPoint2d &loc) const =0
Return a list of traffic lights/intersections along the current route. The traffic lights along a rou...
virtual std::vector< lanelet::BasicPoint2d > sampleRoutePoints(double start_downtrack, double end_downtrack, double step_size) const =0
Samples the route centerline between the provided downtracks with the provided step size....
virtual lanelet::Optional< lanelet::Lanelet > getIntersectingLanelet(const carma_perception_msgs::msg::ExternalObject &object) const =0
Gets the a lanelet the object is currently on determined by its position on the semantic map....
virtual TrackPos routeTrackPos(const lanelet::BasicPoint2d &point) const =0
Returns the TrackPos, computed in 2d, of the provided point relative to the current route.
virtual std::vector< lanelet::SignalizedIntersectionPtr > getSignalizedIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const =0
Return a list of signalized intersections along the current route. The signalized intersections along...
virtual std::vector< lanelet::ConstLanelet > nonConnectedAdjacentLeft(const lanelet::BasicPoint2d &input_point, const unsigned int n=10) const =0
Given the cartesian point on the map, tries to get the opposite direction lanelet on the left This fu...
virtual TrackPos getRouteEndTrackPos() const =0
Get trackpos of the end of route point relative to the route.
virtual lanelet::LaneletMapConstPtr getMap() const =0
Get a pointer to the current map. If the underlying map has changed the pointer will also need to be ...
virtual LaneletRoutingGraphConstPtr getMapRoutingGraph() const =0
Get a pointer to the routing graph for the current map. If the underlying map has changed the pointer...
virtual TrackPos routeTrackPos(const lanelet::ConstLanelet &lanelet) const =0
Returns the TrackPos, computed in 2d, of the provided lanelet relative to the current route....
virtual std::vector< lanelet::ConstLanelet > getLane(const lanelet::ConstLanelet &lanelet, const LaneSection &section=LANE_AHEAD) const =0
Gets the specified lane section achievable without lane change, sorted from the start,...
virtual size_t getMapVersion() const =0
Returns a monotonically increasing version number which represents the version stamp of the map geome...
virtual lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > nearestObjectBehindInLane(const lanelet::BasicPoint2d &object_center) const =0
Gets Downtrack distance to AND copy of the closest object BEHIND on the same lane as the given point....
virtual std::optional< lanelet::ConstLanelet > getFirstLaneletOnShortestPath(const std::vector< lanelet::ConstLanelet > &lanelets_to_filter) const =0
Given the vector of lanelets, returns the lanelet that's on the shortest path. Returns earliest lanel...
virtual lanelet::Optional< TrafficRulesConstPtr > getTrafficRules() const =0
Get the Traffic Rules object.
virtual std::vector< carma_perception_msgs::msg::RoadwayObstacle > getInLaneObjects(const lanelet::ConstLanelet &lanelet, const LaneSection &section=LANE_AHEAD) const =0
Gets all roadway objects currently in the same lane as the given lanelet.
virtual lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > nearestObjectAheadInLane(const lanelet::BasicPoint2d &object_center) const =0
Gets Downtrack distance to AND copy of the closest object AHEAD on the same lane as the given point....
virtual std::pair< TrackPos, TrackPos > routeTrackPos(const lanelet::ConstArea &area) const =0
Returns a pair of TrackPos, computed in 2d, of the provided area relative to the current route....
virtual ~WorldModel()
Virtual destructor to ensure delete safety for pointers to implementing classes.
Definition: WorldModel.hpp:81
virtual lanelet::Optional< carma_perception_msgs::msg::RoadwayObstacle > toRoadwayObstacle(const carma_perception_msgs::msg::ExternalObject &object) const =0
Converts an ExternalObject in a RoadwayObstacle by mapping its position onto the semantic map....
virtual boost::optional< lanelet::BasicPoint2d > pointFromRouteTrackPos(const TrackPos &route_pos) const =0
Converts a route track position into a map frame cartesian point.
virtual std::vector< carma_perception_msgs::msg::RoadwayObstacle > getRoadwayObjects() const =0
Get most recent roadway objects - all objects on the road detected by perception stack.
virtual std::vector< lanelet::ConstLanelet > getLaneletsBetween(double start, double end, bool shortest_path_only=false, bool bounds_inclusive=true) const =0
Returns a list of lanelets which are part of the route and whose downtrack bounds exist within the pr...
virtual lanelet::Optional< double > distToNearestObjInLane(const lanelet::BasicPoint2d &object_center) const =0
Gets Cartesian distance to the closest object on the same lane as the given point.
virtual std::vector< lanelet::ConstLanelet > getLaneletsFromPoint(const lanelet::BasicPoint2d &point, const unsigned int n=10) const =0
Gets the underlying lanelet, given the cartesian point on the map.
virtual std::string getRouteName() const =0
Get the current route name.
virtual std::vector< std::shared_ptr< lanelet::AllWayStop > > getIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const =0
Return a list of all way stop intersections along the current route. The tall way stop intersections ...
virtual lanelet::Optional< TrafficRulesConstPtr > getTrafficRules(const std::string &participant) const =0
Get a pointer to the traffic rules object used internally by the world model and considered the carma...
virtual std::vector< lanelet::BusStopRulePtr > getBusStopsAlongRoute(const lanelet::BasicPoint2d &loc) const =0
Return a list of bus stop along the current route. The bus stop along a route and the next bus stop a...
virtual LaneletRouteConstPtr getRoute() const =0
Get a pointer to the current route. If the underlying route has changed the pointer will also need to...
std::unique_ptr< const lanelet::routing::RoutingGraph > LaneletRoutingGraphConstUPtr
Definition: WorldModel.hpp:55
std::shared_ptr< lanelet::routing::RoutingGraph > LaneletRoutingGraphPtr
Definition: WorldModel.hpp:52
std::shared_ptr< const WorldModel > WorldModelConstPtr
Definition: WorldModel.hpp:454
std::shared_ptr< const lanelet::traffic_rules::TrafficRules > TrafficRulesConstPtr
Definition: WorldModel.hpp:57
std::shared_ptr< const lanelet::routing::Route > LaneletRouteConstPtr
Definition: WorldModel.hpp:48
std::unique_ptr< const lanelet::traffic_rules::TrafficRules > TrafficRulesUConstPtr
Definition: WorldModel.hpp:58
std::unique_ptr< lanelet::routing::Route > LaneletRouteUPtr
Definition: WorldModel.hpp:49
std::unique_ptr< lanelet::routing::RoutingGraph > LaneletRoutingGraphUPtr
Definition: WorldModel.hpp:54
std::shared_ptr< const lanelet::routing::RoutingGraph > LaneletRoutingGraphConstPtr
Definition: WorldModel.hpp:53
std::shared_ptr< lanelet::routing::Route > LaneletRoutePtr
Definition: WorldModel.hpp:47
std::unique_ptr< const lanelet::routing::Route > LaneletRouteUConstPtr
Definition: WorldModel.hpp:50