@@ -73,13 +73,15 @@ namespace object_detection
73
73
{
74
74
75
75
using Polygon2d = tier4_autoware_utils::Polygon2d;
76
+ using Shape = autoware_auto_perception_msgs::msg::Shape;
76
77
77
78
// struct for creating objects buffer
78
79
struct object_info
79
80
{
80
- autoware_auto_perception_msgs::msg:: Shape shape;
81
+ Shape shape;
81
82
geometry_msgs::msg::Pose position;
82
- autoware_auto_perception_msgs::msg::ObjectClassification classification;
83
+ // autoware_auto_perception_msgs::msg::ObjectClassification classification;
84
+ std::vector<autoware_auto_perception_msgs::msg::ObjectClassification> classification;
83
85
};
84
86
85
87
inline pcl::PointXYZRGB toPCL (const double x, const double y, const double z)
@@ -185,7 +187,7 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
185
187
186
188
// get access to rivz node to sub and to pub to topics
187
189
rclcpp::Node::SharedPtr raw_node = this ->context_ ->getRosNodeAbstraction ().lock ()->get_raw_node ();
188
- publisher_ = raw_node->create_publisher <sensor_msgs::msg::PointCloud2>(" output/pointcloud" , 10 );
190
+ publisher_ = raw_node->create_publisher <sensor_msgs::msg::PointCloud2>(" output/pointcloud" , rclcpp::SensorDataQoS () );
189
191
pointcloud_subscription_ = raw_node->create_subscription <sensor_msgs::msg::PointCloud2>(
190
192
m_default_pointcloud_topic->getTopicStd (),
191
193
rclcpp::SensorDataQoS (),
@@ -224,8 +226,62 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
224
226
{
225
227
m_marker_common.addMessage (markers_ptr);
226
228
}
229
+
230
+ // transfrom detected object pose to target frame and return bool result
231
+ bool transformObjects (
232
+ const MsgT & input_msg, const std::string & target_frame_id, const tf2_ros::Buffer & tf_buffer,
233
+ MsgT & output_msg)
234
+ {
235
+ output_msg = input_msg;
236
+
237
+ // transform to world coordinate
238
+ if (input_msg.header .frame_id != target_frame_id) {
239
+ output_msg.header .frame_id = target_frame_id;
240
+ tf2::Transform tf_target2objects_world;
241
+ tf2::Transform tf_target2objects;
242
+ tf2::Transform tf_objects_world2objects;
243
+ {
244
+ const auto ros_target2objects_world = getTransform (
245
+ tf_buffer, input_msg.header .frame_id , target_frame_id, input_msg.header .stamp );
246
+ if (!ros_target2objects_world) {
247
+ return false ;
248
+ }
249
+ tf2::fromMsg (*ros_target2objects_world, tf_target2objects_world);
250
+ }
251
+ for (auto & object : output_msg.objects ) {
252
+ tf2::fromMsg (object.kinematics .pose_with_covariance .pose , tf_objects_world2objects);
253
+ tf_target2objects = tf_target2objects_world * tf_objects_world2objects;
254
+ tf2::toMsg (tf_target2objects, object.kinematics .pose_with_covariance .pose );
255
+ }
256
+ }
257
+ return true ;
258
+ }
259
+
260
+ // get transformation from tf2
261
+ boost::optional<geometry_msgs::msg::Transform> getTransform (
262
+ const tf2_ros::Buffer & tf_buffer, const std::string & source_frame_id,
263
+ const std::string & target_frame_id, const rclcpp::Time & time)
264
+ {
265
+ try {
266
+ geometry_msgs::msg::TransformStamped self_transform_stamped;
267
+ self_transform_stamped = tf_buffer.lookupTransform (
268
+ target_frame_id, source_frame_id, time , rclcpp::Duration::from_seconds (0.5 ));
269
+ return self_transform_stamped.transform ;
270
+ } catch (tf2::TransformException & ex) {
271
+ RCLCPP_WARN_STREAM (rclcpp::get_logger (" perception_utils" ), ex.what ()); // rename
272
+ return boost::none;
273
+ }
274
+ }
275
+
227
276
277
+ // std::string objects_frame_id_;
278
+ // variables for transfer detected objects information between callbacks
279
+ std::vector<object_info> objs_buffer;
228
280
std::string objects_frame_id_;
281
+ std::string pointcloud_frame_id_;
282
+ std::shared_ptr<tf2_ros::TransformListener> tf_listener_{nullptr }; // !! different type in prototype,
283
+ std::unique_ptr<tf2_ros::Buffer> tf_buffer_; // !! different type in prototype
284
+ rclcpp::Node::SharedPtr raw_node;
229
285
230
286
protected:
231
287
// / \brief Convert given shape msg into a Marker
@@ -462,51 +518,8 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
462
518
463
519
double get_line_width () { return m_line_width_property.getFloat (); }
464
520
465
- // get transformation from tf2
466
- boost::optional<geometry_msgs::msg::Transform> getTransform (
467
- const tf2_ros::Buffer & tf_buffer, const std::string & source_frame_id,
468
- const std::string & target_frame_id, const rclcpp::Time & time)
469
- {
470
- try {
471
- geometry_msgs::msg::TransformStamped self_transform_stamped;
472
- self_transform_stamped = tf_buffer.lookupTransform (
473
- target_frame_id, source_frame_id, time , rclcpp::Duration::from_seconds (0.5 ));
474
- return self_transform_stamped.transform ;
475
- } catch (tf2::TransformException & ex) {
476
- RCLCPP_WARN_STREAM (rclcpp::get_logger (" perception_utils" ), ex.what ()); // rename
477
- return boost::none;
478
- }
479
- }
480
521
481
- // transfrom detected object pose to target frame and return bool result
482
- bool transformObjects (
483
- const MsgT & input_msg, const std::string & target_frame_id, const tf2_ros::Buffer & tf_buffer,
484
- MsgT & output_msg)
485
- {
486
- output_msg = input_msg;
487
522
488
- // transform to world coordinate
489
- if (input_msg.header .frame_id != target_frame_id) {
490
- output_msg.header .frame_id = target_frame_id;
491
- tf2::Transform tf_target2objects_world;
492
- tf2::Transform tf_target2objects;
493
- tf2::Transform tf_objects_world2objects;
494
- {
495
- const auto ros_target2objects_world = getTransform (
496
- tf_buffer, input_msg.header .frame_id , target_frame_id, input_msg.header .stamp );
497
- if (!ros_target2objects_world) {
498
- return false ;
499
- }
500
- tf2::fromMsg (*ros_target2objects_world, tf_target2objects_world);
501
- }
502
- for (auto & object : output_msg.objects ) {
503
- tf2::fromMsg (object.kinematics .pose_with_covariance .pose , tf_objects_world2objects);
504
- tf_target2objects = tf_target2objects_world * tf_objects_world2objects;
505
- tf2::toMsg (tf_target2objects, object.kinematics .pose_with_covariance .pose );
506
- }
507
- }
508
- return true ;
509
- }
510
523
511
524
// helper function to get radius for kd-search
512
525
std::optional<float > getMaxRadius (object_info & object)
@@ -521,24 +534,22 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
521
534
}
522
535
return max_dist;
523
536
} else {
524
- RCLCPP_WARN_THROTTLE (this ->get_logger (), *this ->get_clock (), 5000 , " unknown shape type" );
537
+ // RCLCPP_WARN_THROTTLE(this->get_logger(), *this->get_clock(), 5000, "unknown shape type");
525
538
return std::nullopt;
526
539
}
527
540
}
541
+
542
+ virtual void objectsCallback (typename MsgT::ConstSharedPtr msg) = 0;
528
543
529
- std::shared_ptr<tf2_ros::TransformListener> tf_listener_{nullptr } // !! different type in prototype,
530
- std::unique_ptr<tf2_ros::Buffer> tf_buffer_; // !! different type in prototype
544
+
531
545
// add pointcloud subscription
532
546
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr pointcloud_subscription_;
533
547
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr publisher_;
534
548
535
549
// Default pointcloud topic;
536
550
rviz_common::properties::RosTopicProperty * m_default_pointcloud_topic;
537
551
538
- // variables for transfer detected objects information between callbacks
539
- std::vector<object_info> objs_buffer;
540
- std::string objects_frame_id_;
541
- std::string pointcloud_frame_id_;
552
+
542
553
543
554
private:
544
555
// All rviz plugins should have this. Should be initialized with pointer to this class
@@ -579,10 +590,10 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
579
590
// RCLCPP_INFO(this->get_logger(), "Get new pointcloud");
580
591
pointcloud_frame_id_ = input_pointcloud_msg.header .frame_id ;
581
592
582
- pcl::PointXYZ minPt, maxPt;
583
- pcl::PointCloud<pcl::PointXYZ> measured_cloud;
584
- pcl::fromROSMsg (input_pointcloud_msg, measured_cloud);
585
- pcl::getMinMax3D (measured_cloud, minPt, maxPt);
593
+ // pcl::PointXYZ minPt, maxPt;
594
+ // pcl::PointCloud<pcl::PointXYZ> measured_cloud;
595
+ // pcl::fromROSMsg(input_pointcloud_msg, measured_cloud);
596
+ // pcl::getMinMax3D(measured_cloud, minPt, maxPt);
586
597
587
598
// RCLCPP_INFO(this->get_logger(), "before translation max X is '%f' max Y is '%f'", maxPt.x, maxPt.y);
588
599
// RCLCPP_INFO(this->get_logger(), "before translation min X is '%f' min Y is '%f'", minPt.x, minPt.y);
@@ -625,7 +636,7 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
625
636
filterPolygon (neighbor_pointcloud, out_cloud, object);
626
637
}
627
638
} else {
628
- RCLCPP_WARN_THROTTLE (this ->get_logger (), *this ->get_clock (), 5 , " objects buffer is empty" );
639
+ // RCLCPP_WARN_THROTTLE(this->get_logger(), *this->get_clock(), 5, "objects buffer is empty");
629
640
return ;
630
641
}
631
642
@@ -636,7 +647,7 @@ class AUTOWARE_AUTO_PERCEPTION_RVIZ_PLUGIN_PUBLIC ObjectPolygonDisplayBase
636
647
// *output_pointcloud_msg_ptr = transformed_pointcloud;
637
648
638
649
output_pointcloud_msg_ptr->header = input_pointcloud_msg.header ;
639
- output_pointcloud_msg_ptr->header .frame_id = objects_frame_id_; // remove
650
+ // output_pointcloud_msg_ptr->header.frame_id = objects_frame_id_; // remove
640
651
641
652
// RCLCPP_INFO(this->get_logger(), "Publishing pointcloud");
642
653
publisher_->publish (*output_pointcloud_msg_ptr);
0 commit comments