203 lines
8.2 KiB
C++
203 lines
8.2 KiB
C++
/*
|
|
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifdef ROS2
|
|
#include <rclcpp/rclcpp.hpp>
|
|
#include <geometry_msgs/msg/point_stamped.hpp>
|
|
#include <sensor_msgs/msg/point_cloud2.hpp>
|
|
#include <sensor_msgs/msg/image.hpp>
|
|
#include <sensor_msgs/msg/compressed_image.hpp>
|
|
#include <nav_msgs/msg/odometry.hpp>
|
|
#include <std_msgs/msg/float32_multi_array.hpp>
|
|
#include <std_msgs/msg/int32.hpp>
|
|
#include <visualization_msgs/msg/marker.hpp>
|
|
#include <visualization_msgs/msg/marker_array.hpp>
|
|
#include <cv_bridge/cv_bridge.h>
|
|
#include <message_filters/subscriber.h>
|
|
#include <message_filters/sync_policies/approximate_time.h>
|
|
#include "odin_ros_driver/msg/target_observation.hpp"
|
|
#include "odin_ros_driver/msg/target_observation_array.hpp"
|
|
#else
|
|
#include <ros/ros.h>
|
|
#include <sensor_msgs/PointCloud2.h>
|
|
#include <sensor_msgs/Image.h>
|
|
#include <sensor_msgs/CompressedImage.h>
|
|
#include <nav_msgs/Odometry.h>
|
|
#include <cv_bridge/cv_bridge.h>
|
|
#include <message_filters/subscriber.h>
|
|
#include <message_filters/sync_policies/approximate_time.h>
|
|
#endif
|
|
|
|
#include <pcl_conversions/pcl_conversions.h>
|
|
#include <pcl/point_types.h>
|
|
#include <pcl/point_cloud.h>
|
|
|
|
#include "cloud_reprojector.hpp"
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
|
|
#ifdef ODIN_ROS_DRIVER_HAS_TARGET_OBSERVATION
|
|
#include "target_observation_processing.hpp"
|
|
#endif
|
|
|
|
#ifdef ROS2
|
|
class CloudReprojectionRosNode : public rclcpp::Node
|
|
{
|
|
public:
|
|
CloudReprojectionRosNode(const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
|
|
|
|
private:
|
|
using PointCloud2 = sensor_msgs::msg::PointCloud2;
|
|
using Odometry = nav_msgs::msg::Odometry;
|
|
using Image = sensor_msgs::msg::Image;
|
|
using CompressedImage = sensor_msgs::msg::CompressedImage;
|
|
|
|
std::string cloud_slam_topic_;
|
|
std::string odometry_topic_;
|
|
std::string wiwc_topic_;
|
|
std::string camera_image_topic_;
|
|
bool camera_image_compressed_ = false;
|
|
bool always_send_sync_compressed_ = false;
|
|
bool always_send_sync_cloud_slam_ = false;
|
|
std::string sync_topic_prefix_;
|
|
std::string combined_compressed_topic_;
|
|
int combined_jpeg_quality_;
|
|
int overlay_jpeg_quality_;
|
|
bool publish_combined_compressed_;
|
|
bool send_overlay_;
|
|
|
|
message_filters::Subscriber<PointCloud2> cloud_sub_;
|
|
message_filters::Subscriber<Odometry> odom_sub_;
|
|
message_filters::Subscriber<Odometry> wiwc_sub_;
|
|
message_filters::Subscriber<Image> image_sub_;
|
|
message_filters::Subscriber<CompressedImage> compressed_image_sub_;
|
|
|
|
typedef message_filters::sync_policies::ApproximateTime<PointCloud2, Odometry, Odometry, Image> RawSyncPolicy;
|
|
typedef message_filters::Synchronizer<RawSyncPolicy> RawSync;
|
|
typedef message_filters::sync_policies::ApproximateTime<PointCloud2, Odometry, Odometry, CompressedImage> CompressedSyncPolicy;
|
|
typedef message_filters::Synchronizer<CompressedSyncPolicy> CompressedSync;
|
|
std::shared_ptr<RawSync> raw_sync_;
|
|
std::shared_ptr<CompressedSync> compressed_sync_;
|
|
|
|
std::string sync_cloud_topic_;
|
|
std::string sync_cloud_slam_topic_;
|
|
std::string sync_odom_topic_;
|
|
std::string sync_wiwc_topic_;
|
|
std::string sync_image_topic_;
|
|
std::string sync_image_compressed_topic_;
|
|
std::string sync_overlay_image_topic_;
|
|
std::string sync_detection_debug_image_topic_;
|
|
std::string sync_gallery_debug_topic_;
|
|
std::string sync_target_observation_topic_;
|
|
std::string sync_track_observations_topic_;
|
|
std::string sync_detection_pos_cam_topic_;
|
|
std::string sync_detection_pos_world_topic_;
|
|
|
|
rclcpp::Publisher<PointCloud2>::SharedPtr sync_cloud_pub_;
|
|
rclcpp::Publisher<PointCloud2>::SharedPtr sync_cloud_slam_pub_;
|
|
rclcpp::Publisher<Odometry>::SharedPtr sync_odom_pub_;
|
|
rclcpp::Publisher<Odometry>::SharedPtr sync_wiwc_pub_;
|
|
rclcpp::Publisher<Image>::SharedPtr sync_image_pub_;
|
|
rclcpp::Publisher<CompressedImage>::SharedPtr sync_image_compressed_pub_;
|
|
|
|
rclcpp::Publisher<CompressedImage>::SharedPtr overlay_compressed_pub_; // optional if send_overlay_
|
|
rclcpp::Publisher<CompressedImage>::SharedPtr detection_debug_compressed_pub_; // debug detections/tracks
|
|
rclcpp::Publisher<Image>::SharedPtr gallery_debug_pub_;
|
|
rclcpp::Publisher<CompressedImage>::SharedPtr combined_pub_; // optional if publish_combined_compressed_
|
|
rclcpp::Publisher<odin_ros_driver::msg::TargetObservation>::SharedPtr target_observation_pub_;
|
|
rclcpp::Publisher<odin_ros_driver::msg::TargetObservationArray>::SharedPtr track_observations_pub_;
|
|
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr detection_pos_cam_pub_;
|
|
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr detection_pos_world_pub_;
|
|
|
|
std::unique_ptr<CloudReprojector> reprojector_;
|
|
#ifdef ODIN_ROS_DRIVER_HAS_TARGET_OBSERVATION
|
|
std::unique_ptr<odin_ros_driver::TargetObservationProcessor> target_observation_processor_;
|
|
bool enable_target_observation_ = false;
|
|
bool debug_target_observation_ = false;
|
|
bool debug_reid_ = false;
|
|
#endif
|
|
|
|
void loadParameters();
|
|
void processSyncedData(const PointCloud2::ConstSharedPtr& cloud_msg,
|
|
const Odometry::ConstSharedPtr& odom_msg,
|
|
const Odometry::ConstSharedPtr& wiwc_msg,
|
|
const Image& image_msg,
|
|
const cv::Mat& cam_bgr);
|
|
void syncCallbackRaw(const PointCloud2::ConstSharedPtr& cloud_msg,
|
|
const Odometry::ConstSharedPtr& odom_msg,
|
|
const Odometry::ConstSharedPtr& wiwc_msg,
|
|
const Image::ConstSharedPtr& image_msg);
|
|
void syncCallbackCompressed(const PointCloud2::ConstSharedPtr& cloud_msg,
|
|
const Odometry::ConstSharedPtr& odom_msg,
|
|
const Odometry::ConstSharedPtr& wiwc_msg,
|
|
const CompressedImage::ConstSharedPtr& image_msg);
|
|
};
|
|
#else
|
|
class CloudReprojectionRosNode
|
|
{
|
|
public:
|
|
CloudReprojectionRosNode(ros::NodeHandle& nh, ros::NodeHandle& pnh);
|
|
|
|
private:
|
|
ros::NodeHandle nh_, pnh_;
|
|
|
|
std::string cloud_slam_topic_;
|
|
std::string odometry_topic_;
|
|
std::string wiwc_topic_;
|
|
std::string camera_image_topic_;
|
|
std::string sync_topic_prefix_;
|
|
std::string combined_compressed_topic_;
|
|
int combined_jpeg_quality_;
|
|
int overlay_jpeg_quality_;
|
|
bool publish_combined_compressed_;
|
|
bool send_overlay_;
|
|
|
|
std::string sync_cloud_topic_;
|
|
std::string sync_cloud_slam_topic_;
|
|
std::string sync_odom_topic_;
|
|
std::string sync_wiwc_topic_;
|
|
std::string sync_image_topic_;
|
|
std::string sync_overlay_image_topic_;
|
|
|
|
message_filters::Subscriber<sensor_msgs::PointCloud2> cloud_sub_;
|
|
message_filters::Subscriber<nav_msgs::Odometry> odom_sub_;
|
|
message_filters::Subscriber<nav_msgs::Odometry> wiwc_sub_;
|
|
message_filters::Subscriber<sensor_msgs::Image> image_sub_;
|
|
|
|
typedef message_filters::sync_policies::ApproximateTime<
|
|
sensor_msgs::PointCloud2, nav_msgs::Odometry, nav_msgs::Odometry, sensor_msgs::Image> MySyncPolicy;
|
|
typedef message_filters::Synchronizer<MySyncPolicy> Sync;
|
|
std::shared_ptr<Sync> sync_;
|
|
|
|
ros::Publisher sync_cloud_pub_;
|
|
ros::Publisher sync_cloud_slam_pub_;
|
|
ros::Publisher sync_odom_pub_;
|
|
ros::Publisher sync_wiwc_pub_;
|
|
ros::Publisher sync_image_pub_; // Image
|
|
|
|
ros::Publisher overlay_compressed_pub_;
|
|
ros::Publisher combined_pub_;
|
|
|
|
std::unique_ptr<CloudReprojector> reprojector_;
|
|
|
|
void loadParameters();
|
|
void syncCallback(const sensor_msgs::PointCloud2ConstPtr& cloud_msg,
|
|
const nav_msgs::OdometryConstPtr& odom_msg,
|
|
const nav_msgs::OdometryConstPtr& wiwc_msg,
|
|
const sensor_msgs::ImageConstPtr& image_msg);
|
|
};
|
|
#endif
|