00001 /*************************************************************************** 00002 * Copyright (C) 2013 by Markus Bader * 00003 * markus.bader@tuwien.ac.at * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 #ifndef ARTOOLKITPLUS_NODE_H 00022 #define ARTOOLKITPLUS_NODE_H 00023 00024 #include <ros/ros.h> 00025 #include <tf/transform_broadcaster.h> 00026 #include <tf/transform_listener.h> 00027 #include <image_transport/image_transport.h> 00028 #include <dynamic_reconfigure/server.h> 00029 #include <tuw_artoolkitplus/ARParamConfig.h> 00030 00031 #include <list> 00032 #include <opencv/cv.h> 00033 #include "ARToolKitPlus/ar.h" 00034 #include "ARToolKitPlus/arMulti.h" 00035 00036 namespace ARToolKitPlus { 00037 class TrackerSingleMarker; 00038 class TrackerMultiMarker; 00039 class Tracker; 00040 00041 00042 00043 class ARTag2D : public ARMarkerInfo { 00044 public: 00045 static const int NO_PATTERN = -1; 00046 static const int PATTERN = 0; 00047 int belongsToPattern; 00048 ARTag2D() 00049 : belongsToPattern(NO_PATTERN) { 00050 } 00051 ARTag2D(const ARTag2D &tag) 00052 : belongsToPattern(tag.belongsToPattern) { 00053 setARMarkerInfo(tag); 00054 } 00055 ARTag2D(const ARMarkerInfo &tag) 00056 : belongsToPattern(NO_PATTERN) { 00057 setARMarkerInfo(tag); 00058 } 00059 void setARMarkerInfo(const ARMarkerInfo &tag) { 00060 ARMarkerInfo *p = (ARMarkerInfo *) this; 00061 *p = tag; 00062 } 00063 }; 00064 00065 }; 00066 00067 00068 class MyLogger; 00069 00070 class ARToolKitPlusNode { 00071 public: 00072 class Parameter { 00073 public: 00074 Parameter(); 00075 void update(const unsigned long &counter); 00076 void callbackParameters ( tuw_artoolkitplus::ARParamConfig &config, uint32_t level ); 00077 ros::NodeHandle node; 00078 dynamic_reconfigure::Server<tuw_artoolkitplus::ARParamConfig> reconfigureServer_; 00079 dynamic_reconfigure::Server<tuw_artoolkitplus::ARParamConfig>::CallbackType reconfigureFnc_; 00080 bool show_camera_image_; 00081 int skip_frames; 00082 std::string node_name; 00083 std::string tf_prefix; 00084 std::string pattern_frame; 00085 std::string pattern_file; 00086 bool useBCH; // simple-id versus BCH-id markers 00087 double patternWidth; // define size of the marker 00088 double borderWidth; 00089 int edge_threshold; 00090 int nPattern; 00091 bool nUpdateMatrix; 00092 bool tracker_single_marker; 00093 bool tracker_multi_marker; 00094 bool use_multi_marker_lite_detection; 00095 bool distorted_input; 00096 int undist_iterations; 00097 int undist_mode; 00098 int pose_estimation_mode; 00099 }; 00100 ARToolKitPlusNode(ros::NodeHandle & n); 00101 ~ARToolKitPlusNode(); 00102 private: 00103 ros::NodeHandle n_; 00104 ros::NodeHandle n_param_; 00105 int callback_counter_; 00106 image_transport::ImageTransport imageTransport_; 00107 image_transport::CameraSubscriber cameraSubscriber_; 00108 tf::TransformBroadcaster transformBroadcaster_; 00109 boost::shared_ptr<ARToolKitPlus::TrackerSingleMarker> trackerSingleMarker_; 00110 boost::shared_ptr<ARToolKitPlus::TrackerMultiMarker> trackerMultiMarker_; 00111 std::vector<ARToolKitPlus::ARTag2D> arTags2D_; 00112 std::list<tf::StampedTransform> markerTransforms_; 00113 const ARToolKitPlus::ARMultiMarkerInfoT *arMultiMarkerInfo_; 00114 MyLogger *logger_; 00115 Parameter param_; 00116 ros::Publisher pub_perceptions_; 00117 00118 void initTrackerSingleMarker(const sensor_msgs::CameraInfoConstPtr& camer_info_); 00119 void initTrackerMultiMarker(const sensor_msgs::CameraInfoConstPtr& camer_info_); 00120 00121 void updateParameterTrackerSingleMarker(const sensor_msgs::CameraInfoConstPtr& camer_info); 00122 void updateParameterTrackerMultiMarker(const sensor_msgs::CameraInfoConstPtr& camer_info); 00123 00124 void imageCallback(const sensor_msgs::ImageConstPtr& image_msg, 00125 const sensor_msgs::CameraInfoConstPtr& info_msg); 00126 void estimatePoses(const std_msgs::Header &header); 00127 void publishTf(); 00128 void publishPerceptions (const std_msgs::Header &header); 00129 void generateDebugImage(cv::Mat &img); 00130 int matrix2Tf(const ARFloat M[3][4], tf::Transform &transform); 00131 void readParam(); 00132 void init(); 00133 00134 }; 00135 00136 #endif // ARTOOLKITPLUS_NODE_H