Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef AR_MARKER_PROCESSOR_HPP_
00014 #define AR_MARKER_PROCESSOR_HPP_
00015
00016 #include <ros/ros.h>
00017
00018 #include <yocs_math_toolkit/common.hpp>
00019 #include <yocs_math_toolkit/geometry.hpp>
00020
00021 #include <geometry_msgs/PoseWithCovarianceStamped.h>
00022 #include <ar_track_alvar_msgs/AlvarMarkers.h>
00023
00024 namespace yocs
00025 {
00026 typedef std::list<geometry_msgs::PoseStamped> ObsList;
00027
00028 namespace ARMarkerTrackingDefaultParams {
00029 const double MAX_VALID_D_INC = 0.8;
00030 const double MAX_VALID_H_INC = 4.0;
00031 const double MAX_TRACKING_TIME = 2.0;
00032 const double MIN_PENALIZED_DIST = 1.4;
00033 const double MAX_RELIABLE_DIST = 2.8;
00034 const double MIN_PENALIZED_HEAD = 1.0;
00035 const double MAX_RELIABLE_HEAD = 1.4;
00036
00037 const double AR_TRACKER_FREQ = 10.0;
00038
00039 const uint32_t MARKERS_COUNT = 32;
00040
00041 const std::string SUB_AR_MARKERS = "ar_track_alvar_msgs/ar_pose_marker";
00042 const std::string PUB_ROBOT_POSE_AR = "robot_pose_ar";
00043 }
00044
00045 class TrackedMarker
00046 {
00047 public:
00048 TrackedMarker()
00049 {
00050 distance = 0.0;
00051 distance2d = 0.0;
00052 heading = 0.0;
00053 confidence = 0.0;
00054 conf_distance = 0.0;
00055 conf_heading = 0.0;
00056 persistence = 0.0;
00057 stability = 0.0;
00058 }
00059
00060 ~TrackedMarker()
00061 {
00062 obs_list_.clear();
00063 }
00064
00065
00066 unsigned int numberOfObservations() const { return obs_list_.size(); }
00067 const geometry_msgs::PoseStamped& lastObservation() const { return obs_list_.back(); }
00068
00069 ObsList obs_list_;
00070 double distance;
00071 double distance2d;
00072 double heading;
00073 double confidence;
00074 double conf_distance;
00075 double conf_heading;
00076 double persistence;
00077 double stability;
00078
00079
00080
00081
00082
00089 template <typename OutputStream>
00090 friend OutputStream& operator<<(OutputStream &ostream , const TrackedMarker& marker);
00091 };
00092
00093 template <typename OutputStream>
00094 OutputStream& operator<<(OutputStream &ostream , const TrackedMarker& marker) {
00095
00096 if ( marker.numberOfObservations() > 0 ) {
00097
00098 const geometry_msgs::PoseStamped& last_observation = marker.lastObservation();
00099 ostream << " Observation\n";
00100 ostream << " Timestamp: " << last_observation.header.stamp.toNSec() << "\n";
00101 const geometry_msgs::Pose& pose = last_observation.pose;
00102 ostream << " x, y, z : [" << pose.position.x << "," << pose.position.y << "," << pose.position.z << "]\n";
00103 }
00104 ostream << " Distance : " << marker.distance << "\n";
00105 ostream << " Distance2d : " << marker.distance2d << "\n";
00106 ostream << " Heading : " << marker.heading << "\n";
00107 ostream << " Confidence : " << marker.confidence << "\n";
00108 ostream << " Conf Dist : " << marker.conf_distance<< "\n";
00109 ostream << " Conf Head : " << marker.conf_heading<< "\n";
00110 ostream << " Persistence: " << marker.persistence << "\n";
00111 ostream << " Stability : " << marker.stability << "\n";
00112 ostream.flush();
00113 return ostream;
00114 }
00115
00116
00117
00118
00119
00120
00121 class ARMarkerTracking
00122 {
00123 public:
00124
00125 ARMarkerTracking();
00126 virtual ~ARMarkerTracking();
00127
00128 bool init();
00129 void spin();
00130
00131
00132 protected:
00133
00134
00135 void arPoseMarkersCB(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr& msg);
00136 virtual void customCB(const ar_track_alvar_msgs::AlvarMarkers& spotted_markers, const std::vector<TrackedMarker> &tracked_markers) {}
00137 void maintainTrackedMarkers(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr& msg,std::vector<TrackedMarker>& tracked_markers);
00138 void maintainTrackedMarker(TrackedMarker& marker,const ar_track_alvar_msgs::AlvarMarker& msgMarker, const int obs_list_max_size, const double max_valid_d_inc, const double max_valid_h_inc);
00139
00141
00149 bool spotted(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& spotted_markers);
00150 bool closest(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarker& closest_marker);
00151 bool spotted(double younger_than, const ar_track_alvar_msgs::AlvarMarkers& including, const ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarkers& spotted_markers);
00152 bool closest(const ar_track_alvar_msgs::AlvarMarkers& including, const ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarker& closest_marker);
00153
00154 bool spotted(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarkers& spotted);
00155 bool closest(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarker& closest_marker);
00156
00157
00158 bool included(const uint32_t id, const ar_track_alvar_msgs::AlvarMarkers& v, ar_track_alvar_msgs::AlvarMarker* e = NULL);
00159
00160
00161 bool excluded(const uint32_t id, const ar_track_alvar_msgs::AlvarMarkers& v);
00162
00163
00164 double min_penalized_dist_;
00165 double max_reliable_dist_;
00166 double min_penalized_head_;
00167 double max_reliable_head_;
00168 double max_tracking_time_;
00169 double max_valid_d_inc_;
00170 double max_valid_h_inc_;
00171 double ar_tracker_freq_;
00174 std::vector<TrackedMarker> tracked_markers_;
00175 ar_track_alvar_msgs::AlvarMarkers spotted_markers_;
00176 ros::Subscriber sub_ar_markers_;
00177
00178
00179
00180
00181
00182 };
00183
00184 }
00185
00186 #endif