00001
00002 #include <nav_msgs/Odometry.h>
00003 #include <dynamic_obs_msgs/DynamicObstacles.h>
00004 #include <dynamic_obs_msgs/DynamicObstacle.h>
00005 #include <dynamic_obs_msgs/DynObsTrajectory.h>
00006 #include <geometry_msgs/PoseWithCovarianceStamped.h>
00007 #include <ros/ros.h>
00008 #include <stdio.h>
00009 #include <../include/fake_tracking/fakeTracking.h>
00010
00011 using namespace std;
00012 using namespace ros;
00013 using namespace nav_msgs;
00014 using namespace dynamic_obs_msgs;
00015
00016 FakeTracking::FakeTracking(){
00017
00018 dynObs_pub = n.advertise<dynamic_obs_msgs::DynamicObstacles>("/robot_0/dynamic_obstacles", 1);
00019
00020 DynamicObstacle o1;
00021 o1.radius = 0.5;
00022 DynObsTrajectory t1;
00023 t1.exists_after = false;
00024 t1.probability = 1;
00025 o1.trajectories.push_back(t1);
00026 d.dyn_obs.push_back(o1);
00027 dynObs1_sub = n.subscribe("robot_1/base_pose_ground_truth", 1, &FakeTracking::dynamicObstacleCallback1,this);
00028
00029 DynamicObstacle o2;
00030 o2.radius = 0.5;
00031 DynObsTrajectory t2;
00032 t2.exists_after = false;
00033 t2.probability = 1;
00034 o2.trajectories.push_back(t2);
00035 d.dyn_obs.push_back(o2);
00036 dynObs2_sub = n.subscribe("robot_2/base_pose_ground_truth", 1, &FakeTracking::dynamicObstacleCallback2,this);
00037
00038 DynamicObstacle o3;
00039 o3.radius = 0.5;
00040 DynObsTrajectory t3;
00041 t3.exists_after = false;
00042 t3.probability = 1;
00043 o3.trajectories.push_back(t3);
00044 d.dyn_obs.push_back(o3);
00045 dynObs3_sub = n.subscribe("robot_3/base_pose_ground_truth", 1, &FakeTracking::dynamicObstacleCallback3,this);
00046
00047 DynamicObstacle o4;
00048 o4.radius = 0.5;
00049 DynObsTrajectory t4;
00050 t4.exists_after = false;
00051 t4.probability = 1;
00052 o4.trajectories.push_back(t4);
00053 d.dyn_obs.push_back(o4);
00054 dynObs4_sub = n.subscribe("robot_4/base_pose_ground_truth", 1, &FakeTracking::dynamicObstacleCallback4,this);
00055 }
00056
00057 void FakeTracking::dynamicObstacleCallback1(const nav_msgs::OdometryConstPtr& msg){
00058 int idx = 0;
00059
00060 double x = msg->pose.pose.position.x;
00061 double y = msg->pose.pose.position.y;
00062 double t = msg->header.stamp.toSec();
00063
00064 double pred_sec = 20;
00065 double t_gran = 0.1;
00066
00067 if(d.dyn_obs[idx].trajectories[0].points.empty()){
00068 for(int i=0; i<pred_sec/t_gran+1; i++){
00069 geometry_msgs::PoseWithCovarianceStamped p;
00070 p.pose.pose.position.x = x;
00071 p.pose.pose.position.y = y;
00072 p.header.stamp = ros::Time(t + i*t_gran);
00073 p.header.frame_id = msg->header.frame_id;
00074 for(int i=0; i<36; i++)
00075 p.pose.covariance[i] = 0;
00076 p.pose.pose.orientation.w = 1;
00077 d.dyn_obs[idx].trajectories[0].points.push_back(p);
00078 }
00079 }
00080 else{
00081 double delta_t = t - d.dyn_obs[idx].trajectories[0].points[0].header.stamp.toSec();
00082 double x_dot = (x-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.x)/delta_t;
00083 double y_dot = (y-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.y)/delta_t;
00084
00085 for(int i=0; i<pred_sec/t_gran+1; i++){
00086 double timestep = i*t_gran;
00087 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.x = x + x_dot*timestep;
00088 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.y = y + y_dot*timestep;
00089 d.dyn_obs[idx].trajectories[0].points[i].header.stamp = ros::Time(t + timestep);
00090 }
00091 }
00092
00093 d.header.stamp = msg->header.stamp;
00094 d.header.frame_id = msg->header.frame_id;
00095 dynObs_pub.publish(d);
00096 }
00097
00098 void FakeTracking::dynamicObstacleCallback2(const nav_msgs::OdometryConstPtr& msg){
00099 int idx = 1;
00100
00101 double x = msg->pose.pose.position.x;
00102 double y = msg->pose.pose.position.y;
00103 double t = msg->header.stamp.toSec();
00104
00105 double pred_sec = 20;
00106 double t_gran = 0.1;
00107
00108 if(d.dyn_obs[idx].trajectories[0].points.empty()){
00109 for(int i=0; i<pred_sec/t_gran+1; i++){
00110 geometry_msgs::PoseWithCovarianceStamped p;
00111 p.pose.pose.position.x = x;
00112 p.pose.pose.position.y = y;
00113 p.header.stamp = ros::Time(t + i*t_gran);
00114 p.header.frame_id = msg->header.frame_id;
00115 for(int i=0; i<36; i++)
00116 p.pose.covariance[i] = 0;
00117 p.pose.pose.orientation.w = 1;
00118 d.dyn_obs[idx].trajectories[0].points.push_back(p);
00119 }
00120 }
00121 else{
00122 double delta_t = t - d.dyn_obs[idx].trajectories[0].points[0].header.stamp.toSec();
00123 double x_dot = (x-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.x)/delta_t;
00124 double y_dot = (y-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.y)/delta_t;
00125
00126 for(int i=0; i<pred_sec/t_gran+1; i++){
00127 double timestep = i*t_gran;
00128 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.x = x + x_dot*timestep;
00129 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.y = y + y_dot*timestep;
00130 d.dyn_obs[idx].trajectories[0].points[i].header.stamp = ros::Time(t + timestep);
00131 }
00132 }
00133
00134 d.header.stamp = msg->header.stamp;
00135 d.header.frame_id = msg->header.frame_id;
00136 dynObs_pub.publish(d);
00137 }
00138
00139 void FakeTracking::dynamicObstacleCallback3(const nav_msgs::OdometryConstPtr& msg){
00140 int idx = 2;
00141
00142 double x = msg->pose.pose.position.x;
00143 double y = msg->pose.pose.position.y;
00144 double t = msg->header.stamp.toSec();
00145
00146 double pred_sec = 20;
00147 double t_gran = 0.1;
00148
00149 if(d.dyn_obs[idx].trajectories[0].points.empty()){
00150 for(int i=0; i<pred_sec/t_gran+1; i++){
00151 geometry_msgs::PoseWithCovarianceStamped p;
00152 p.pose.pose.position.x = x;
00153 p.pose.pose.position.y = y;
00154 p.header.stamp = ros::Time(t + i*t_gran);
00155 p.header.frame_id = msg->header.frame_id;
00156 for(int i=0; i<36; i++)
00157 p.pose.covariance[i] = 0;
00158 p.pose.pose.orientation.w = 1;
00159 d.dyn_obs[idx].trajectories[0].points.push_back(p);
00160 }
00161 }
00162 else{
00163 double delta_t = t - d.dyn_obs[idx].trajectories[0].points[0].header.stamp.toSec();
00164 double x_dot = (x-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.x)/delta_t;
00165 double y_dot = (y-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.y)/delta_t;
00166
00167 for(int i=0; i<pred_sec/t_gran+1; i++){
00168 double timestep = i*t_gran;
00169 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.x = x + x_dot*timestep;
00170 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.y = y + y_dot*timestep;
00171 d.dyn_obs[idx].trajectories[0].points[i].header.stamp = ros::Time(t + timestep);
00172 }
00173 }
00174
00175 d.header.stamp = msg->header.stamp;
00176 d.header.frame_id = msg->header.frame_id;
00177 dynObs_pub.publish(d);
00178 }
00179
00180 void FakeTracking::dynamicObstacleCallback4(const nav_msgs::OdometryConstPtr& msg){
00181 int idx = 3;
00182
00183 double x = msg->pose.pose.position.x;
00184 double y = msg->pose.pose.position.y;
00185 double t = msg->header.stamp.toSec();
00186
00187 double pred_sec = 20;
00188 double t_gran = 0.1;
00189
00190 if(d.dyn_obs[idx].trajectories[0].points.empty()){
00191 for(int i=0; i<pred_sec/t_gran+1; i++){
00192 geometry_msgs::PoseWithCovarianceStamped p;
00193 p.pose.pose.position.x = x;
00194 p.pose.pose.position.y = y;
00195 p.header.stamp = ros::Time(t + i*t_gran);
00196 p.header.frame_id = msg->header.frame_id;
00197 for(int i=0; i<36; i++)
00198 p.pose.covariance[i] = 0;
00199 p.pose.pose.orientation.w = 1;
00200 d.dyn_obs[idx].trajectories[0].points.push_back(p);
00201 }
00202 }
00203 else{
00204 double delta_t = t - d.dyn_obs[idx].trajectories[0].points[0].header.stamp.toSec();
00205 double x_dot = (x-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.x)/delta_t;
00206 double y_dot = (y-d.dyn_obs[idx].trajectories[0].points[0].pose.pose.position.y)/delta_t;
00207
00208 for(int i=0; i<pred_sec/t_gran+1; i++){
00209 double timestep = i*t_gran;
00210 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.x = x + x_dot*timestep;
00211 d.dyn_obs[idx].trajectories[0].points[i].pose.pose.position.y = y + y_dot*timestep;
00212 d.dyn_obs[idx].trajectories[0].points[i].header.stamp = ros::Time(t + timestep);
00213 }
00214 }
00215
00216 d.header.stamp = msg->header.stamp;
00217 d.header.frame_id = msg->header.frame_id;
00218 dynObs_pub.publish(d);
00219 }
00220
00221
00222 int main(int argc, char** argv){
00223 ros::init(argc, argv, "fake_tracking");
00224 FakeTracking f;
00225 ros::spin();
00226 }
00227