Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse old CSV format #177

Merged
merged 1 commit into from
Dec 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static double _decelerate = 1.0;

static std::vector<WP> _waypoints;

static WP parseWaypoint(const std::string& line)
static WP parseWaypoint(const std::string& line, bool yaw)
{
std::istringstream ss(line);
std::vector<std::string> columns;
Expand All @@ -63,14 +63,37 @@ static WP parseWaypoint(const std::string& line)
}

WP waypoint;
waypoint.pose.position.x = std::stod(columns[0]);
waypoint.pose.position.y = std::stod(columns[1]);
waypoint.pose.position.z = std::stod(columns[2]);
waypoint.pose.orientation = tf::createQuaternionMsgFromYaw(std::stod(columns[3]));
waypoint.velocity_kmh = std::stod(columns[4]);
if (yaw)
{
waypoint.pose.position.x = std::stod(columns[0]);
waypoint.pose.position.y = std::stod(columns[1]);
waypoint.pose.position.z = std::stod(columns[2]);
waypoint.pose.orientation = tf::createQuaternionMsgFromYaw(std::stod(columns[3]));
waypoint.velocity_kmh = std::stod(columns[4]);
}
else
{
waypoint.pose.position.x = std::stod(columns[0]);
waypoint.pose.position.y = std::stod(columns[1]);
waypoint.pose.position.z = std::stod(columns[2]);
waypoint.velocity_kmh = std::stod(columns[3]);
}

return waypoint;
}

static size_t countColumn(const std::string& line)
{
std::istringstream ss(line);
size_t ncol = 0;

std::string column;
while (std::getline(ss, column, ','))
{
++ncol;
}

return ncol;
}

static std::vector<WP> readWaypoint(const char *filename)
Expand All @@ -79,12 +102,40 @@ static std::vector<WP> readWaypoint(const char *filename)
std::string line;

std::getline(ifs, line); // Remove first line
size_t ncol = countColumn(line);

std::vector<WP> waypoints;
while (std::getline(ifs, line))
if (ncol == 3)
{
waypoints.push_back(parseWaypoint(line));

while (std::getline(ifs, line))
{
waypoints.push_back(parseWaypoint(line, false));
}

size_t last = waypoints.size() - 1;
for (size_t i = 0; i < waypoints.size(); ++i)
{
double yaw;
if (i == last)
{
yaw = atan2(waypoints[i-1].pose.position.y - waypoints[i].pose.position.y,
waypoints[i-1].pose.position.x - waypoints[i].pose.position.x);
yaw -= M_PI;
}
else
{
yaw = atan2(waypoints[i+1].pose.position.y - waypoints[i].pose.position.y,
waypoints[i+1].pose.position.x - waypoints[i].pose.position.x);
}
waypoints[i].pose.orientation = tf::createQuaternionMsgFromYaw(yaw);
}
}
else if (ncol == 4)
{
while (std::getline(ifs, line))
{
waypoints.push_back(parseWaypoint(line, true));
}
}

return waypoints;
Expand Down