21#include <lanelet2_core/LaneletMap.h>
22#include <boost/date_time/posix_time/posix_time.hpp>
23#include <boost/date_time/date_defs.hpp>
24#include <boost/icl/interval_set.hpp>
25#include <unordered_set>
26#include <rclcpp/rclcpp.hpp>
27#include <lanelet2_core/geometry/Lanelet.h>
28#include <lanelet2_core/primitives/Lanelet.h>
29#include <autoware_lanelet2_msgs/msg/map_bin.h>
30#include <autoware_lanelet2_ros2_interface/utility/message_conversion.hpp>
31#include <lanelet2_extension/projection/local_frame_projector.h>
33#include <lanelet2_core/geometry/BoundingBox.h>
34#include <lanelet2_core/primitives/BoundingBox.h>
36#include <carma_planning_msgs/msg/route.hpp>
37#include <carma_v2x_msgs/msg/traffic_control_request.hpp>
38#include <carma_v2x_msgs/msg/traffic_control_bounds.hpp>
39#include <lanelet2_routing/RoutingGraph.h>
40#include <geometry_msgs/msg/pose_stamped.h>
44#include <lanelet2_extension/traffic_rules/CarmaUSTrafficRules.h>
45#include <lanelet2_core/utility/Units.h>
46#include <carma_perception_msgs/msg/check_active_geofence.hpp>
48#include <std_msgs/msg/string.hpp>
49#include <unordered_set>
50#include <visualization_msgs/msg/marker_array.hpp>
51#include <carma_v2x_msgs/msg/traffic_control_request_polygon.hpp>
53#include <std_msgs/msg/int32_multi_array.hpp>
54#include <carma_v2x_msgs/msg/map_data.hpp>
56#include <carma_v2x_msgs/msg/mobility_operation.hpp>
94 void baseMapCallback(autoware_lanelet2_msgs::msg::MapBin::UniquePtr map_msg);
109 void geofenceCallback(carma_v2x_msgs::msg::TrafficControlMessage::UniquePtr geofence_msg);
121 void addGeofence(std::shared_ptr<Geofence> gf_ptr);
144 carma_v2x_msgs::msg::TrafficControlRequestPolygon
composeTCRStatus(
const lanelet::BasicPoint3d& localPoint,
const carma_v2x_msgs::msg::TrafficControlBounds& cB,
const lanelet::projection::LocalFrameProjector& local_projector);
152 carma_v2x_msgs::msg::TrafficControlRequest
controlRequestFromRoute(
const carma_planning_msgs::msg::Route& route_msg, std::shared_ptr<j2735_v2x_msgs::msg::Id64b> req_id_for_testing = NULL);
160 lanelet::Points3d
getPointsInLocalFrame(
const carma_v2x_msgs::msg::TrafficControlMessageV01& geofence_msg);
181 void setIntersectionCoordCorrection(
const std::vector<int64_t>& intersection_ids_for_correction,
const std::vector<double>& intersection_correction);
208 void geofenceFromMsg(std::shared_ptr<Geofence> gf_ptr,
const carma_v2x_msgs::msg::TrafficControlMessageV01& geofence_msg);
216 std::vector<std::shared_ptr<Geofence>>
geofenceFromMapMsg(std::shared_ptr<Geofence> gf_ptr,
const carma_v2x_msgs::msg::MapData& map_msg);
234 carma_perception_msgs::msg::CheckActiveGeofence
checkActiveGeofenceLogic(
const geometry_msgs::msg::PoseStamped& current_pos);
241 void addRegionAccessRule(std::shared_ptr<Geofence> gf_ptr,
const carma_v2x_msgs::msg::TrafficControlMessageV01& msg_v01,
const std::vector<lanelet::Lanelet>& affected_llts)
const;
249 void addRegionMinimumGap(std::shared_ptr<Geofence> gf_ptr,
const carma_v2x_msgs::msg::TrafficControlMessageV01& msg_v01,
double min_gap,
const std::vector<lanelet::Lanelet>& affected_llts,
const std::vector<lanelet::Area>& affected_areas)
const;
255 std::vector<std::string>
participantsChecker(
const carma_v2x_msgs::msg::TrafficControlMessageV01& msg_v01)
const;
261 std::vector<std::string>
invertParticipants(
const std::vector<std::string>& input_participants)
const;
275 carma_planning_msgs::msg::Route
getRoute();
288 std::shared_ptr<Geofence>
createWorkzoneGeofence(std::unordered_map<uint8_t, std::shared_ptr<Geofence>> work_zone_geofence_cache);
302 void preprocessWorkzoneGeometry(std::unordered_map<uint8_t, std::shared_ptr<Geofence>> work_zone_geofence_cache, std::shared_ptr<std::vector<lanelet::Lanelet>> parallel_llts,
303 std::shared_ptr<std::vector<lanelet::Lanelet>> opposite_llts);
316 std::shared_ptr<Geofence>
createWorkzoneGeometry(std::unordered_map<uint8_t, std::shared_ptr<Geofence>> work_zone_geofence_cache, lanelet::Lanelet parallel_llt_front, lanelet::Lanelet parallel_llt_back,
317 std::shared_ptr<std::vector<lanelet::Lanelet>> middle_opposite_lanelets);
332 std::vector<lanelet::Lanelet>
splitLaneletWithPoint(
const std::vector<lanelet::BasicPoint2d>& input_pts,
const lanelet::Lanelet& input_llt,
double error_distance);
348 lanelet::Lanelets
splitOppositeLaneletWithPoint(std::shared_ptr<std::vector<lanelet::Lanelet>> opposite_llts,
const lanelet::BasicPoint2d& input_pt,
const lanelet::Lanelet& input_llt,
double error_distance);
363 std::vector<lanelet::Lanelet>
splitLaneletWithRatio(std::vector<double> ratios, lanelet::Lanelet input_lanelet,
double error_distance)
const;
397 void pubTCMACK(j2735_v2x_msgs::msg::Id64b tcm_req_id, uint16_t msgnum,
int ack_status,
const std::string& ack_reason);
418 bool shouldChangeControlLine(
const lanelet::ConstLaneletOrArea& el,
const lanelet::RegulatoryElementConstPtr& regem, std::shared_ptr<Geofence> gf_ptr)
const;
419 bool shouldChangeTrafficSignal(
const lanelet::ConstLaneletOrArea& el,
const lanelet::RegulatoryElementConstPtr& regem, std::shared_ptr<carma_wm::SignalizedIntersectionManager> sim)
const;
420 void addPassingControlLineFromMsg(std::shared_ptr<Geofence> gf_ptr,
const carma_v2x_msgs::msg::TrafficControlMessageV01& msg_v01,
const std::vector<lanelet::Lanelet>& affected_llts)
const;
421 void addScheduleFromMsg(std::shared_ptr<Geofence> gf_ptr,
const carma_v2x_msgs::msg::TrafficControlMessageV01& msg_v01);
422 void scheduleGeofence(std::shared_ptr<carma_wm_ctrl::Geofence> gf_ptr_list);
425 const lanelet::Point3d& left_back_pt,
const lanelet::Point3d& right_back_pt,
double increment_distance = 0.25);
426 std::unordered_set<lanelet::Lanelet>
filterSuccessorLanelets(
const std::unordered_set<lanelet::Lanelet>& possible_lanelets,
const std::unordered_set<lanelet::Lanelet>& root_lanelets);
463 std::shared_ptr<carma_wm::SignalizedIntersectionManager>
sim_;
A GeofenceScheduler is responsable for notifying the user when a geofence is active or inactive accor...
Class which provies exposes map publication and carma_wm update logic.
lanelet::LaneletMapPtr current_map_
lanelet::Lanelet createLinearInterpolatingLanelet(const lanelet::Point3d &left_front_pt, const lanelet::Point3d &right_front_pt, const lanelet::Point3d &left_back_pt, const lanelet::Point3d &right_back_pt, double increment_distance=0.25)
visualization_msgs::msg::MarkerArray tcm_marker_array_
std::vector< carma_v2x_msgs::msg::TrafficControlMessageV01 > workzone_remaining_msgs_
void removeGeofenceHelper(std::shared_ptr< Geofence > gf_ptr) const
void publishLightId()
helps to populate upcoming_intersection_ids_ from local traffic lanelet ids
carma_v2x_msgs::msg::TrafficControlRequest controlRequestFromRoute(const carma_planning_msgs::msg::Route &route_msg, std::shared_ptr< j2735_v2x_msgs::msg::Id64b > req_id_for_testing=NULL)
Pulls vehicle information from CARMA Cloud at startup by providing its selected route in a TrafficCon...
void addRegionMinimumGap(std::shared_ptr< Geofence > gf_ptr, const carma_v2x_msgs::msg::TrafficControlMessageV01 &msg_v01, double min_gap, const std::vector< lanelet::Lanelet > &affected_llts, const std::vector< lanelet::Area > &affected_areas) const
Adds Minimum Gap to the map.
std::shared_ptr< Geofence > createWorkzoneGeometry(std::unordered_map< uint8_t, std::shared_ptr< Geofence > > work_zone_geofence_cache, lanelet::Lanelet parallel_llt_front, lanelet::Lanelet parallel_llt_back, std::shared_ptr< std::vector< lanelet::Lanelet > > middle_opposite_lanelets)
Create workzone geofence. Create diagonal lanelets and a lanelet that houses opposing lane's trafficl...
lanelet::ConstLaneletOrAreas getAffectedLaneletOrAreas(const lanelet::Points3d &gf_pts)
Gets the affected lanelet or areas based on the points in local frame.
bool shouldChangeTrafficSignal(const lanelet::ConstLaneletOrArea &el, const lanelet::RegulatoryElementConstPtr ®em, std::shared_ptr< carma_wm::SignalizedIntersectionManager > sim) const
This is a helper function that returns true if signal in the lanelet should be changed according to t...
std::vector< lanelet::Lanelet > splitLaneletWithRatio(std::vector< double > ratios, lanelet::Lanelet input_lanelet, double error_distance) const
Split given lanelet with given downtrack ratios relative to the lanelet. Newly created lanelet will h...
void setErrorDistance(double error_distance)
std::function< void(const carma_perception_msgs::msg::CheckActiveGeofence &)> PublishActiveGeofCallback
PublishCtrlRequestCallback control_msg_pub_
const std::string geofence_ack_strategy_
std::vector< autoware_lanelet2_msgs::msg::MapBin > map_update_message_queue_
void baseMapCallback(autoware_lanelet2_msgs::msg::MapBin::UniquePtr map_msg)
Callback to set the base map when it has been loaded.
visualization_msgs::msg::Marker composeTCMMarkerVisualizer(const std::vector< lanelet::Point3d > &input)
composeTCMMarkerVisualizer() compose TCM Marker visualization
lanelet::Lanelets splitOppositeLaneletWithPoint(std::shared_ptr< std::vector< lanelet::Lanelet > > opposite_llts, const lanelet::BasicPoint2d &input_pt, const lanelet::Lanelet &input_llt, double error_distance)
Split given lanelet's adjacent, OPPOSITE lanelet with same proportion as the given point's downtrack ...
carma_planning_msgs::msg::Route current_route
std::vector< std::string > combineParticipantsToVehicle(const std::vector< std::string > &input_participants) const
Combines a list of the given participants into a single "vehicle" type if participants cover all poss...
double distToNearestActiveGeofence(const lanelet::BasicPoint2d &curr_pos)
Returns the route distance (downtrack or crosstrack in meters) to the nearest active geofence lanelet...
void removeGeofence(std::shared_ptr< Geofence > gf_ptr)
Removes a geofence from the current map and publishes the ROS msg.
lanelet::LaneletMapPtr base_map_
void setConfigVehicleId(const std::string &vehicle_id)
Retrieve the vehicle ID from global vehicle parameters, and set instance memeber vehicle id.
lanelet::Points3d getPointsInLocalFrame(const carma_v2x_msgs::msg::TrafficControlMessageV01 &geofence_msg)
Extract geofence points from geofence message using its given proj and datum fields.
std::unordered_map< uint8_t, std::shared_ptr< Geofence > > work_zone_geofence_cache_
bool convertLightIdToInterGroupId(unsigned &intersection_id, unsigned &group_id, const lanelet::Id &lanelet_id)
helper for generating intersection and group Id of a traffic light from lanelet id
lanelet::Velocity config_limit
lanelet::routing::RoutingGraphPtr current_routing_graph_
void addGeofenceHelper(std::shared_ptr< Geofence > gf_ptr)
std::shared_ptr< Geofence > createWorkzoneGeofence(std::unordered_map< uint8_t, std::shared_ptr< Geofence > > work_zone_geofence_cache)
Creates a single workzone geofence (in the vector) that includes all additional lanelets (housing tra...
lanelet::ConstLanelets route_path_
void setMaxLaneWidth(double max_lane_width)
Sets the max lane width in meters. Geofence points are associated to a lanelet if they are within thi...
void geofenceCallback(carma_v2x_msgs::msg::TrafficControlMessage::UniquePtr geofence_msg)
Callback to add a geofence to the map. Currently only supports version 1 TrafficControlMessage.
void addGeofence(std::shared_ptr< Geofence > gf_ptr)
Adds a geofence to the current map and publishes the ROS msg.
std::unordered_set< lanelet::Lanelet > filterSuccessorLanelets(const std::unordered_set< lanelet::Lanelet > &possible_lanelets, const std::unordered_set< lanelet::Lanelet > &root_lanelets)
void setConfigSpeedLimit(double cL)
Sets the configured speed limit.
void currentLocationCallback(geometry_msgs::msg::PoseStamped::UniquePtr current_pos)
void addPassingControlLineFromMsg(std::shared_ptr< Geofence > gf_ptr, const carma_v2x_msgs::msg::TrafficControlMessageV01 &msg_v01, const std::vector< lanelet::Lanelet > &affected_llts) const
void setVehicleParticipationType(std::string participant)
Set the Vehicle Participation Type.
carma_perception_msgs::msg::CheckActiveGeofence checkActiveGeofenceLogic(const geometry_msgs::msg::PoseStamped ¤t_pos)
Returns a message indicating whether or not the vehicle is inside of an active geofence lanelet.
std::function< void(const autoware_lanelet2_msgs::msg::MapBin &)> PublishMapUpdateCallback
void routeCallbackMessage(carma_planning_msgs::msg::Route::UniquePtr route_msg)
Calls controlRequestFromRoute() and publishes the TrafficControlRequest Message returned after the co...
std::string getVehicleParticipationType()
Get the Vehicle Participation Type object.
bool workzone_geometry_published_
std::vector< lanelet::Lanelet > splitLaneletWithPoint(const std::vector< lanelet::BasicPoint2d > &input_pts, const lanelet::Lanelet &input_llt, double error_distance)
Split given lanelet with same proportion as the given points' downtrack relative to the lanelet....
std::string base_map_georef_
carma_v2x_msgs::msg::TrafficControlRequestPolygon composeTCRStatus(const lanelet::BasicPoint3d &localPoint, const carma_v2x_msgs::msg::TrafficControlBounds &cB, const lanelet::projection::LocalFrameProjector &local_projector)
composeTCRStatus() compose TCM Request visualization on UI
WMBroadcaster(const PublishMapCallback &map_pub, const PublishMapUpdateCallback &map_update_pub, const PublishCtrlRequestCallback &control_msg_pub, const PublishActiveGeofCallback &active_pub, std::shared_ptr< carma_ros2_utils::timers::TimerFactory > timer_factory, const PublishMobilityOperationCallback &tcm_ack_pub)
Constructor.
PublishMobilityOperationCallback tcm_ack_pub_
std_msgs::msg::Int32MultiArray upcoming_intersection_ids_
void externalMapMsgCallback(carma_v2x_msgs::msg::MapData::UniquePtr map_msg)
Callback to MAP.msg which contains intersections' static info such geometry and lane ids.
std::unordered_set< lanelet::Id > active_geofence_llt_ids_
std::unordered_map< uint32_t, lanelet::Id > traffic_light_id_lookup_
std::shared_ptr< carma_wm::SignalizedIntersectionManager > sim_
std::vector< std::string > participantsChecker(const carma_v2x_msgs::msg::TrafficControlMessageV01 &msg_v01) const
Generates participants list.
PublishMapCallback map_pub_
void addRegulatoryComponent(std::shared_ptr< Geofence > gf_ptr) const
std::vector< std::shared_ptr< Geofence > > geofenceFromMapMsg(std::shared_ptr< Geofence > gf_ptr, const carma_v2x_msgs::msg::MapData &map_msg)
Fills geofence object from MAP Data ROS Msg which contains intersections' static data such as geometr...
void scheduleGeofence(std::shared_ptr< carma_wm_ctrl::Geofence > gf_ptr_list)
size_t current_map_version_
carma_v2x_msgs::msg::TrafficControlRequestPolygon tcr_polygon_
GeofenceScheduler scheduler_
PublishActiveGeofCallback active_pub_
void addScheduleFromMsg(std::shared_ptr< Geofence > gf_ptr, const carma_v2x_msgs::msg::TrafficControlMessageV01 &msg_v01)
Populates the schedules member of the geofence object from given TrafficControlMessageV01 message.
std::function< void(const carma_v2x_msgs::msg::MobilityOperation &)> PublishMobilityOperationCallback
std::vector< std::string > invertParticipants(const std::vector< std::string > &input_participants) const
Generates inverse participants list of the given participants.
void pubTCMACK(j2735_v2x_msgs::msg::Id64b tcm_req_id, uint16_t msgnum, int ack_status, const std::string &ack_reason)
Construct TCM acknowledgement object and populate it with params. Publish the object for a configured...
void setIntersectionCoordCorrection(const std::vector< int64_t > &intersection_ids_for_correction, const std::vector< double > &intersection_correction)
Sets the coordinate correction for intersection.
std::function< void(const autoware_lanelet2_msgs::msg::MapBin &)> PublishMapCallback
void updateUpcomingSGIntersectionIds()
populate upcoming_intersection_ids_ from local traffic lanelet ids
std::vector< lanelet::LaneletMapPtr > cached_maps_
void preprocessWorkzoneGeometry(std::unordered_map< uint8_t, std::shared_ptr< Geofence > > work_zone_geofence_cache, std::shared_ptr< std::vector< lanelet::Lanelet > > parallel_llts, std::shared_ptr< std::vector< lanelet::Lanelet > > opposite_llts)
Preprocess for workzone area. Parallel_llts will have front_parallel and back_parallel lanelets that ...
carma_planning_msgs::msg::Route getRoute()
Returns the most recently recieved route message.
uint32_t generate32BitId(const std::string &label)
helper for generating 32bit traffic light Id from TCM label field consisting workzone intersection/si...
std::unordered_set< std::string > generated_geofence_reqids_
void addRegionAccessRule(std::shared_ptr< Geofence > gf_ptr, const carma_v2x_msgs::msg::TrafficControlMessageV01 &msg_v01, const std::vector< lanelet::Lanelet > &affected_llts) const
Adds RegionAccessRule to the map.
void setConfigACKPubTimes(int ack_pub_times)
Sets the TCM Acknowledgement publish times.
PublishMapUpdateCallback map_update_pub_
lanelet::LineString3d createLinearInterpolatingLinestring(const lanelet::Point3d &front_pt, const lanelet::Point3d &back_pt, double increment_distance=0.25)
bool shouldChangeControlLine(const lanelet::ConstLaneletOrArea &el, const lanelet::RegulatoryElementConstPtr ®em, std::shared_ptr< Geofence > gf_ptr) const
This is a helper function that returns true if the provided regem is marked to be changed by the geof...
std::unordered_set< std::string > checked_geofence_ids_
void geofenceFromMsg(std::shared_ptr< Geofence > gf_ptr, const carma_v2x_msgs::msg::TrafficControlMessageV01 &geofence_msg)
Fills geofence object from TrafficControlMessageV01 ROS Msg.
void addBackRegulatoryComponent(std::shared_ptr< Geofence > gf_ptr) const
std::function< void(const carma_v2x_msgs::msg::TrafficControlRequest &)> PublishCtrlRequestCallback
void geoReferenceCallback(std_msgs::msg::String::UniquePtr geo_ref)
Callback to set the base map georeference (proj string)
const int WORKZONE_TCM_REQUIRED_SIZE
static const uint8_t OPEN
static const uint8_t TAPERRIGHT
static const uint8_t OPENLEFT
static const uint8_t CLOSED
static const uint8_t TAPERLEFT
static const uint8_t OPENRIGHT
static const uint8_t REVERSE