From 59ecab62bdad26dae642931f7a51bafbcb37f14f Mon Sep 17 00:00:00 2001 From: Yu Asabe Date: Thu, 19 May 2022 19:59:42 +0900 Subject: [PATCH 1/2] Run publishCpmSenderObject in indicate function --- src/cpm_application.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cpm_application.cpp b/src/cpm_application.cpp index 893a601..a906ba9 100644 --- a/src/cpm_application.cpp +++ b/src/cpm_application.cpp @@ -131,6 +131,11 @@ namespace v2x { // RCLCPP_INFO(node_->get_logger(), "[CpmApplication::indicate] heading: %d", heading); // RCLCPP_INFO(node_->get_logger(), "[CpmApplication::indicate] orientation: %f", orientation); + + // Publish CPM Sender info to /v2x/cpm/sender through V2XNode function + node_->publishCpmSenderObject(x_mgrs, y_mgrs, orientation); + + // Get PerceivedObjects receivedObjectsStack.clear(); @@ -452,6 +457,7 @@ namespace v2x { StationDataContainer_t *&sdc = cpm.cpmParameters.stationDataContainer; sdc = vanetza::asn1::allocate(); sdc->present = StationDataContainer_PR_originatingVehicleContainer; + OriginatingVehicleContainer_t &ovc = sdc->choice.originatingVehicleContainer; ovc.speed.speedValue = 0; ovc.speed.speedConfidence = 1; From 2e78973ef888b4ff39f4572dc4f42ef15b37f199 Mon Sep 17 00:00:00 2001 From: Yu Asabe Date: Thu, 19 May 2022 20:00:02 +0900 Subject: [PATCH 2/2] Create new publisher and function to publish to topic --- include/autoware_v2x/v2x_node.hpp | 2 ++ src/v2x_node.cpp | 45 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/autoware_v2x/v2x_node.hpp b/include/autoware_v2x/v2x_node.hpp index 4c5440a..4d503d0 100644 --- a/include/autoware_v2x/v2x_node.hpp +++ b/include/autoware_v2x/v2x_node.hpp @@ -23,6 +23,7 @@ namespace v2x explicit V2XNode(const rclcpp::NodeOptions &node_options); V2XApp *app; void publishObjects(std::vector *); + void publishCpmSenderObject(double, double, double); private: void objectsCallback(const autoware_auto_perception_msgs::msg::PredictedObjects::ConstSharedPtr msg); @@ -31,6 +32,7 @@ namespace v2x rclcpp::Subscription::SharedPtr subscription_; rclcpp::Subscription::SharedPtr subscription_pos_; rclcpp::Publisher::SharedPtr publisher_; + rclcpp::Publisher::SharedPtr publisher_v2x_cpm_sender_; double pos_lat_; double pos_lon_; diff --git a/src/v2x_node.cpp b/src/v2x_node.cpp index c4644fd..7b17740 100644 --- a/src/v2x_node.cpp +++ b/src/v2x_node.cpp @@ -17,6 +17,8 @@ #include #include +#include "tf2/LinearMath/Quaternion.h" + namespace gn = vanetza::geonet; using namespace vanetza; @@ -32,6 +34,7 @@ namespace v2x subscription_pos_ = this->create_subscription("/tf", 10, std::bind(&V2XNode::tfCallback, this, _1)); publisher_ = create_publisher("/v2x/cpm/objects", rclcpp::QoS{10}); + publisher_v2x_cpm_sender_ = create_publisher("/v2x/cpm/sender", rclcpp::QoS{10}); this->declare_parameter("network_interface", "vmnet1"); this->declare_parameter("is_sender", true); @@ -46,6 +49,48 @@ namespace v2x } + void V2XNode::publishCpmSenderObject(double x_mgrs, double y_mgrs, double orientation) { + autoware_auto_perception_msgs::msg::PredictedObjects cpm_sender_object_msg; + std_msgs::msg::Header header; + rclcpp::Time current_time = this->now(); + cpm_sender_object_msg.header.frame_id = "map"; + cpm_sender_object_msg.header.stamp = current_time; + + autoware_auto_perception_msgs::msg::PredictedObject object; + autoware_auto_perception_msgs::msg::ObjectClassification classification; + autoware_auto_perception_msgs::msg::Shape shape; + autoware_auto_perception_msgs::msg::PredictedObjectKinematics kinematics; + + classification.label = autoware_auto_perception_msgs::msg::ObjectClassification::CAR; + classification.probability = 0.99; + + shape.type = autoware_auto_perception_msgs::msg::Shape::BOUNDING_BOX; + shape.dimensions.x = 5.0; + shape.dimensions.y = 2.0; + shape.dimensions.z = 1.7; + + kinematics.initial_pose_with_covariance.pose.position.x = x_mgrs; + kinematics.initial_pose_with_covariance.pose.position.y = y_mgrs; + kinematics.initial_pose_with_covariance.pose.position.z = 0.1; + + tf2::Quaternion quat; + quat.setRPY(0, 0, orientation); + + kinematics.initial_pose_with_covariance.pose.orientation.x = quat.x(); + kinematics.initial_pose_with_covariance.pose.orientation.y = quat.y(); + kinematics.initial_pose_with_covariance.pose.orientation.z = quat.z(); + kinematics.initial_pose_with_covariance.pose.orientation.w = quat.w(); + + object.classification.emplace_back(classification); + object.shape = shape; + object.kinematics = kinematics; + + cpm_sender_object_msg.objects.push_back(object); + + publisher_v2x_cpm_sender_->publish(cpm_sender_object_msg); + + } + void V2XNode::publishObjects(std::vector *objectsStack) { autoware_auto_perception_msgs::msg::PredictedObjects output_dynamic_object_msg; std_msgs::msg::Header header;