2 #include <geometry_msgs/PoseWithCovarianceStamped.h>
3 #include <geometry_msgs/PointStamped.h>
6 #include <gps_common/conversions.h>
11 using namespace geometry_msgs;
25 ROS_ERROR_STREAM(
"Could not load empty file path.");
30 file.open(path.c_str());
34 ROS_INFO_STREAM(
"Could not open file: " << path);
46 vector<string> tokens =
split(line,
',');
48 if(tokens.size() != 2)
50 ROS_ERROR_STREAM(path <<
":" << lineIndex <<
" - " << tokens.size() <<
" tokens instead of 2.");
54 auto lat = stof(tokens[0]);
55 auto lon = stof(tokens[1]);
59 gps_common::UTM(lat, lon, &(p.point.x), &(p.point.y));
61 waypoints.push_back(p);
70 return sqrt((p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y));
93 int main(
int argc,
char** argv)
95 ros::init(argc, argv,
"waypoint_source");
98 ros::NodeHandle
nhp(
"~");
100 ROS_INFO_STREAM(
"Has param: " << nhp.hasParam(
"file"));
103 nhp.getParam(
"file", path);
105 ROS_INFO_STREAM(
"Loading waypoints from " << path);
107 waypoint_pub = nh.advertise<PointStamped>(
"/waypoint", 1);
109 ros::Subscriber odom_sub = nh.subscribe(
"/robot_pose_ekf/odom_combined", 1,
positionCallback);
111 ros::Subscriber origin_sub = nh.subscribe(
"/map_origin", 1,
originCallback);
117 ROS_INFO_STREAM(
waypoints.size() <<
" waypoints found.");
122 ROS_INFO(
"publishing current waypoint...");
124 current_waypoint.header.stamp = ros::Time::now();
125 current_waypoint.header.seq++;
126 current_waypoint.header.frame_id =
"map";
133 ROS_ERROR(
"No valid waypoint entries found.");
vector< PointStamped > waypoints
int main(int argc, char **argv)
PointStamped current_waypoint
void positionCallback(const geometry_msgs::PoseWithCovarianceStampedConstPtr &msg)
std::vector< std::string > split(const std::string &s, const char &delim)
void loadWaypointsFile(string path, vector< PointStamped > &waypoints)
ros::Publisher waypoint_pub
double distanceBetweenPoints(const Point &p1, const Point &p2)
void originCallback(const geometry_msgs::PointStampedConstPtr &msg)