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.
mobilitypath_publisher.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17#pragma once
18
19#include <rclcpp/rclcpp.hpp>
20#include <functional>
21#include <boost/uuid/uuid_generators.hpp>
22#include <boost/uuid/uuid_io.hpp>
23#include <boost/shared_ptr.hpp>
24#include <lanelet2_extension/projection/local_frame_projector.h>
25#include <bsm_helper/bsm_helper.h>
26#include <std_msgs/msg/string.hpp>
27#include <carma_planning_msgs/msg/trajectory_plan.hpp>
28#include <carma_planning_msgs/msg/guidance_state.hpp>
29#include <carma_v2x_msgs/msg/mobility_path.hpp>
30#include <carma_v2x_msgs/msg/bsm.hpp>
31
32#include <carma_ros2_utils/carma_lifecycle_node.hpp>
34
36{
37
44 class MobilityPathPublication : public carma_ros2_utils::CarmaLifecycleNode
45 {
46
47 private:
48 // Subscribers
49 carma_ros2_utils::SubPtr<carma_planning_msgs::msg::TrajectoryPlan> traj_sub_;
50 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::BSM> bsm_sub_;
51 carma_ros2_utils::SubPtr<std_msgs::msg::String> georeference_sub_;
52 carma_ros2_utils::SubPtr<carma_planning_msgs::msg::GuidanceState> guidance_state_sub_;
53
54 bool guidance_engaged_ = false;
55
56 // Publishers
57 carma_ros2_utils::PubPtr<carma_v2x_msgs::msg::MobilityPath> path_pub_;
58
59 // Timer for publishing MobilityPath message
60 rclcpp::TimerBase::SharedPtr path_pub_timer_;
61
62 // Node configuration
64
65 // The most recently published trajectory plan
66 carma_planning_msgs::msg::TrajectoryPlan latest_trajectory_;
67
68 // The MobilityPath message generated from the most recently published trajectory plan
69 carma_v2x_msgs::msg::MobilityPath latest_mobility_path_;
70
71 // The BSMCoreData from the most recently published BSM message
72 carma_v2x_msgs::msg::BSMCoreData bsm_core_;
73
74 // Map projection string, which defines the lat/lon -> map conversion
75 std::string georeference_{""};
76 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_;
77
78 // Recipient's static ID (Empty string indicates a broadcast message)
79 std::string recipient_id = "";
80
81 // Sender's dynamic ID which is its BSM id in hex string
82 std::string sender_bsm_id = "FFFF";
83
87 bool spin_callback();
88
94 void trajectory_cb(const carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg);
95
100 void bsm_cb(const carma_v2x_msgs::msg::BSM::UniquePtr msg);
101
106 void guidance_state_cb(const carma_planning_msgs::msg::GuidanceState::UniquePtr msg);
107
113 carma_v2x_msgs::msg::MobilityHeader compose_mobility_header(uint64_t time);
114
120 carma_v2x_msgs::msg::Trajectory trajectory_plan_to_trajectory(const std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint>& traj_points) const;
121
127 carma_v2x_msgs::msg::LocationECEF trajectory_point_to_ECEF(const carma_planning_msgs::msg::TrajectoryPlanPoint& traj_point) const;
128
129 public:
133 explicit MobilityPathPublication(const rclcpp::NodeOptions &);
134
138 rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters);
139
145 carma_v2x_msgs::msg::MobilityPath mobility_path_message_generator(const carma_planning_msgs::msg::TrajectoryPlan& trajectory_plan);
146
151 void georeference_cb(const std_msgs::msg::String::UniquePtr msg);
152
154 // Overrides
156 carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &);
157 carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &);
158 };
159
160} // mobilitypath_publisher
The class responsible for publishing MobilityPath messages based on the latest trajectory plan.
void georeference_cb(const std_msgs::msg::String::UniquePtr msg)
Callback for map projection string to define lat/lon -> map conversion.
void guidance_state_cb(const carma_planning_msgs::msg::GuidanceState::UniquePtr msg)
Callback for the Guidance State.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > guidance_state_sub_
void trajectory_cb(const carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
Callback for the trajectory plan subscriber, which stores the latest trajectory plan locally and stor...
carma_ros2_utils::SubPtr< std_msgs::msg::String > georeference_sub_
carma_v2x_msgs::msg::MobilityHeader compose_mobility_header(uint64_t time)
Generates a MobilityHeader to be used for a published MobilityPath message.
carma_planning_msgs::msg::TrajectoryPlan latest_trajectory_
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > traj_sub_
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Function callback for dynamic parameter updates.
carma_v2x_msgs::msg::LocationECEF trajectory_point_to_ECEF(const carma_planning_msgs::msg::TrajectoryPlanPoint &traj_point) const
Converts Trajectory Plan Point to ECEF (accepts meters and outputs in cm)
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
carma_v2x_msgs::msg::MobilityPath latest_mobility_path_
carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &)
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::BSM > bsm_sub_
carma_ros2_utils::PubPtr< carma_v2x_msgs::msg::MobilityPath > path_pub_
MobilityPathPublication(const rclcpp::NodeOptions &)
MobilityPathPublication constructor.
bool spin_callback()
Spin callback, which will be called frequently based on the configured spin rate.
void bsm_cb(const carma_v2x_msgs::msg::BSM::UniquePtr msg)
Callback for the BSM subscriber, which stores the BSM's BSMCoreData locally.
carma_v2x_msgs::msg::MobilityPath mobility_path_message_generator(const carma_planning_msgs::msg::TrajectoryPlan &trajectory_plan)
Generates a MobilityPath message from a TrajectoryPlan.
carma_v2x_msgs::msg::Trajectory trajectory_plan_to_trajectory(const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &traj_points) const
Converts a Trajectory Plan to a (Mobility) Trajectory.
Stuct containing the algorithm configuration values for mobilitypath_publisher.