45
45
#include < cv_bridge/cv_bridge.h>
46
46
#include < sensor_msgs/image_encodings.h>
47
47
#include < dynamic_reconfigure/server.h>
48
+ #include < std_srvs/SetBool.h>
48
49
49
50
#include " fiducial_msgs/Fiducial.h"
50
51
#include " fiducial_msgs/FiducialArray.h"
@@ -72,8 +73,11 @@ class FiducialsNode {
72
73
image_transport::ImageTransport it;
73
74
image_transport::Subscriber img_sub;
74
75
76
+ ros::ServiceServer service_enable_detections;
77
+
75
78
// if set, we publish the images that contain fiducials
76
79
bool publish_images;
80
+ bool enable_detections;
77
81
78
82
double fiducial_len;
79
83
@@ -86,7 +90,6 @@ class FiducialsNode {
86
90
std::vector<int > ignoreIds;
87
91
std::map<int , double > fiducialLens;
88
92
89
-
90
93
image_transport::Publisher image_pub;
91
94
92
95
cv::Ptr<aruco::DetectorParameters> detectorParams;
@@ -105,6 +108,9 @@ class FiducialsNode {
105
108
void camInfoCallback (const sensor_msgs::CameraInfo::ConstPtr &msg);
106
109
void configCallback (aruco_detect::DetectorParamsConfig &config, uint32_t level);
107
110
111
+ bool enableDetectionsCallback (std_srvs::SetBool::Request &req,
112
+ std_srvs::SetBool::Response &res);
113
+
108
114
dynamic_reconfigure::Server<aruco_detect::DetectorParamsConfig> configServer;
109
115
dynamic_reconfigure::Server<aruco_detect::DetectorParamsConfig>::CallbackType callbackType;
110
116
@@ -293,6 +299,10 @@ void FiducialsNode::camInfoCallback(const sensor_msgs::CameraInfo::ConstPtr& msg
293
299
}
294
300
295
301
void FiducialsNode::imageCallback (const sensor_msgs::ImageConstPtr & msg) {
302
+ if (enable_detections == false ) {
303
+ return ; // return without doing anything
304
+ }
305
+
296
306
ROS_INFO (" Got image %d" , msg->header .seq );
297
307
frameNum++;
298
308
@@ -319,6 +329,10 @@ void FiducialsNode::imageCallback(const sensor_msgs::ImageConstPtr & msg) {
319
329
ROS_INFO (" Detected %d markers" , (int )ids.size ());
320
330
321
331
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
+ }
322
336
fiducial_msgs::Fiducial fid;
323
337
fid.fiducial_id = ids[i];
324
338
@@ -411,6 +425,23 @@ void FiducialsNode::imageCallback(const sensor_msgs::ImageConstPtr & msg) {
411
425
}
412
426
}
413
427
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
+
414
445
FiducialsNode::FiducialsNode (ros::NodeHandle & nh) : it(nh)
415
446
{
416
447
frameNum = 0 ;
@@ -422,6 +453,7 @@ FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
422
453
distortionCoeffs = cv::Mat::zeros (1 , 5 , CV_64F);
423
454
424
455
haveCamInfo = false ;
456
+ enable_detections = true ;
425
457
426
458
int dicno;
427
459
@@ -506,18 +538,20 @@ FiducialsNode::FiducialsNode(ros::NodeHandle & nh) : it(nh)
506
538
507
539
image_pub = it.advertise (" /fiducial_images" , 1 );
508
540
509
-
510
541
vertices_pub = new ros::Publisher (nh.advertise <fiducial_msgs::FiducialArray>(" /fiducial_vertices" , 1 ));
511
542
512
543
pose_pub = new ros::Publisher (nh.advertise <fiducial_msgs::FiducialTransformArray>(" /fiducial_transforms" , 1 ));
513
544
514
545
dictionary = aruco::getPredefinedDictionary (dicno);
515
546
516
547
img_sub = it.subscribe (" /camera" , 1 ,
517
- &FiducialsNode::imageCallback, this );
548
+ &FiducialsNode::imageCallback, this );
518
549
519
550
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 );
521
555
522
556
callbackType = boost::bind (&FiducialsNode::configCallback, this , _1, _2);
523
557
configServer.setCallback (callbackType);
0 commit comments