Skip to content

Commit fe1dd0a

Browse files
Merge pull request #1 from UbiquityRobotics/kinetic-devel
Pulling in changes from main repo
2 parents 913fa35 + ef0a113 commit fe1dd0a

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

aruco_detect/src/aruco_detect.cpp

Lines changed: 38 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

@@ -319,6 +329,10 @@ void FiducialsNode::imageCallback(const sensor_msgs::ImageConstPtr & msg) {
319329
ROS_INFO("Detected %d markers", (int)ids.size());
320330

321331
for (size_t i=0; i<ids.size(); i++) {
332+
if (std::count(ignoreIds.begin(), ignoreIds.end(), ids[i]) != 0) {
333+
ROS_INFO("Ignoring id %d", ids[i]);
334+
continue;
335+
}
322336
fiducial_msgs::Fiducial fid;
323337
fid.fiducial_id = ids[i];
324338

@@ -411,6 +425,23 @@ void FiducialsNode::imageCallback(const sensor_msgs::ImageConstPtr & msg) {
411425
}
412426
}
413427

428+
bool FiducialsNode::enableDetectionsCallback(std_srvs::SetBool::Request &req,
429+
std_srvs::SetBool::Response &res)
430+
{
431+
enable_detections = req.data;
432+
if (enable_detections){
433+
res.message = "Enabled aruco detections.";
434+
ROS_INFO("Enabled aruco detections.");
435+
}
436+
else {
437+
res.message = "Disabled aruco detections.";
438+
ROS_INFO("Disabled aruco detections.");
439+
}
440+
441+
res.success = true;
442+
return true;
443+
}
444+
414445
FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
415446
{
416447
frameNum = 0;
@@ -422,6 +453,7 @@ FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
422453
distortionCoeffs = cv::Mat::zeros(1, 5, CV_64F);
423454

424455
haveCamInfo = false;
456+
enable_detections = true;
425457

426458
int dicno;
427459

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

507539
image_pub = it.advertise("/fiducial_images", 1);
508540

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

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

514545
dictionary = aruco::getPredefinedDictionary(dicno);
515546

516547
img_sub = it.subscribe("/camera", 1,
517-
&FiducialsNode::imageCallback, this);
548+
&FiducialsNode::imageCallback, this);
518549

519550
caminfo_sub = nh.subscribe("/camera_info", 1,
520-
&FiducialsNode::camInfoCallback, this);
551+
&FiducialsNode::camInfoCallback, this);
552+
553+
service_enable_detections = nh.advertiseService("enable_detections",
554+
&FiducialsNode::enableDetectionsCallback, this);
521555

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

0 commit comments

Comments
 (0)