18#include <rclcpp/rclcpp.hpp>
20#include <lanelet2_extension/traffic_rules/CarmaUSTrafficRules.h>
21#include <lanelet2_core/primitives/BasicRegulatoryElements.h>
22#include <lanelet2_core/primitives/LineString.h>
24#include <carma_perception_msgs/msg/roadway_obstacle.hpp>
25#include <carma_perception_msgs/msg/roadway_obstacle_list.hpp>
26#include <carma_perception_msgs/msg/external_object.hpp>
27#include <carma_perception_msgs/msg/external_object_list.hpp>
28#include <carma_v2x_msgs/msg/spat.hpp>
31#include <lanelet2_extension/time/TimeConversion.h>
32#include "boost/date_time/posix_time/posix_time.hpp"
34#include <rosgraph_msgs/msg/clock.hpp>
35#include <gtest/gtest_prod.h>
69 void setMap(lanelet::LaneletMapPtr map,
size_t map_version = 0,
bool recompute_routing_graph =
true);
107 void setRoadwayObjects(
const std::vector<carma_perception_msgs::msg::RoadwayObstacle>& rw_objs);
116 void processSpatFromMsg(
const carma_v2x_msgs::msg::SPAT& spat_msg,
bool use_sim_time =
false,
bool is_spat_wall_time=
true);
141 boost::posix_time::ptime
min_end_time_converter_minute_of_year(boost::posix_time::ptime min_end_time,
bool moy_exists,uint32_t moy=0,
bool is_simulation =
true,
bool is_spat_wall_time=
false);
179 lanelet::CarmaTrafficSignalPtr
getTrafficSignal(
const lanelet::Id&
id)
const;
205 std::vector<lanelet::Lanelet>
nonConnectedAdjacentLeft(
const lanelet::BasicPoint2d& input_point,
const unsigned int n = 10);
210 std::pair<TrackPos, TrackPos>
routeTrackPos(
const lanelet::ConstArea& area)
const override;
216 std::vector<lanelet::ConstLanelet>
getLaneletsBetween(
double start,
double end,
bool shortest_path_only =
false,
bool bounds_inclusive =
true)
const override;
218 std::vector<lanelet::BasicPoint2d>
sampleRoutePoints(
double start_downtrack,
double end_downtrack,
double step_size)
const override;
222 lanelet::LaneletMapConstPtr
getMap()
const override;
232 lanelet::Optional<TrafficRulesConstPtr>
235 lanelet::Optional<TrafficRulesConstPtr>
238 std::vector<carma_perception_msgs::msg::RoadwayObstacle>
getRoadwayObjects()
const override;
242 lanelet::Optional<lanelet::Lanelet>
getIntersectingLanelet (
const carma_perception_msgs::msg::ExternalObject&
object)
const override;
244 lanelet::Optional<carma_perception_msgs::msg::RoadwayObstacle>
toRoadwayObstacle(
const carma_perception_msgs::msg::ExternalObject&
object)
const override;
246 lanelet::Optional<double>
distToNearestObjInLane(
const lanelet::BasicPoint2d& object_center)
const override;
248 lanelet::Optional<std::tuple<TrackPos,carma_perception_msgs::msg::RoadwayObstacle>>
nearestObjectAheadInLane(
const lanelet::BasicPoint2d& object_center)
const override;
250 lanelet::Optional<std::tuple<TrackPos,carma_perception_msgs::msg::RoadwayObstacle>>
nearestObjectBehindInLane(
const lanelet::BasicPoint2d& object_center)
const override;
256 std::vector<lanelet::ConstLanelet>
getLaneletsFromPoint(
const lanelet::BasicPoint2d&
point,
const unsigned int n = 10)
const override;
258 std::vector<lanelet::ConstLanelet>
nonConnectedAdjacentLeft(
const lanelet::BasicPoint2d& input_point,
const unsigned int n = 10)
const override;
260 std::vector<lanelet::CarmaTrafficSignalPtr>
getSignalsAlongRoute(
const lanelet::BasicPoint2d& loc)
const override;
262 std::vector<lanelet::BusStopRulePtr>
getBusStopsAlongRoute(
const lanelet::BasicPoint2d& loc)
const override;
264 boost::optional<std::pair<lanelet::ConstLanelet, lanelet::ConstLanelet>>
getEntryExitOfSignalAlongRoute(
const lanelet::CarmaTrafficSignalPtr& traffic_signal)
const override;
266 std::vector<std::shared_ptr<lanelet::AllWayStop>>
getIntersectionsAlongRoute(
const lanelet::BasicPoint2d& loc)
const override;
Class which implements the WorldModel interface. In addition this class provides write access to the ...
IndexedDistanceMap shortest_path_distance_map_
std::vector< carma_perception_msgs::msg::RoadwayObstacle > roadway_objects_
void setTrafficLightIds(uint32_t id, lanelet::Id lanelet_id)
Sets the id mapping between intersection/signal group and lanelet::Id for traffic lights in the map.
lanelet::Optional< double > distToNearestObjInLane(const lanelet::BasicPoint2d &object_center) const override
Gets Cartesian distance to the closest object on the same lane as the given point.
std::pair< TrackPos, TrackPos > routeTrackPos(const lanelet::ConstArea &area) const override
Returns a pair of TrackPos, computed in 2d, of the provided area relative to the current route....
std::vector< carma_perception_msgs::msg::RoadwayObstacle > getInLaneObjects(const lanelet::ConstLanelet &lanelet, const LaneSection §ion=LANE_AHEAD) const override
Gets all roadway objects currently in the same lane as the given lanelet.
boost::optional< lanelet::BasicPoint2d > pointFromRouteTrackPos(const TrackPos &route_pos) const override
Converts a route track position into a map frame cartesian point.
lanelet::LineString3d copyConstructLineString(const lanelet::ConstLineString3d &line) const
Helper function to perform a deep copy of a LineString and assign new ids to all the elements....
std::optional< rclcpp::Time > ros1_clock_
boost::optional< std::pair< lanelet::ConstLanelet, lanelet::ConstLanelet > > getEntryExitOfSignalAlongRoute(const lanelet::CarmaTrafficSignalPtr &traffic_signal) const override
Returns the entry and exit lanelet of the signal along the SHORTEST PATH of route....
std::vector< lanelet::Lanelet > getLaneletsFromPoint(const lanelet::BasicPoint2d &point, const unsigned int n)
(non-const version) Gets the underlying lanelet, given the cartesian point on the map
lanelet::Optional< lanelet::Lanelet > getIntersectingLanelet(const carma_perception_msgs::msg::ExternalObject &object) const override
Gets the a lanelet the object is currently on determined by its position on the semantic map....
std::vector< lanelet::BusStopRulePtr > getBusStopsAlongRoute(const lanelet::BasicPoint2d &loc) const override
Return a list of bus stop along the current route. The bus stop along a route and the next bus stop a...
lanelet::Id getTrafficSignalId(uint16_t intersection_id, uint8_t signal_id)
helper for traffic signal Id
std::string participant_type_
void setVehicleParticipationType(const std::string &participant)
Set vehicle participation type.
boost::posix_time::ptime min_end_time_converter_minute_of_year(boost::posix_time::ptime min_end_time, bool moy_exists, uint32_t moy=0, bool is_simulation=true, bool is_spat_wall_time=false)
update minimum end time to account for minute of the year
void setConfigSpeedLimit(double config_lim)
~CARMAWorldModel()=default
Destructor as required by interface.
static constexpr double GREEN_LIGHT_DURATION
std::optional< lanelet::ConstLanelet > getFirstLaneletOnShortestPath(const std::vector< lanelet::ConstLanelet > &lanelets_to_filter) const
Given the vector of lanelets, returns the lanelet that's on the shortest path. Returns earliest lanel...
lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > getNearestObjInLane(const lanelet::BasicPoint2d &object_center, const LaneSection §ion=LANE_AHEAD) const
This function is called by distanceToObjectBehindInLane or distanceToObjectAheadInLane....
lanelet::LaneletMapConstPtr getMap() const override
Get a pointer to the current map. If the underlying map has changed the pointer will also need to be ...
void setMap(lanelet::LaneletMapPtr map, size_t map_version=0, bool recompute_routing_graph=true)
Set the current map.
lanelet::LaneletSubmapConstUPtr shortest_path_view_
lanelet::CarmaTrafficSignalPtr getTrafficSignal(const lanelet::Id &id) const
helper for getting traffic signal with given lanelet::Id
LaneletRouteConstPtr getRoute() const override
Get a pointer to the current route. If the underlying route has changed the pointer will also need to...
void setRoutingGraph(LaneletRoutingGraphPtr graph)
Set the routing graph for the participant type. This function may serve as an optimization to recompu...
lanelet::Optional< TrafficRulesConstPtr > getTrafficRules() const override
Get the Traffic Rules object.
void computeDowntrackReferenceLine()
Helper function to compute the geometry of the route downtrack/crosstrack reference line This functio...
LaneletRoutingGraphPtr map_routing_graph_
std::optional< rclcpp::Time > simulation_clock_
std::unordered_map< uint32_t, lanelet::Id > traffic_light_ids_
static constexpr double YELLOW_LIGHT_DURATION
void setRouteName(const std::string &route_name)
Set the name of the route.
void setSimulationClock(const rclcpp::Time &time_now)
Set simulation clock clock (only used in simulation runs)
void setRouteEndPoint(const lanelet::BasicPoint3d &end_point)
Set endpoint of the route.
std::vector< lanelet::ConstLanelet > getLane(const lanelet::ConstLanelet &lanelet, const LaneSection §ion=LANE_AHEAD) const override
Gets the specified lane section achievable without lane change, sorted from the start,...
std::string getVehicleParticipationType()
Get vehicle participation type.
std::vector< lanelet::ConstLanelet > getLaneletsBetween(double start, double end, bool shortest_path_only=false, bool bounds_inclusive=true) const override
Returns a list of lanelets which are part of the route and whose downtrack bounds exist within the pr...
void setRos1Clock(const rclcpp::Time &time_now)
Set current Ros1 clock (only used in simulation runs)
lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > nearestObjectBehindInLane(const lanelet::BasicPoint2d &object_center) const override
Gets Downtrack distance to AND copy of the closest object BEHIND on the same lane as the given point....
double config_speed_limit_
lanelet::LaneletMapPtr getMutableMap() const
Get a mutable version of the current map.
carma_wm::SignalizedIntersectionManager sim_
TrackPos getRouteEndTrackPos() const override
Get trackpos of the end of route point relative to the route.
std::vector< lanelet::Lanelet > nonConnectedAdjacentLeft(const lanelet::BasicPoint2d &input_point, const unsigned int n=10)
(non-const version) Given the cartesian point on the map, tries to get the opposite direction lanelet...
CARMAWorldModel()=default
Constructor.
lanelet::LaneletMapUPtr shortest_path_filtered_centerline_view_
std::vector< std::shared_ptr< lanelet::AllWayStop > > getIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const override
Return a list of all way stop intersections along the current route. The tall way stop intersections ...
std::shared_ptr< lanelet::LaneletMap > semantic_map_
void setRoute(LaneletRoutePtr route)
Set the current route. This route must match the current map for this class to function properly.
LaneletRoutingGraphConstPtr getMapRoutingGraph() const override
Get a pointer to the routing graph for the current map. If the underlying map has changed the pointer...
void processSpatFromMsg(const carma_v2x_msgs::msg::SPAT &spat_msg, bool use_sim_time=false, bool is_spat_wall_time=true)
processSpatFromMsg update map's traffic light states with SPAT msg
size_t getMapVersion() const override
Returns a monotonically increasing version number which represents the version stamp of the map geome...
void setRoadwayObjects(const std::vector< carma_perception_msgs::msg::RoadwayObstacle > &rw_objs)
Update internal records of roadway objects. These objects MUST be guaranteed to be on the road.
std::vector< lanelet::LineString3d > shortest_path_centerlines_
std::vector< lanelet::CarmaTrafficSignalPtr > getSignalsAlongRoute(const lanelet::BasicPoint2d &loc) const override
Return a list of traffic lights/intersections along the current route. The traffic lights along a rou...
std::vector< carma_perception_msgs::msg::RoadwayObstacle > getRoadwayObjects() const override
Get most recent roadway objects - all objects on the road detected by perception stack.
FRIEND_TEST(CARMAWorldModelTest, getFirstLaneletOnShortestPath)
lanelet::Optional< carma_perception_msgs::msg::RoadwayObstacle > toRoadwayObstacle(const carma_perception_msgs::msg::ExternalObject &object) const override
Converts an ExternalObject in a RoadwayObstacle by mapping its position onto the semantic map....
std::vector< lanelet::BasicPoint2d > sampleRoutePoints(double start_downtrack, double end_downtrack, double step_size) const override
Samples the route centerline between the provided downtracks with the provided step size....
std::vector< lanelet::SignalizedIntersectionPtr > getSignalizedIntersectionsAlongRoute(const lanelet::BasicPoint2d &loc) const
Return a list of signalized intersections along the current route. The signalized intersections along...
static constexpr double RED_LIGHT_DURATION
lanelet::Optional< std::tuple< TrackPos, carma_perception_msgs::msg::RoadwayObstacle > > nearestObjectAheadInLane(const lanelet::BasicPoint2d &object_center) const override
Gets Downtrack distance to AND copy of the closest object AHEAD on the same lane as the given point....
std::string getRouteName() const override
Get the current route name.
O(1) distance lookup structure for quickly accessing route distance information. NOTE: This structure...
This class manages and keeps track of all signalized intersections in the map. All of the SPAT and MA...
Position in a track based coordinate system where the axis are downtrack and crosstrack....
An interface which provides read access to the semantic map and route. This class is not thread safe....
std::shared_ptr< lanelet::routing::RoutingGraph > LaneletRoutingGraphPtr
std::shared_ptr< const lanelet::routing::Route > LaneletRouteConstPtr
std::shared_ptr< const lanelet::routing::RoutingGraph > LaneletRoutingGraphConstPtr
std::shared_ptr< lanelet::routing::Route > LaneletRoutePtr