20 namespace std_ph = std::placeholders;
23 : carma_ros2_utils::CarmaLifecycleNode(options)
36 auto error_2 = update_params<std::string>({{
"vehicle_id",
config_.
vehicle_id}}, parameters);
38 rcl_interfaces::msg::SetParametersResult result;
40 result.successful = !error && !error_2;
47 RCLCPP_INFO_STREAM(this->get_logger(),
"MobilityPathPublication trying to configure");
56 RCLCPP_INFO_STREAM(get_logger(),
"Loaded params: " <<
config_);
62 traj_sub_ = create_subscription<carma_planning_msgs::msg::TrajectoryPlan>(
"plan_trajectory", 5,
64 bsm_sub_ = create_subscription<carma_v2x_msgs::msg::BSM>(
"bsm_outbound", 1,
73 path_pub_ = create_publisher<carma_v2x_msgs::msg::MobilityPath>(
"mobility_path_msg", 5);
77 return CallbackReturn::SUCCESS;
90 std::chrono::milliseconds(path_pub_period_millisecs),
93 return CallbackReturn::SUCCESS;
99 uint64_t millisecs = get_clock()->now().nanoseconds() / 1000000;
112 map_projector_ = std::make_shared<lanelet::projection::LocalFrameProjector>(msg->data.c_str());
129 carma_v2x_msgs::msg::MobilityPath mobility_path_msg;
131 uint64_t millisecs = get_clock()->now().nanoseconds() / 1000000;
135 RCLCPP_ERROR_STREAM(this->get_logger(),
"MobilityPath cannot be populated as map projection is not available");
136 return mobility_path_msg;
140 mobility_path_msg.trajectory = mob_path_traj;
142 return mobility_path_msg;
147 carma_v2x_msgs::msg::MobilityHeader header;
150 header.sender_bsm_id = BSMHelper::BSMHelper::bsmIDtoString(
bsm_core_.id);
154 header.timestamp = time;
161 carma_v2x_msgs::msg::Trajectory traj;
163 if (traj_points.empty()) {
164 throw std::invalid_argument(
"Received an empty vector of Trajectory Plan Points");
169 if (traj_points.size() < 2){
170 RCLCPP_WARN_STREAM(this->get_logger(),
"Received Trajectory Plan is too small");
174 carma_v2x_msgs::msg::LocationECEF prev_point = ecef_location;
175 for (
size_t i=1;
i<traj_points.size();
i++){
177 carma_v2x_msgs::msg::LocationOffsetECEF offset;
179 offset.offset_x = (int16_t)(new_point.ecef_x - prev_point.ecef_x);
180 offset.offset_y = (int16_t)(new_point.ecef_y - prev_point.ecef_y);
181 offset.offset_z = (int16_t)(new_point.ecef_z - prev_point.ecef_z);
182 prev_point = new_point;
183 traj.offsets.push_back(offset);
184 if(
i >= 60 ){
break;};
188 traj.location = ecef_location;
196 throw std::invalid_argument(
"No map projector available for ecef conversion");
198 carma_v2x_msgs::msg::LocationECEF location;
200 lanelet::BasicPoint3d ecef_point =
map_projector_->projectECEF({traj_point.x, traj_point.y, 0.0}, 1);
201 location.ecef_x = ecef_point.x() * 100.0;
202 location.ecef_y = ecef_point.y() * 100.0;
203 location.ecef_z = ecef_point.z() * 100.0;
210#include "rclcpp_components/register_node_macro.hpp"
The class responsible for publishing MobilityPath messages based on the latest trajectory plan.
std::string georeference_
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.
rclcpp::TimerBase::SharedPtr path_pub_timer_
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 > ¶meters)
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::BSMCoreData bsm_core_
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.
auto to_string(const UtmZone &zone) -> std::string
Stuct containing the algorithm configuration values for mobilitypath_publisher.