extract_features.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 ***************************************************************************************************/
39 #include "ros/ros.h"
40 #include "std_msgs/String.h"
41 // #include "geometry_msgs/PoseWithCovariance.h"
42 #include "tf/transform_listener.h"
43 #include "mtt/TargetList.h"
44 // #include <visualization_msgs/Marker.h>
45 
46 // static ros::Time start_time;
47 ros::Time time_last_msg(0);
48 ros::Duration time_elapsed;
49 // ros::Duration duration_btw_msg;
50 // ros::Publisher nfeatures_pub;
51 // ros::Publisher marker_pub;
52 
53 tf::TransformListener *p_listener;
54 tf::StampedTransform transform;
55 
56 geometry_msgs::Twist twist;
57 geometry_msgs::Twist features;
58 // geometry_msgs::PoseWithCovariance nfeatures;
59 
60 // std::list<geometry_msgs::PoseWithCovariance> matlab_list;
61 
64 double robot_x, robot_y;
69 uint leader_tag = 0;
70 uint target_id = 0;
71 uint single_target = 0;
72 // uint counter = 0;
73 
74 void targetsCallback(const mtt::TargetList& list)
75 {
76  //will print information that should be stored in a file
77  //file format: id, good/bad tag, time, pos x, pos y, vel, theta
78  // position_diff, heading_diff, angle_to_robot, velocity_diff
79  static ros::Time start_time = ros::Time::now();
80  time_elapsed = ros::Time::now() - start_time;
81 // matlab_list.clear();
82 
84  //use transformations to extract robot features
85  try{
86  p_listener->lookupTransform("/map", "/base_link", ros::Time(0), transform);
87  p_listener->lookupTwist("/map", "/base_link", ros::Time(0), ros::Duration(0.5), twist);
88  }
89  catch (tf::TransformException ex){
90  ROS_ERROR("%s",ex.what());
91  }
92 
93  robot_x = transform.getOrigin().x();
94  robot_y = transform.getOrigin().y();
95  robot_theta = tf::getYaw(transform.getRotation());
96  robot_vel = sqrt(pow(twist.linear.x, 2) + pow(twist.linear.y, 2));
97 
98  //robot output line
100  printf("%d,%d,%.10f,%.10f,%.10f,%.10f,%.10f,0,0,0,0\n",
101  -1, leader_tag, time_elapsed.toSec(),
103 
105  //sweeps target list and extract features
106  for(uint i = 0; i < list.Targets.size(); i++){
107  target_id = list.Targets[i].id;
108  target_x = list.Targets[i].pose.position.x;
109  target_y = list.Targets[i].pose.position.y;
110  target_theta = tf::getYaw(list.Targets[i].pose.orientation);
111  target_vel = sqrt(pow(list.Targets[i].velocity.linear.x,2)+
112  pow(list.Targets[i].velocity.linear.y,2));
113  position_diff = sqrt(pow(robot_x - target_x,2)+
114  pow(robot_y - target_y,2));
116  angle_to_robot = -robot_theta + atan2(target_y - robot_y,
117  target_x - robot_x );
118  velocity_diff = robot_vel - target_vel;
119 
120  //target output (to be used in adaboost training)
121 
122  // % output file format:
123  // % 1: id
124  // % 2: good/bad tag
125  // % 3: time
126  // % 4: pos x
127  // % 5: pos y
128  // % 6: vel
129  // % 7: theta
130  // % 8: pos diff
131  // % 9: head diff
132  // %10: angle 2 robot
133  // %11: velocity diff
134 
136  printf("%d,%d,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f\n",
140 
141 // if(position_diff < 6.0 && target_vel > 0.5){
142 // //if inside boundaries (in meters)
143 // //store features in a covariance struct to send to matlab
144 // nfeatures.pose.position.x = target_x;
145 // nfeatures.pose.position.y = target_y;
146 // nfeatures.pose.position.z = target_id;
147 //
148 // nfeatures.covariance[0] = target_vel;
149 // nfeatures.covariance[1] = velocity_diff;
150 // nfeatures.covariance[2] = heading_diff;
151 // nfeatures.covariance[3] = angle_to_robot;
152 // nfeatures.covariance[4] = position_diff;
153 //
154 // matlab_list.push_back(nfeatures);
155 // // counter++;
156 // }
157  }
158 // printf("targets within range: %d\n",counter);
159 // counter = 0;
160 
161  //check if enough time has passed
162  //and send batch of msgs to matlab
163 // duration_btw_msg = ros::Time::now() - time_last_msg;
164 //
165 // if(duration_btw_msg.toSec() > 0.01){
166 // while(!matlab_list.empty()){
167 // nfeatures_pub.publish(matlab_list.front());
168 // matlab_list.pop_front();
169 // usleep(0.01e6); //has to sleep, otherwise matlab do not get the msg
170 // }
171 // time_last_msg = ros::Time::now();
172 // }
173 }
174 
175 void tagCallback(const std_msgs::Header& tag)
176 {
177  //ROS_INFO("tag received");
178  //only works for a transition good/bad leader
179  leader_tag = 1;
180 }
181 
182 // void drawCallback(const geometry_msgs::Pose& input)
183 // {
184 // visualization_msgs::Marker marker;
185 //
186 // marker.header.frame_id = "/map";
187 // marker.header.stamp = ros::Time::now();
188 //
189 // marker.ns = "quality";
190 // marker.id = 0;
191 //
192 // marker.type = visualization_msgs::Marker::CYLINDER;
193 // marker.action = visualization_msgs::Marker::ADD;
194 //
195 // // Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header
196 // marker.pose.position.x = input.position.x;
197 // marker.pose.position.y = input.position.y;
198 // marker.pose.position.z = 0;
199 // marker.pose.orientation.x = 0.0;
200 // marker.pose.orientation.y = 0.0;
201 // marker.pose.orientation.z = 0.0;
202 // marker.pose.orientation.w = 1.0;
203 //
204 // // Set the scale of the marker
205 // marker.scale.x = 0.5;
206 // marker.scale.y = 0.5;
207 // marker.scale.z = 0.5;
208 //
209 // //good or bad leader
210 // if(input.position.z == -1){
211 // marker.color.r = 0.0f;
212 // marker.color.g = 1.0f;
213 // }
214 // else if (input.position.z == 1){
215 // marker.color.r = 1.0f;
216 // marker.color.g = 0.0f;
217 // }
218 //
219 // marker.color.b = 0.0f;
220 // marker.color.a = 1.0;
221 //
222 // marker.lifetime = ros::Duration();
223 //
224 // // Publish the marker
225 // marker_pub.publish(marker);
226 // }
227 
228 int main(int argc, char **argv)
229 {
230  ros::init(argc, argv, "process_target");
231  ros::NodeHandle n;
232 
233  tf::TransformListener listener;
234  p_listener=&listener;
235 
236  //for testing purposes
237 // single_target = atoi(argv[1]);
238 // ROS_INFO("chosen target:%d",single_target);
239 
240  ros::Subscriber sub = n.subscribe("/targets", 1000, targetsCallback);
241  ros::Subscriber sub_tag = n.subscribe("/timetag", 1000, tagCallback);
242 // ros::Subscriber sub_draw = n.subscribe("/pose_to_draw", 1000, drawCallback);
243 // nfeatures_pub = n.advertise<geometry_msgs::PoseWithCovariance>("/example_topic", 100);
244 // marker_pub = n.advertise<visualization_msgs::Marker>("/leader_quality", 1);
245 
246  ros::spin();
247 
248  return 0;
249 }
geometry_msgs::Twist twist
double target_vel
double position_diff
double robot_theta
uint single_target
tf::StampedTransform transform
double target_y
ros::Duration time_elapsed
double target_x
geometry_msgs::Twist features
tf::TransformListener * p_listener
uint target_id
uint leader_tag
ros::Time time_last_msg(0)
Code for feature extraction.
double angle_to_robot
double robot_y
double velocity_diff
double heading_diff
double target_theta
void tagCallback(const std_msgs::Header &tag)
double robot_x
int main(int argc, char **argv)
void targetsCallback(const mtt::TargetList &list)
double robot_vel


human_leader
Author(s): Procopio Stein
autogenerated on Mon Mar 2 2015 01:31:41