Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
remove string -> double conversion, make string processing more robus…
Browse files Browse the repository at this point in the history
…t to websocket junk
  • Loading branch information
domluna committed Apr 27, 2017
1 parent 383df45 commit cbd91d5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ double rad2deg(double x) { return x * 180 / pi(); }
std::string hasData(std::string s) {
auto found_null = s.find("null");
auto b1 = s.find_first_of("[");
auto b2 = s.find_last_of("]");
auto b2 = s.rfind("}]");
if (found_null != std::string::npos) {
return "";
} else if (b1 != std::string::npos && b2 != std::string::npos) {
return s.substr(b1, b2 - b1 + 1);
return s.substr(b1, b2 - b1 + 2);
}
return "";
}
Expand All @@ -45,11 +45,11 @@ int main() {
std::string event = j[0].get<std::string>();
if (event == "telemetry") {
// j[1] is the data JSON object
double cte = std::stod(j[1]["cte"].get<std::string>());
double epsi = std::stod(j[1]["epsi"].get<std::string>());
double speed = std::stod(j[1]["speed"].get<std::string>());
double throttle = std::stod(j[1]["throttle"].get<std::string>());
double angle = std::stod(j[1]["steering_angle"].get<std::string>());
double cte = j[1]["cte"];
double epsi = j[1]["epsi"];
double speed = j[1]["speed"];
double throttle = j[1]["throttle"];
double angle = j[1]["steering_angle"];

/*
* TODO: Calculate steeering angle and throttle here.
Expand Down

0 comments on commit cbd91d5

Please sign in to comment.