00001 #include <nav_msgs/Odometry.h>
00002 #include <ros/ros.h>
00003 #include <stdio.h>
00004 #include <tf/tf.h>
00005 #include <tf/transform_listener.h>
00006 #include <geometry_msgs/PoseWithCovarianceStamped.h>
00007
00008 using namespace std;
00009 using namespace ros;
00010 using namespace nav_msgs;
00011
00012 bool atGoal = false;
00013 geometry_msgs::TransformStamped geo_pose;
00014
00015 void sendGoal(double x, double y, double theta, Publisher pub){
00016
00017 geometry_msgs::PoseStamped goal;
00018
00019
00020
00021 goal.pose.position.x = x;
00022 goal.pose.position.y = y;
00023 goal.pose.position.z = 0;
00024 btQuaternion temp;
00025 temp.setEulerZYX(theta,0,0);
00026 goal.pose.orientation.x = temp.getX();
00027 goal.pose.orientation.y = temp.getY();
00028 goal.pose.orientation.z = temp.getZ();
00029 goal.pose.orientation.w = temp.getW();
00030 goal.header.stamp = ros::Time::now();
00031 goal.header.frame_id = "/map";
00032 pub.publish(goal);
00033 }
00034
00035 void getPose(tf::TransformListener* listener, double* x, double* y, double* th){
00036 tf::StampedTransform transform;
00037 try{
00038 listener->lookupTransform("/map", "/base_footprint", ros::Time(0), transform);
00039 }
00040 catch (tf::TransformException ex){
00041 ROS_ERROR("%s",ex.what());
00042 }
00043
00044 transformStampedTFToMsg(transform, geo_pose);
00045
00046 *x = geo_pose.transform.translation.x;
00047 *y = geo_pose.transform.translation.y;
00048 *th = tf::getYaw(geo_pose.transform.rotation);
00049 }
00050
00051 void sendPose(double x, double y, double theta, Publisher pub){
00052
00053 geometry_msgs::PoseWithCovarianceStamped goal;
00054
00055
00056
00057 goal.pose.pose.position.x = x;
00058 goal.pose.pose.position.y = y;
00059 goal.pose.pose.position.z = 0;
00060 btQuaternion temp;
00061 temp.setEulerZYX(theta,0,0);
00062 goal.pose.pose.orientation.x = temp.getX();
00063 goal.pose.pose.orientation.y = temp.getY();
00064 goal.pose.pose.orientation.z = temp.getZ();
00065 goal.pose.pose.orientation.w = temp.getW();
00066 goal.header.stamp = ros::Time::now();
00067 goal.header.frame_id = "/map";
00068 pub.publish(goal);
00069 }
00070
00071 int main(int argc, char** argv){
00072 ros::init(argc, argv, "demo_sbpl_dynamic_env");
00073
00074
00075 Publisher robotGoal = ros::NodeHandle().advertise<geometry_msgs::PoseStamped>("/move_base_simple/goal", 1);
00076 Publisher robotStart = ros::NodeHandle().advertise<geometry_msgs::PoseWithCovarianceStamped>("/initialpose", 1);
00077 tf::TransformListener listener;
00078
00079 sleep(10.0);
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 double goals[2][3] = {{1.404, 7.161, -0.012}, {15.948, 7.304, 3.141}};
00090
00091 sendPose(goals[0][0], goals[0][1], goals[0][2], robotStart);
00092
00093
00094 ros::NodeHandle n;
00095 double t = ros::Time::now().toSec();
00096 double x,y,th;
00097 while(n.ok()){
00098 t = ros::Time::now().toSec();
00099 atGoal = false;
00100 sendGoal(goals[0][0], goals[0][1], goals[0][2], robotGoal);
00101 while(n.ok() && ros::Time::now().toSec()-t < 180.0 && !atGoal){
00102 getPose(&listener,&x,&y,&th);
00103 double dx = goals[0][0]-x;
00104 double dy = goals[0][1]-y;
00105 double dist = sqrt(dx*dx+dy*dy);
00106 atGoal = dist < 1.0;
00107 ros::Duration(2.0).sleep();
00108 }
00109
00110 t = ros::Time::now().toSec();
00111 atGoal = false;
00112 sendGoal(goals[1][0], goals[1][1], goals[1][2], robotGoal);
00113 while(n.ok() && ros::Time::now().toSec()-t < 180.0 && !atGoal){
00114 getPose(&listener,&x,&y,&th);
00115 double dx = goals[1][0]-x;
00116 double dy = goals[1][1]-y;
00117 double dist = sqrt(dx*dx+dy*dy);
00118 atGoal = dist < 1.0;
00119 ros::Duration(2.0).sleep();
00120 }
00121 }
00122
00123 ros::spin();
00124 }
00125