Adding aruco msgs input support (#1334)

* Adding aruco msgs input support

* updated topic names
This commit is contained in:
matlabbe
2025-06-28 16:46:10 -07:00
committed by GitHub
parent d336369ca4
commit aa7f42a57e
4 changed files with 204 additions and 9 deletions
+44
View File
@@ -38,6 +38,10 @@ find_package(rtabmap_sync REQUIRED)
#optional #optional
find_package(apriltag_msgs) find_package(apriltag_msgs)
find_package(aruco_msgs)
find_package(aruco_markers_msgs)
find_package(aruco_opencv_msgs)
find_package(ros2_aruco_interfaces)
find_package(nav2_msgs) find_package(nav2_msgs)
IF(WIN32) IF(WIN32)
@@ -88,6 +92,46 @@ SET(Libraries
) )
ENDIF(apriltag_msgs_FOUND) ENDIF(apriltag_msgs_FOUND)
# If aruco_msgs is found, add definition
IF(aruco_msgs_FOUND)
MESSAGE(STATUS "WITH aruco_msgs")
ADD_DEFINITIONS("-DWITH_ARUCO_MSGS")
SET(Libraries
${Libraries}
aruco_msgs
)
ENDIF(aruco_msgs_FOUND)
# If aruco_opencv_msgs is found, add definition
IF(aruco_opencv_msgs_FOUND)
MESSAGE(STATUS "WITH aruco_opencv_msgs")
ADD_DEFINITIONS("-DWITH_ARUCO_OPENCV_MSGS")
SET(Libraries
${Libraries}
aruco_opencv_msgs
)
ENDIF(aruco_opencv_msgs_FOUND)
# If aruco_markers_msgs is found, add definition
IF(aruco_markers_msgs_FOUND)
MESSAGE(STATUS "WITH aruco_markers_msgs")
ADD_DEFINITIONS("-DWITH_ARUCO_MARKERS_MSGS")
SET(Libraries
${Libraries}
aruco_markers_msgs
)
ENDIF(aruco_markers_msgs_FOUND)
# If ros2_aruco_interfaces is found, add definition
IF(ros2_aruco_interfaces_FOUND)
MESSAGE(STATUS "WITH ros2_aruco_interfaces")
ADD_DEFINITIONS("-DWITH_ROS2_ARUCO_INTERFACES")
SET(Libraries
${Libraries}
ros2_aruco_interfaces
)
ENDIF(ros2_aruco_interfaces_FOUND)
# If nav2_msgs is found, add definition # If nav2_msgs is found, add definition
IF(nav2_msgs_FOUND) IF(nav2_msgs_FOUND)
MESSAGE(STATUS "WITH nav2_msgs") MESSAGE(STATUS "WITH nav2_msgs")
@@ -88,6 +88,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <apriltag_msgs/msg/april_tag_detection_array.hpp> #include <apriltag_msgs/msg/april_tag_detection_array.hpp>
#endif #endif
#ifdef WITH_ARUCO_MSGS
#include <aruco_msgs/msg/marker_array.hpp>
#endif
#ifdef WITH_ARUCO_OPENCV_MSGS
#include <aruco_opencv_msgs/msg/aruco_detection.hpp>
#endif
#ifdef WITH_ARUCO_MARKERS_MSGS
#include <aruco_markers_msgs/msg/marker_array.hpp>
#endif
#ifdef WITH_ROS2_ARUCO_INTERFACES
#include <ros2_aruco_interfaces/msg/aruco_markers.hpp>
#endif
#ifdef WITH_NAV2_MSGS #ifdef WITH_NAV2_MSGS
#include <nav2_msgs/action/navigate_to_pose.hpp> #include <nav2_msgs/action/navigate_to_pose.hpp>
#include <rclcpp_action/rclcpp_action.hpp> #include <rclcpp_action/rclcpp_action.hpp>
@@ -178,7 +194,20 @@ private:
void landmarkDetectionAsyncCallback(const rtabmap_msgs::msg::LandmarkDetection::SharedPtr landmarkDetection); void landmarkDetectionAsyncCallback(const rtabmap_msgs::msg::LandmarkDetection::SharedPtr landmarkDetection);
void landmarkDetectionsAsyncCallback(const rtabmap_msgs::msg::LandmarkDetections::SharedPtr landmarkDetections); void landmarkDetectionsAsyncCallback(const rtabmap_msgs::msg::LandmarkDetections::SharedPtr landmarkDetections);
#ifdef WITH_APRILTAG_MSGS #ifdef WITH_APRILTAG_MSGS
void tagDetectionsAsyncCallback(const apriltag_msgs::msg::AprilTagDetectionArray::SharedPtr tagDetections); void tagDetectionsAsyncCallback(const apriltag_msgs::msg::AprilTagDetectionArray::SharedPtr msg);
void apriltagAsyncCallback(const apriltag_msgs::msg::AprilTagDetectionArray::SharedPtr msg);
#endif
#ifdef WITH_ARUCO_MSGS
void arucoAsyncCallback(const aruco_msgs::msg::MarkerArray::SharedPtr msg);
#endif
#ifdef WITH_ARUCO_OPENCV_MSGS
void arucoOpencvAsyncCallback(const aruco_opencv_msgs::msg::ArucoDetection::SharedPtr msg);
#endif
#ifdef WITH_ARUCO_MARKERS_MSGS
void arucoMarkersAsyncCallback(const aruco_markers_msgs::msg::MarkerArray::SharedPtr msg);
#endif
#ifdef WITH_ROS2_ARUCO_INTERFACES
void arucoInterfacesAsyncCallback(const ros2_aruco_interfaces::msg::ArucoMarkers::SharedPtr msg);
#endif #endif
#ifdef WITH_FIDUCIAL_MSGS #ifdef WITH_FIDUCIAL_MSGS
void fiducialDetectionsAsyncCallback(const fiducial_msgs::msgs::FiducialTransformArray::SharedPtr fiducialDetections); void fiducialDetectionsAsyncCallback(const fiducial_msgs::msgs::FiducialTransformArray::SharedPtr fiducialDetections);
@@ -420,6 +449,19 @@ private:
rclcpp::Subscription<rtabmap_msgs::msg::LandmarkDetections>::SharedPtr landmarkDetectionsSub_; rclcpp::Subscription<rtabmap_msgs::msg::LandmarkDetections>::SharedPtr landmarkDetectionsSub_;
#ifdef WITH_APRILTAG_MSGS #ifdef WITH_APRILTAG_MSGS
rclcpp::Subscription<apriltag_msgs::msg::AprilTagDetectionArray>::SharedPtr tagDetectionsSub_; rclcpp::Subscription<apriltag_msgs::msg::AprilTagDetectionArray>::SharedPtr tagDetectionsSub_;
rclcpp::Subscription<apriltag_msgs::msg::AprilTagDetectionArray>::SharedPtr apriltagSub_;
#endif
#ifdef WITH_ARUCO_MSGS
rclcpp::Subscription<aruco_msgs::msg::MarkerArray>::SharedPtr arucoSub_;
#endif
#ifdef WITH_ARUCO_OPENCV_MSGS
rclcpp::Subscription<aruco_opencv_msgs::msg::ArucoDetection>::SharedPtr arucoOpencvSub_;
#endif
#ifdef WITH_ARUCO_MARKERS_MSGS
rclcpp::Subscription<aruco_markers_msgs::msg::MarkerArray>::SharedPtr arucoMarkersSub_;
#endif
#ifdef WITH_ROS2_ARUCO_INTERFACES
rclcpp::Subscription<ros2_aruco_interfaces::msg::ArucoMarkers>::SharedPtr arucoInterfacesSub_;
#endif #endif
#ifdef WITH_FIDUCIAL_MSGS #ifdef WITH_FIDUCIAL_MSGS
rclcpp::Subscription<fiducial_msgs::msg::FiducialTransformArray>::SharedPtr fiducialTransfromsSub_; rclcpp::Subscription<fiducial_msgs::msg::FiducialTransformArray>::SharedPtr fiducialTransfromsSub_;
+3
View File
@@ -27,6 +27,9 @@
<depend>tf2_ros</depend> <depend>tf2_ros</depend>
<depend>visualization_msgs</depend> <depend>visualization_msgs</depend>
<depend>apriltag_msgs</depend> <depend>apriltag_msgs</depend>
<depend>aruco_msgs</depend>
<depend>aruco_opencv_msgs</depend>
<!-- depend>aruco_markers_msgs</depend --> <!-- binaries only available on humble -->
<depend>rtabmap_msgs</depend> <depend>rtabmap_msgs</depend>
<depend>rtabmap_util</depend> <depend>rtabmap_util</depend>
+114 -8
View File
@@ -886,6 +886,19 @@ CoreWrapper::CoreWrapper(const rclcpp::NodeOptions & options) :
landmarkDetectionsSub_ = this->create_subscription<rtabmap_msgs::msg::LandmarkDetections>("landmark_detections", 1, std::bind(&CoreWrapper::landmarkDetectionsAsyncCallback, this, std::placeholders::_1), landmarkSubOptions); landmarkDetectionsSub_ = this->create_subscription<rtabmap_msgs::msg::LandmarkDetections>("landmark_detections", 1, std::bind(&CoreWrapper::landmarkDetectionsAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
#ifdef WITH_APRILTAG_MSGS #ifdef WITH_APRILTAG_MSGS
tagDetectionsSub_ = this->create_subscription<apriltag_msgs::msg::AprilTagDetectionArray>("tag_detections", 5, std::bind(&CoreWrapper::tagDetectionsAsyncCallback, this, std::placeholders::_1), landmarkSubOptions); tagDetectionsSub_ = this->create_subscription<apriltag_msgs::msg::AprilTagDetectionArray>("tag_detections", 5, std::bind(&CoreWrapper::tagDetectionsAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
apriltagSub_ = this->create_subscription<apriltag_msgs::msg::AprilTagDetectionArray>("apriltag/detections", 5, std::bind(&CoreWrapper::apriltagAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
#endif
#ifdef WITH_ARUCO_MSGS
arucoSub_ = this->create_subscription<aruco_msgs::msg::MarkerArray>("aruco/detections", 5, std::bind(&CoreWrapper::arucoAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
#endif
#ifdef WITH_ARUCO_OPENCV_MSGS
arucoOpencvSub_ = this->create_subscription<aruco_opencv_msgs::msg::ArucoDetection>("aruco_opencv/detections", 5, std::bind(&CoreWrapper::arucoOpencvAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
#endif
#ifdef WITH_ARUCO_MARKERS_MSGS
arucoMarkersSub_ = this->create_subscription<aruco_markers_msgs::msg::MarkerArray>("aruco_markers/detections", 5, std::bind(&CoreWrapper::arucoMarkersAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
#endif
#ifdef WITH_ROS2_ARUCO_INTERFACES
arucoInterfacesSub_ = this->create_subscription<ros2_aruco_interfaces::msg::ArucoMarkers>("aruco_interfaces/detections", 5, std::bind(&CoreWrapper::arucoInterfacesAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
#endif #endif
#ifdef WITH_FIDUCIAL_MSGS #ifdef WITH_FIDUCIAL_MSGS
fiducialTransfromsSub_ = this->create_subscription<fiducial_msgs::msg::FiducialTransformArray>("fiducial_transforms", 5, std::bind(&CoreWrapper::fiducialDetectionsAsyncCallback, this, std::placeholders::_1), landmarkSubOptions); fiducialTransfromsSub_ = this->create_subscription<fiducial_msgs::msg::FiducialTransformArray>("fiducial_transforms", 5, std::bind(&CoreWrapper::fiducialDetectionsAsyncCallback, this, std::placeholders::_1), landmarkSubOptions);
@@ -2651,18 +2664,30 @@ void CoreWrapper::landmarkDetectionsAsyncCallback(const rtabmap_msgs::msg::Landm
} }
#ifdef WITH_APRILTAG_MSGS #ifdef WITH_APRILTAG_MSGS
void CoreWrapper::tagDetectionsAsyncCallback(const apriltag_msgs::msg::AprilTagDetectionArray::SharedPtr tagDetections) void CoreWrapper::tagDetectionsAsyncCallback(const apriltag_msgs::msg::AprilTagDetectionArray::SharedPtr msg)
{
if(!paused_)
{
static bool warningShow = false;
if(!warningShow) {
RCLCPP_WARN(this->get_logger(), "\"tag_detections\" input topic name for apriltag_msgs is deprecated, remap \"apriltag\" input topic name instead. This message is only printed once.");
warningShow = true;
}
apriltagAsyncCallback(msg);
}
}
void CoreWrapper::apriltagAsyncCallback(const apriltag_msgs::msg::AprilTagDetectionArray::SharedPtr msg)
{ {
if(!paused_) if(!paused_)
{ {
UScopeMutex lock(landmarksMutex_); UScopeMutex lock(landmarksMutex_);
for(unsigned int i=0; i<tagDetections->detections.size(); ++i) for(unsigned int i=0; i<msg->detections.size(); ++i)
{ {
std::string tagFrameId = tagDetections->detections[i].family+":"+uNumber2Str(tagDetections->detections[i].id); std::string tagFrameId = msg->detections[i].family+":"+uNumber2Str(msg->detections[i].id);
Transform camToTag = rtabmap_conversions::getTransform( Transform camToTag = rtabmap_conversions::getTransform(
tagDetections->header.frame_id, // e.g., camera_optical_frame msg->header.frame_id, // e.g., camera_optical_frame
tagFrameId, // e.g., tag36h11:42 tagFrameId, // e.g., tag36h11:42
tagDetections->header.stamp, msg->header.stamp,
*tfBuffer_, *tfBuffer_,
waitForTransform_); waitForTransform_);
if(camToTag.isNull()) if(camToTag.isNull())
@@ -2670,16 +2695,97 @@ void CoreWrapper::tagDetectionsAsyncCallback(const apriltag_msgs::msg::AprilTagD
RCLCPP_WARN(get_logger(), "Could not get TF between %s and %s frames for tag detection %d.", RCLCPP_WARN(get_logger(), "Could not get TF between %s and %s frames for tag detection %d.",
frameId_.c_str(), frameId_.c_str(),
tagFrameId.c_str(), tagFrameId.c_str(),
tagDetections->detections[i].id); msg->detections[i].id);
continue; continue;
} }
geometry_msgs::msg::PoseWithCovarianceStamped p; geometry_msgs::msg::PoseWithCovarianceStamped p;
rtabmap_conversions::transformToPoseMsg(camToTag, p.pose.pose); rtabmap_conversions::transformToPoseMsg(camToTag, p.pose.pose);
p.header = tagDetections->header; p.header = msg->header;
uInsert(landmarks_, uInsert(landmarks_,
std::make_pair(tagDetections->detections[i].id, std::make_pair(msg->detections[i].id,
std::make_pair(p, 0.0f)));
}
}
}
#endif
#ifdef WITH_ARUCO_MSGS
void CoreWrapper::arucoAsyncCallback(const aruco_msgs::msg::MarkerArray::SharedPtr msg)
{
if(!paused_)
{
UScopeMutex lock(landmarksMutex_);
for(unsigned int i=0; i<msg->markers.size(); ++i)
{
geometry_msgs::msg::PoseWithCovarianceStamped p;
p.pose = msg->markers[i].pose;
p.header = msg->markers[i].header;
uInsert(landmarks_,
std::make_pair((int)msg->markers[i].id,
std::make_pair(p, 0.0f)));
}
}
}
#endif
#ifdef WITH_ARUCO_OPENCV_MSGS
void CoreWrapper::arucoOpencvAsyncCallback(const aruco_opencv_msgs::msg::ArucoDetection::SharedPtr msg)
{
if(!paused_)
{
UScopeMutex lock(landmarksMutex_);
for(unsigned int i=0; i<msg->markers.size(); ++i)
{
geometry_msgs::msg::PoseWithCovarianceStamped p;
p.pose.pose = msg->markers[i].pose;
p.header = msg->header;
uInsert(landmarks_,
std::make_pair((int)msg->markers[i].marker_id,
std::make_pair(p, 0.0f)));
}
}
}
#endif
#ifdef WITH_ARUCO_MARKERS_MSGS
void CoreWrapper::arucoMarkersAsyncCallback(const aruco_markers_msgs::msg::MarkerArray::SharedPtr msg)
{
if(!paused_)
{
UScopeMutex lock(landmarksMutex_);
for(unsigned int i=0; i<msg->markers.size(); ++i)
{
geometry_msgs::msg::PoseWithCovarianceStamped p;
p.pose.pose = msg->markers[i].pose.pose;
p.header = msg->markers[i].pose.header;
uInsert(landmarks_,
std::make_pair((int)msg->markers[i].id,
std::make_pair(p, 0.0f)));
}
}
}
#endif
#ifdef WITH_ROS2_ARUCO_INTERFACES
void CoreWrapper::arucoInterfacesAsyncCallback(const ros2_aruco_interfaces::msg::ArucoMarkers::SharedPtr msg)
{
if(!paused_)
{
UScopeMutex lock(landmarksMutex_);
UASSERT(msg->marker_ids.size() == msg->poses.size());
for(unsigned int i=0; i<msg->marker_ids.size(); ++i)
{
geometry_msgs::msg::PoseWithCovarianceStamped p;
p.pose.pose = msg->poses[i];
p.header = msg->header;
uInsert(landmarks_,
std::make_pair((int)msg->marker_ids[i],
std::make_pair(p, 0.0f))); std::make_pair(p, 0.0f)));
} }
} }