ar_human_proc.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 #include "ros/ros.h"
28 #include "ar_human_proc.h"
29 // #include <tf/transform_broadcaster.h>
30 
31 #define DEG2RAD 0.01745
32 
33 /*******
34 This node gets data from ar_pose and publishes structures for humanPoses.
35 There are two classes ar_humanProc and ar_pose_reader.
36 ********/
37 
38 ar_pose_reader::ar_pose_reader(std_msgs::String topic_name,ros::NodeHandle* n)
39 {
40  local_n=n;
41  name.data.assign(topic_name.data);
42 }
43 
45 {
46  //initialize fields
47 // local_ped.x=0.0;
48 // local_ped.y=0.0;
49 // local_ped.theta= 0.0; //in degrees
50 // local_ped.linear_velocity=0.0;
51 // local_ped.angular_velocity=0.0;
52 
53  //subscribe to ar_pose messages
54  ar_pose_sub = local_n->subscribe(name.data.c_str(), 15, &ar_pose_reader::ar_pose_callback,this);
55 
56  for(int i = 0; i < list_size; i++){
57 // markers_list[i].type = 0;
59  }
60 
61 }
62 
63 void ar_pose_reader::ar_pose_callback(const ar_pose::ARMarkers::ConstPtr& markers)
64 {
65  //receives a list of marker poses and build a list of human_poses
66  num_markers = markers->markers.size();
67 // ROS_INFO("number of markers: [%d]", num_markers);
68 
69 // list_ped.humans.clear();
70 
71  for(int i=0; i< num_markers; i++){
72 
73  //feeding pose structure from ar_pose
74  source_pose.header = markers->markers[i].header;
75  source_pose.pose = markers->markers[i].pose.pose;
76  marker_id = markers->markers[i].id;
77  int confidence = markers->markers[i].confidence;
78 
79  //transform pose to /map frame
80  try{
81 // ros::Time now = ros::Time::now();
82 // listener.waitForTransform("/prosilica_optical_frame", "/map", source_pose.header.stamp, ros::Duration(10.0));
83 // listener.waitForTransform("/usb_cam", "/map", source_pose.header.stamp, ros::Duration(10.0));
84  listener.transformPose("/map",source_pose,target_pose);
85  }
86  catch (tf::TransformException ex) {
87  ROS_ERROR("%s", ex.what());
88  return;
89  }
90 
91 
92 // ROS_INFO("confidence:%d",confidence);
93  //only process markers with high confidence
94  if(confidence > 60){
95 
96 // //retrieve pose values and feed into human_pose structure
97 // local_ped.id = marker_id;
98 // local_ped.header.frame_id = target_pose.header.frame_id;
99 // local_ped.header.stamp = target_pose.header.stamp;
100 // local_ped.x = target_pose.pose.position.x;
101 // local_ped.y = target_pose.pose.position.y;
102 // local_ped.theta = tf::getYaw(target_pose.pose.orientation); //in radians
103 // local_ped.linear_velocity = 0.0;
104 // local_ped.angular_velocity = 0.0;
105 // list_ped.humans.push_back(local_ped); //append to the end of the list
106 
108 
109  //check if there is a large jump in tracked markers
110  double distance = euclidean_dist(
111  markers_list[marker_id].ghmm_wrapper.pose.x,
112  markers_list[marker_id].ghmm_wrapper.pose.y,
113  target_pose.pose.position.x,
114  target_pose.pose.position.y);
115 
116  if(markers_list[marker_id].ghmm_wrapper.type == 0 && distance > 5.0){
117  ROS_INFO("distance:%f",distance);
118 
119 // ROS_INFO("not publishing");
120  }
121 
122 // ROS_INFO("distance:%f",distance);
123 
124 
125  // if(markers_list[marker_id].type == 0 && distance > 5.0){
126  // ROS_INFO("distance:%f",distance);
127  // ROS_INFO("not publishing");
128  // } else{
129  //ghmm wrapper
131 // markers_list[marker_id].ghmm_wrapper.type = markers_list[marker_id].type;
132  markers_list[marker_id].ghmm_wrapper.header.frame_id = target_pose.header.frame_id;
133  markers_list[marker_id].ghmm_wrapper.header.stamp = target_pose.header.stamp;
134  markers_list[marker_id].ghmm_wrapper.pose.x = target_pose.pose.position.x;
135  markers_list[marker_id].ghmm_wrapper.pose.y = target_pose.pose.position.y;
136  markers_list[marker_id].ghmm_wrapper.pose.theta = tf::getYaw(target_pose.pose.orientation);//radians
137 
138  ROS_INFO("id:%d,type:%d",markers_list[marker_id].ghmm_wrapper.object_id,
139  markers_list[marker_id].ghmm_wrapper.type);
140 
142  trajectory_pub.publish(markers_list[marker_id].ghmm_wrapper);
143  // }
144  } else {
145  ROS_INFO("confidence too low:%d",confidence);
146  }
147  }
148 
149 }
150 
152  markers_list[marker_id].detect_time = ros::Time::now();
153  if(markers_list[marker_id].ghmm_wrapper.type == 2){
154  markers_list[marker_id].ghmm_wrapper.type = 1; //first detection
155  ROS_INFO("MARKER %d DETECTED",marker_id);
156  }
157  else if(markers_list[marker_id].ghmm_wrapper.type == 1){
158  markers_list[marker_id].ghmm_wrapper.type = 0; //has been detected before
159  }
160 }
161 
162 // void manage_list(int marker_id){
163 // markers_list[marker_id].detect_time = ros::Time::now();
164 // if(markers_list[marker_id].type == 2){
165 // markers_list[marker_id].type = 1; //first detection
166 // ROS_INFO("MARKER %d DETECTED",marker_id);
167 // }
168 // else if(markers_list[marker_id].type == 1){
169 // markers_list[marker_id].type = 0; //has been detected before
170 // }
171 // }
172 
174 {
175  //advertise topic to publish human positions
176  pose_pub = n.advertise<social_filter::humanPoses>("human_poses", 15);
177 
178  //advertise topic to publish human positions for GHMM
179  trajectory_pub = n.advertise<trajectory_simulator::TrajectoryObservation>("dynamic_objects", 15);
180 }
181 
183 {
184  //instantiate reader class
185  std_msgs::String msg;
186  std::stringstream ss;
187  ss<<"/ar_pose_marker";
188  msg.data = ss.str();
189 // std_msgs::String ar_pose_topic = "/ar_pose_marker";
190 // ar_pose_reader* reader_ptr = new ar_pose_reader(ar_pose_topic, &n);
191  ar_pose_reader* reader_ptr = new ar_pose_reader(msg, &n);
192  reader_ptr->init();
193  readers.push_back(reader_ptr);
194 }
195 
196 
198 {
199 // pose_pub.publish(list_ped);
200 }
201 
202 
204 {
205 // for(unsigned int i=0; i< readers.size();i++)
206 // delete readers[i];
207 }
208 
209 
210 int main(int argc, char **argv)
211 {
212  ros::init(argc, argv, "ar_human_processes");
213  ar_humanProc h_processor;
214  h_processor.init();
215  ros::Rate loop_rate(10);
216 
217  while (ros::ok())
218  {
219  h_processor.pub();
220  ros::spinOnce();
221  loop_rate.sleep();
222 
223  //iterate along n markers
224  for(int i = 0; i < list_size; i++){
225  duration_since_detection = ros::Time::now() - markers_list[i].detect_time;
226 // ROS_INFO("DURATION: %f", duration_since_detection.toSec());
227 
228  //if time in list entry is bigger then
229  //threshold and not type 2 change to type 2
230  if (duration_since_detection.toSec() > 1.0 && markers_list[i].ghmm_wrapper.type != 2){
231 // markers_list[i].type = 2;
233  ROS_INFO("MARKER %d DISAPPEARED",i);
234 
235 // markers_list[marker_id].ghmm_wrapper.object_id
236  ROS_INFO("id:%d,type:%d",markers_list[i].ghmm_wrapper.object_id,
238 
240  trajectory_pub.publish(markers_list[i].ghmm_wrapper);
241  }
242  }
243  }
244 
245  return 0;
246 }
247 
tf::TransformListener listener
Definition: ar_human_proc.h:83
void ar_pose_callback(const ar_pose::ARMarkers::ConstPtr &)
ros::NodeHandle n
ros::Duration duration_since_detection
Definition: ar_human_proc.h:51
int list_size
Definition: ar_human_proc.h:52
ros::NodeHandle * local_n
Definition: ar_human_proc.h:77
std::vector< ar_pose_reader * > readers
ros::Publisher pose_pub
int marker_id
Definition: ar_human_proc.h:50
ros::Publisher trajectory_pub
Definition: ar_human_proc.h:49
double euclidean_dist(double x1, double y1, double x2, double y2)
Definition: ar_human_proc.h:64
ros::Subscriber ar_pose_sub
Definition: ar_human_proc.h:78
geometry_msgs::PoseStamped target_pose
Definition: ar_human_proc.h:85
std_msgs::String name
Definition: ar_human_proc.h:80
geometry_msgs::PoseStamped source_pose
Definition: ar_human_proc.h:84
ros::Time detect_time
Definition: ar_human_proc.h:56
trajectory_simulator::TrajectoryObservation ghmm_wrapper
Definition: ar_human_proc.h:57
::geometry_msgs::Pose2D_< ContainerAllocator > pose
::std_msgs::Header_< ContainerAllocator > header
ar_management markers_list[10]
Definition: ar_human_proc.h:60
void manage_list(int marker_id)
int main(int argc, char **argv)
ar_pose_reader(std_msgs::String topic_name, ros::NodeHandle *n)


leader_follower
Author(s): Procopio Silveira Stein
autogenerated on Mon Mar 2 2015 01:32:07