6 #include <std_msgs/String.h> 12 std::cout <<
"ARPairTracking constructor" << std::endl;
46 ROS_INFO(
"AR Pair Tracking : New Pairs Received");
50 for(i =0; i < msg->pairs.size(); i++)
56 void ARPairTracking::customCB(
const ar_track_alvar_msgs::AlvarMarkers& spotted_markers,
const std::vector<TrackedMarker> &tracked_markers)
58 ar_track_alvar_msgs::AlvarMarker left;
59 ar_track_alvar_msgs::AlvarMarker right;
75 bool ARPairTracking::spotMarkerPair(
const ar_track_alvar_msgs::AlvarMarkers& spotted_markers,
const yocs_msgs::ARPair& pair, ar_track_alvar_msgs::AlvarMarker& left, ar_track_alvar_msgs::AlvarMarker& right)
77 bool left_spotted =
included(pair.left_id, spotted_markers, &left);
78 bool right_spotted =
included(pair.right_id, spotted_markers, &right);
82 if(left_spotted && !right_spotted) {
83 spotted.data =
"left";
84 }
else if(!left_spotted && right_spotted) {
85 spotted.data =
"right";
86 }
else if(left_spotted && right_spotted) {
87 spotted.data =
"both";
89 spotted.data =
"none";
93 return left_spotted && right_spotted;
96 void ARPairTracking::computeRelativeRobotPose(
const yocs_msgs::ARPair& spotted_pair,
const std::vector<TrackedMarker>& tracked_markers,
const ar_track_alvar_msgs::AlvarMarker& left,
const ar_track_alvar_msgs::AlvarMarker& right)
98 double baseline = spotted_pair.baseline;
99 double target_pose_offset = spotted_pair.target_offset;
100 std::string target_pose_frame = spotted_pair.target_frame;
101 double left_x = left.pose.pose.position.x;
102 double left_z = left.pose.pose.position.z;
103 double right_x = right.pose.pose.position.x;
104 double right_z = right.pose.pose.position.z;
106 double left_d = std::sqrt(left_x*left_x + left_z*left_z);
107 double right_d = std::sqrt(right_x*right_x + right_z*right_z);
108 double b = baseline/2 + (left_d*left_d-right_d*right_d)/(2*baseline);
109 double a = std::sqrt(left_d*left_d - b*b);
110 ROS_DEBUG_STREAM(
"AR Pairing Tracker : computing robot-marker relative pose");
111 ROS_DEBUG_STREAM(
"AR Pairing Tracker : left : [" << left_x <<
"," << left_z <<
"," << left_d <<
"]");
112 ROS_DEBUG_STREAM(
"AR Pairing Tracker : right: [" << right_x <<
"," << right_z <<
"," << right_d <<
"]");
114 ROS_DEBUG_STREAM(
"AR Pairing Tracker : 2: " << (left_d*left_d-right_d*right_d)/(2*baseline));
118 double alpha = atan2(left_x, left_z);
119 double alpha_degrees = alpha * (180.0) / M_PI;
122 double beta = atan2(right_x, right_z);
123 double beta_degrees = beta * (180.0) / M_PI;
126 double theta = atan2((left_z - right_z), (right_x - left_x));
127 double theta_degrees = theta * (180.0) / M_PI;
129 double target_x = left_x + (right_x - left_x) / 2 - target_pose_offset * sin(theta);
130 double target_z = left_z + (right_z - left_z) / 2 - target_pose_offset * cos(theta);
131 double target_heading = atan2(target_x, target_z);
132 double target_heading_degrees = target_heading * 180.0 / M_PI;
134 ROS_DEBUG_STREAM(
"AR Pairing Tracker : alpha=" << alpha_degrees <<
"degrees");
135 ROS_DEBUG_STREAM(
"AR Pairing Tracker : beta=" << beta_degrees <<
"degrees");
136 ROS_DEBUG_STREAM(
"AR Pairing Tracker : theta=" << theta_degrees <<
"degrees");
137 ROS_DEBUG_STREAM(
"AR Pairing Tracker : t_[x,z,h]=[" << target_x <<
"," << target_z <<
"," << target_heading_degrees <<
"deg]");
140 geometry_msgs::PoseStamped pose;
142 pose.pose.position.x = target_x;
143 pose.pose.position.y = 0;
144 pose.pose.position.z = target_z;
149 pose.pose.orientation.x = quat.getX();
150 pose.pose.orientation.y = quat.getY();
151 pose.pose.orientation.z = quat.getZ();
152 pose.pose.orientation.w = quat.
getW();
178 pwcs->header.stamp = tf_ar_base_footprint.
stamp_;
181 geometry_msgs::PoseStamped ps;
183 pwcs->pose.pose = ps.pose;
184 pwcs->pose.covariance[6*0+0] = 0.2 * 0.2;
185 pwcs->pose.covariance[6*1+1] = 0.2 * 0.2;
186 pwcs->pose.covariance[6*5+5] = M_PI/12.0 * M_PI/12.0;
void pose2tf(const geometry_msgs::Pose &pose, tf::Transform &tf)
void updateARPairsCB(const yocs_msgs::ARPairList::ConstPtr &msg)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void customCB(const ar_track_alvar_msgs::AlvarMarkers &spotted_markers, const std::vector< TrackedMarker > &tracked_markers)
void computeRelativeRobotPose(const yocs_msgs::ARPair &spotted_pair, const std::vector< TrackedMarker > &tracked_markers, const ar_track_alvar_msgs::AlvarMarker &left, const ar_track_alvar_msgs::AlvarMarker &right)
virtual ~ARPairTracking()
std::string marker_frame_
TFSIMD_FORCE_INLINE const tfScalar & getW() const
const std::string PUB_RELATIVE_TARGET_POSE
ros::Subscriber sub_update_ar_pairs_
std::vector< yocs_msgs::ARPair > ar_pairs_
bool spotted(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers &spotted_markers)
const std::string BASE_FRAME
bool spotMarkerPair(const ar_track_alvar_msgs::AlvarMarkers &spotted_markers, const yocs_msgs::ARPair &pair, ar_track_alvar_msgs::AlvarMarker &left, ar_track_alvar_msgs::AlvarMarker &right)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string MARKER_FRAME
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
tf::TransformBroadcaster tf_brcaster_
#define ROS_DEBUG_STREAM(args)
tf::TransformListener tf_listener_
void setEuler(const tfScalar &yaw, const tfScalar &pitch, const tfScalar &roll)
void addPair(const yocs_msgs::ARPair &p)
const std::string PUB_INITIAL_POSE
const bool PUBLISH_TRANSFORMS
ros::Publisher pub_relative_target_pose_
bool included(const uint32_t id, const ar_track_alvar_msgs::AlvarMarkers &v, ar_track_alvar_msgs::AlvarMarker *e=NULL)
std::string global_frame_
void tf2pose(const tf::Transform &tf, geometry_msgs::Pose &pose)
tf::Transformer tf_internal_
ros::Publisher pub_initial_pose_
const std::string SUB_UPDATE_AR_PAIRS
const std::string GLOBAL_FRAME
ros::Publisher pub_spotted_markers_
const std::string PUB_SPOTTED_MARKERS