Parses WGS84 waypoints from "<LATITUDE>,<LONGITUDE>[,<WAIT_TIME_S>]" strings.
29 {
30 std::vector<std::pair<double, double>> waypoints;
31 std::vector<double> parsed_wait_times;
32 for (const auto& waypoint : waypoints_param) {
33 size_t comma_pos = waypoint.find(',');
34 if (comma_pos != std::string::npos) {
35 try {
36 size_t wait_time_comma_pos = waypoint.find(',', comma_pos + 1);
37 if (wait_time_comma_pos != std::string::npos && waypoint.find(',', wait_time_comma_pos + 1) != std::string::npos) {
38 return std::nullopt;
39 }
40 double lat = std::stod(waypoint.substr(0, comma_pos));
41 double lon = std::stod(waypoint.substr(comma_pos + 1, wait_time_comma_pos - comma_pos - 1));
42 double wait_time_s = 0.0;
43 if (wait_time_comma_pos != std::string::npos) {
44 wait_time_s = std::stod(waypoint.substr(wait_time_comma_pos + 1));
45 }
46 waypoints.emplace_back(lat, lon);
47 parsed_wait_times.push_back(wait_time_s);
48 } catch (const std::invalid_argument& e) {
49 return std::nullopt;
50 } catch (const std::out_of_range& e) {
51 return std::nullopt;
52 }
53 } else {
54 return std::nullopt;
55 }
56 }
57
58 if (!parsed_wait_times.empty() && parsed_wait_times.back() < 0.0) {
59 RCLCPP_WARN(logger, "Last waypoint cannot be intermediate, treating it as stop with wait_time_s 0.0");
60 parsed_wait_times.back() = 0.0;
61 }
62
63 waypoint_wait_times = parsed_wait_times;
64 return waypoints;
65}