tracking.hpp
Go to the documentation of this file.
1 /*
2  * ar_marker_processor.hpp
3  *
4  * LICENSE : BSD - https://raw.github.com/yujinrobot/yujin_ocs/license/LICENSE
5  *
6  * Created on: Apr 6, 2013
7  * Author: jorge
8  * Modified on: Dec, 2013
9  * Jihoon Lee
10  *
11  */
12 
13 #ifndef AR_MARKER_PROCESSOR_HPP_
14 #define AR_MARKER_PROCESSOR_HPP_
15 
16 #include <ros/ros.h>
17 
20 
21 #include <geometry_msgs/PoseWithCovarianceStamped.h>
22 #include <ar_track_alvar_msgs/AlvarMarkers.h>
23 
24 namespace yocs
25 {
26 typedef std::list<geometry_msgs::PoseStamped> ObsList;
27 
28 namespace ARMarkerTrackingDefaultParams {
29  const double MAX_VALID_D_INC = 0.8;
30  const double MAX_VALID_H_INC = 4.0;
31  const double MAX_TRACKING_TIME = 2.0;
32  const double MIN_PENALIZED_DIST = 1.4;
33  const double MAX_RELIABLE_DIST = 2.8;
34  const double MIN_PENALIZED_HEAD = 1.0;
35  const double MAX_RELIABLE_HEAD = 1.4;
36 
37  const double AR_TRACKER_FREQ = 10.0;
38 
39  const uint32_t MARKERS_COUNT = 32;
40 
41  const std::string SUB_AR_MARKERS = "ar_track_alvar_msgs/ar_pose_marker";
42  const std::string PUB_ROBOT_POSE_AR = "robot_pose_ar";
43 }
44 
46 {
47  public:
49  {
50  distance = 0.0;
51  distance2d = 0.0;
52  heading = 0.0;
53  confidence = 0.0;
54  conf_distance = 0.0;
55  conf_heading = 0.0;
56  persistence = 0.0;
57  stability = 0.0;
58  }
59 
61  {
62  obs_list_.clear();
63  }
64 
65  // be careful with these - calling lastObservation on an empty list causes undefined behaviour.
66  unsigned int numberOfObservations() const { return obs_list_.size(); }
67  const geometry_msgs::PoseStamped& lastObservation() const { return obs_list_.back(); }
68 
69  ObsList obs_list_;
70  double distance;
71  double distance2d;
72  double heading;
73  double confidence;
74  double conf_distance;
75  double conf_heading;
76  double persistence;
77  double stability;
78 
79 
80  /*********************
81  ** Streaming
82  **********************/
89  template <typename OutputStream>
90  friend OutputStream& operator<<(OutputStream &ostream , const TrackedMarker& marker);
91 };
92 
93 template <typename OutputStream>
94 OutputStream& operator<<(OutputStream &ostream , const TrackedMarker& marker) {
95 
96  if ( marker.numberOfObservations() > 0 ) {
97  // be careful - this is not thread safe.
98  const geometry_msgs::PoseStamped& last_observation = marker.lastObservation();
99  ostream << " Observation\n";
100  ostream << " Timestamp: " << last_observation.header.stamp.toNSec() << "\n";
101  const geometry_msgs::Pose& pose = last_observation.pose;
102  ostream << " x, y, z : [" << pose.position.x << "," << pose.position.y << "," << pose.position.z << "]\n";
103  }
104  ostream << " Distance : " << marker.distance << "\n";
105  ostream << " Distance2d : " << marker.distance2d << "\n";
106  ostream << " Heading : " << marker.heading << "\n";
107  ostream << " Confidence : " << marker.confidence << "\n";
108  ostream << " Conf Dist : " << marker.conf_distance<< "\n";
109  ostream << " Conf Head : " << marker.conf_heading<< "\n";
110  ostream << " Persistence: " << marker.persistence << "\n";
111  ostream << " Stability : " << marker.stability << "\n";
112  ostream.flush();
113  return ostream;
114 }
115 
116 
117 /*****************************************************************************
118 ** Tracking Classes
119 *****************************************************************************/
120 
122 {
123  public:
124 
126  virtual ~ARMarkerTracking();
127 
128  bool init();
129  void spin();
130 
131 
132  protected:
133 
134  // raw list of ar markers from ar_alvar_track pkg
135  void arPoseMarkersCB(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr& msg);
136  virtual void customCB(const ar_track_alvar_msgs::AlvarMarkers& spotted_markers, const std::vector<TrackedMarker> &tracked_markers) {}
137  void maintainTrackedMarkers(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr& msg,std::vector<TrackedMarker>& tracked_markers);
138  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);
139 
141 
149  bool spotted(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& spotted_markers);
150  bool closest(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarker& closest_marker);
151  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);
152  bool closest(const ar_track_alvar_msgs::AlvarMarkers& including, const ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarker& closest_marker);
153 
154  bool spotted(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarkers& spotted);
155  bool closest(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarker& closest_marker);
156 
157  // check if the given id ar_marker is in the list. If yes, return the full ar marker data
158  bool included(const uint32_t id, const ar_track_alvar_msgs::AlvarMarkers& v, ar_track_alvar_msgs::AlvarMarker* e = NULL);
159 
160  // Check if the given id is in the list of ar markers
161  bool excluded(const uint32_t id, const ar_track_alvar_msgs::AlvarMarkers& v);
162 
163  // Confidence evaluation attributes
174  std::vector<TrackedMarker> tracked_markers_;
175  ar_track_alvar_msgs::AlvarMarkers spotted_markers_;
177 
178 // tf::Transformer tf_internal_;
179 // tf::TransformListener tf_listener_;
180 // tf::TransformBroadcaster tf_brcaster_;
181 // double tf_broadcast_freq_; /**< Allows enabling tf broadcasting; mostly for debug */
182 };
183 
184 } /* namespace yocs */
185 
186 #endif /* AR_MARKERS_HPP_ */
const std::string PUB_ROBOT_POSE_AR
Definition: tracking.hpp:42
ar_track_alvar_msgs::AlvarMarkers spotted_markers_
Definition: tracking.hpp:175
std::vector< TrackedMarker > tracked_markers_
Definition: tracking.hpp:174
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
const geometry_msgs::PoseStamped & lastObservation() const
Definition: tracking.hpp:67
const std::string SUB_AR_MARKERS
Definition: tracking.hpp:41
unsigned int numberOfObservations() const
Definition: tracking.hpp:66
OutputStream & operator<<(OutputStream &ostream, const TrackedMarker &marker)
Definition: tracking.hpp:94
ros::Subscriber sub_ar_markers_
Definition: tracking.hpp:176
virtual void customCB(const ar_track_alvar_msgs::AlvarMarkers &spotted_markers, const std::vector< TrackedMarker > &tracked_markers)
Definition: tracking.hpp:136
double heading(geometry_msgs::Point p)
std::list< geometry_msgs::PoseStamped > ObsList
Definition: tracking.hpp:26


yocs_ar_marker_tracking
Author(s): Daniel Stonier, Jorge Santos
autogenerated on Mon Jun 10 2019 15:53:43