client.cpp
Go to the documentation of this file.
1 
3 
4 namespace yocs {
5 
7 {
8  ros::NodeHandle nh("");
9  global_frame_ = std::string("map");
10  global_marker_prefix_ = std::string("global_marker");
11  target_frame_postfix_ = std::string("target");
12 
13  pub_update_ar_pair_ = nh.advertise<yocs_msgs::ARPairList>("update_ar_pairs", 1, true);
14  sub_global_marker_ = nh.subscribe<ar_track_alvar_msgs::AlvarMarkers>("global_markers", 1, &ARPairTrackingClient::globalMarkersCB, this);
15 
16  tf_broadcast_freq_ = 5.0;
17  boost::thread(&ARPairTrackingClient::broadcastMarkersTF, this);
18 
19  baseline_ = 0.26;
20  target_offset_ = 0.5;
21 }
22 
24 {
25 }
26 
27 void ARPairTrackingClient::globalMarkersCB(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr& msg)
28 {
29  global_markers_ = *msg;
31 
32  ROS_INFO("%lu global marker pose(s) received", global_markers_.markers.size());
33 
35 }
36 
38 {
39  for (unsigned int i = 0; i < global_markers_.markers.size(); i++)
40  {
41  // Compensate the vertical alignment of markers and put at ground level to adopt navistack goals format
42  tf::Transform tf(tf::createQuaternionFromYaw(tf::getYaw(global_markers_.markers[i].pose.pose.orientation) - M_PI/2.0),
43  tf::Vector3(global_markers_.markers[i].pose.pose.position.x, global_markers_.markers[i].pose.pose.position.y, 0.0));
44  tf::StampedTransform marker_gb(tf, ros::Time::now(), global_frame_, "KKKK");
45 
46  // Half turn and translate to put goal at some distance in front of the marker
48  tf::Vector3(1.0, 0.0, 0.0));
49  marker_gb *= in_front;
50 
51  ar_track_alvar_msgs::AlvarMarker kk;
52  mtk::tf2pose(marker_gb, kk.pose);
53  global_markers_mirrors_.markers.push_back(kk);
54 
55  ROS_DEBUG("Marker %d: %s", global_markers_.markers[i].id, mtk::pose2str(global_markers_.markers[i].pose.pose));
56 
57  // TODO: In the current annotation design, it is impossible to record both left and right id of ar marker.
58  }
59 }
60 
62 {
63  unsigned int i;
64  yocs_msgs::ARPairList l;
65 
66  for(i = 0; i < global_markers_.markers.size(); i ++)
67  {
68  ar_track_alvar_msgs::AlvarMarker m = global_markers_.markers[i];
69  yocs_msgs::ARPair p;
70  char frame[32];
71  sprintf(frame, "%s_%d_%s",global_marker_prefix_.c_str(), m.id, target_frame_postfix_.c_str());
72 
73  p.left_id = m.id;
74  p.right_id = m.id - 3;
75  p.baseline = baseline_;
76  p.target_offset = target_offset_;
77  p.target_frame = frame;
78 
79  l.pairs.push_back(p);
80  }
81 
83 }
84 
85 
87 {
89 
90  // TODO semantic map is not broadcasting this already? only docking base no
91  while (ros::ok())
92  {
96  rate.sleep();
97  }
98 
99 }
100 
101 void ARPairTrackingClient::publishTargetTFs(const std::string prefix, const ar_track_alvar_msgs::AlvarMarkers& markers)
102 {
103  char parent_frame[32];
104  char child_frame[32];
106  tf.stamp_ = ros::Time::now();
107 
108  for (unsigned int i = 0; i <markers.markers.size(); i++)
109  {
110  sprintf(parent_frame, "%s_%d", prefix.c_str(), markers.markers[i].id);
111  sprintf(child_frame, "%s_%s", parent_frame, target_frame_postfix_.c_str());
112 
114  tf::Vector3(0, 0, target_offset_));
115  tf::StampedTransform target(tf, ros::Time::now(), parent_frame, child_frame);
116 
117  tf_brcaster_.sendTransform(target);
118  }
119 }
120 
121 void ARPairTrackingClient::publishMarkerTFs(const std::string prefix, const ar_track_alvar_msgs::AlvarMarkers& markers)
122 {
123  char child_frame[32];
125  tf.stamp_ = ros::Time::now();
126 
127  for (unsigned int i = 0; i <markers.markers.size(); i++)
128  {
129  sprintf(child_frame, "%s_%d", prefix.c_str(), markers.markers[i].id);
130  mtk::pose2tf(markers.markers[i].pose, tf);
131  tf.child_frame_id_ = child_frame;
132  tf.stamp_ = ros::Time::now();
134  }
135 }
136 
137 
138 
139 }
140 
141 int main(int argc, char** argv)
142 {
143  ros::init(argc, argv, "ar_pair_client");
145 
146  ros::spin();
147 }
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
void pose2tf(const geometry_msgs::Pose &pose, tf::Transform &tf)
void publish(const boost::shared_ptr< M > &message) const
void globalMarkersCB(const ar_track_alvar_msgs::AlvarMarkers::ConstPtr &msg)
Definition: client.cpp:27
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static double getYaw(const Quaternion &bt_q)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher pub_update_ar_pair_
Definition: client.hpp:35
int main(int argc, char **argv)
Definition: client.cpp:141
ROSCPP_DECL void spin(Spinner &spinner)
std::string target_frame_postfix_
Definition: client.hpp:43
std::string child_frame_id_
void publishMarkerTFs(const std::string prefix, const ar_track_alvar_msgs::AlvarMarkers &markers)
Definition: client.cpp:121
static Quaternion createQuaternionFromYaw(double yaw)
ar_track_alvar_msgs::AlvarMarkers global_markers_mirrors_
Definition: client.hpp:33
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
void sendTransform(const StampedTransform &transform)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
std::string global_frame_
Definition: client.hpp:41
void publishTargetTFs(const std::string prefix, const ar_track_alvar_msgs::AlvarMarkers &markers)
Definition: client.cpp:101
static Time now()
void tf2pose(const tf::Transform &tf, geometry_msgs::Pose &pose)
ar_track_alvar_msgs::AlvarMarkers global_markers_
Definition: client.hpp:33
std::string global_marker_prefix_
Definition: client.hpp:42
ECL_DEPRECATED const char * pose2str(const geometry_msgs::Pose &pose)
tf::TransformBroadcaster tf_brcaster_
Definition: client.hpp:38
ros::Subscriber sub_global_marker_
Definition: client.hpp:34
#define ROS_DEBUG(...)


yocs_ar_pair_tracking
Author(s): Daniel Stonier, Jihoon Lee, Jorge Santos Simon
autogenerated on Mon Jun 10 2019 15:53:47