lanelet2_route_planning v2.0.0
Loading...
Searching...
No Matches
plan_route_action_client Namespace Reference

Classes

struct  is_vector
 
struct  is_vector< std::vector< T, A > >
 
class  PlanRouteActionClient
 Action client node for planning a route. More...
 

Functions

std::optional< std::vector< std::pair< double, double > > > parseWaypoints (const std::vector< std::string > &waypoints_param, std::vector< double > &waypoint_wait_times, const rclcpp::Logger &logger)
 Parses WGS84 waypoints from "<LATITUDE>,<LONGITUDE>[,<WAIT_TIME_S>]" strings.
 

Variables

template<typename C >
constexpr bool is_vector_v = is_vector<C>::value
 

Function Documentation

◆ parseWaypoints()

std::optional< std::vector< std::pair< double, double > > > plan_route_action_client::parseWaypoints ( const std::vector< std::string > & waypoints_param,
std::vector< double > & waypoint_wait_times,
const rclcpp::Logger & logger )

Parses WGS84 waypoints from "<LATITUDE>,<LONGITUDE>[,<WAIT_TIME_S>]" strings.

Parameters
[in]waypoints_paramwaypoint parameter values
[in,out]waypoint_wait_timeswait time for each waypoint
[in]loggerROS logger
Returns
parsed latitude/longitude pairs, or std::nullopt if parsing fails

Definition at line 27 of file plan_route_action_client.cpp.

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}

Variable Documentation

◆ is_vector_v

template<typename C >
bool plan_route_action_client::is_vector_v = is_vector<C>::value
inlineconstexpr

Definition at line 28 of file plan_route_action_client.hpp.