Skip to content

Commit 1a04aa6

Browse files
authored
Merge pull request #141 from RoverRobotics/enable_aruco_detections_topic
Added topic that enables/disables Aruco detections
2 parents 913fa35 + b11fbed commit 1a04aa6

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

aruco_detect/src/aruco_detect.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <cv_bridge/cv_bridge.h>
4646
#include <sensor_msgs/image_encodings.h>
4747
#include <dynamic_reconfigure/server.h>
48+
#include <std_srvs/SetBool.h>
4849

4950
#include "fiducial_msgs/Fiducial.h"
5051
#include "fiducial_msgs/FiducialArray.h"
@@ -72,8 +73,11 @@ class FiducialsNode {
7273
image_transport::ImageTransport it;
7374
image_transport::Subscriber img_sub;
7475

76+
ros::ServiceServer service_enable_detections;
77+
7578
// if set, we publish the images that contain fiducials
7679
bool publish_images;
80+
bool enable_detections;
7781

7882
double fiducial_len;
7983

@@ -86,7 +90,6 @@ class FiducialsNode {
8690
std::vector<int> ignoreIds;
8791
std::map<int, double> fiducialLens;
8892

89-
9093
image_transport::Publisher image_pub;
9194

9295
cv::Ptr<aruco::DetectorParameters> detectorParams;
@@ -105,6 +108,9 @@ class FiducialsNode {
105108
void camInfoCallback(const sensor_msgs::CameraInfo::ConstPtr &msg);
106109
void configCallback(aruco_detect::DetectorParamsConfig &config, uint32_t level);
107110

111+
bool enableDetectionsCallback(std_srvs::SetBool::Request &req,
112+
std_srvs::SetBool::Response &res);
113+
108114
dynamic_reconfigure::Server<aruco_detect::DetectorParamsConfig> configServer;
109115
dynamic_reconfigure::Server<aruco_detect::DetectorParamsConfig>::CallbackType callbackType;
110116

@@ -293,6 +299,10 @@ void FiducialsNode::camInfoCallback(const sensor_msgs::CameraInfo::ConstPtr& msg
293299
}
294300

295301
void FiducialsNode::imageCallback(const sensor_msgs::ImageConstPtr & msg) {
302+
if (enable_detections == false) {
303+
return; //return without doing anything
304+
}
305+
296306
ROS_INFO("Got image %d", msg->header.seq);
297307
frameNum++;
298308

@@ -411,6 +421,23 @@ void FiducialsNode::imageCallback(const sensor_msgs::ImageConstPtr & msg) {
411421
}
412422
}
413423

424+
bool FiducialsNode::enableDetectionsCallback(std_srvs::SetBool::Request &req,
425+
std_srvs::SetBool::Response &res)
426+
{
427+
enable_detections = req.data;
428+
if (enable_detections){
429+
res.message = "Enabled aruco detections.";
430+
ROS_INFO("Enabled aruco detections.");
431+
}
432+
else {
433+
res.message = "Disabled aruco detections.";
434+
ROS_INFO("Disabled aruco detections.");
435+
}
436+
437+
res.success = true;
438+
return true;
439+
}
440+
414441
FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
415442
{
416443
frameNum = 0;
@@ -422,6 +449,7 @@ FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
422449
distortionCoeffs = cv::Mat::zeros(1, 5, CV_64F);
423450

424451
haveCamInfo = false;
452+
enable_detections = true;
425453

426454
int dicno;
427455

@@ -506,18 +534,20 @@ FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
506534

507535
image_pub = it.advertise("/fiducial_images", 1);
508536

509-
510537
vertices_pub = new ros::Publisher(nh.advertise<fiducial_msgs::FiducialArray>("/fiducial_vertices", 1));
511538

512539
pose_pub = new ros::Publisher(nh.advertise<fiducial_msgs::FiducialTransformArray>("/fiducial_transforms", 1));
513540

514541
dictionary = aruco::getPredefinedDictionary(dicno);
515542

516543
img_sub = it.subscribe("/camera", 1,
517-
&FiducialsNode::imageCallback, this);
544+
&FiducialsNode::imageCallback, this);
518545

519546
caminfo_sub = nh.subscribe("/camera_info", 1,
520-
&FiducialsNode::camInfoCallback, this);
547+
&FiducialsNode::camInfoCallback, this);
548+
549+
service_enable_detections = nh.advertiseService("enable_detections",
550+
&FiducialsNode::enableDetectionsCallback, this);
521551

522552
callbackType = boost::bind(&FiducialsNode::configCallback, this, _1, _2);
523553
configServer.setCallback(callbackType);

0 commit comments

Comments
 (0)