ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

No it's not possible to pass a vector 2D directly as a ros2 parameter. You have to define the parameter as a string: setpoints_lla: "[[47.3977507, 8.5456073, 5], [47.39774376, 8.54576301, 6], [47.39781572, 8.54577784, 5], [47.39781739, 8.54558749, 6], [47.3977507, 8.5456073, 0]]"

Then you can pass this to a parser like this (cite to the navigation stack ):

  std::vector<std::vector<float>> parseVVF(const std::string & input, std::string & error_return)
  {
    std::vector<std::vector<float>> result;

    std::stringstream input_ss(input);
    int depth = 0;
    std::vector<float> current_vector;
    while (!!input_ss && !input_ss.eof()) {
      switch (input_ss.peek()) {
      case EOF:
        break;
      case '[':
        depth++;
        if (depth > 2) {
          error_return = "Array depth greater than 2";
          return result;
        }
        input_ss.get();
        current_vector.clear();
        break;
      case ']':
        depth--;
        if (depth < 0) {
          error_return = "More close ] than open [";
          return result;
        }
        input_ss.get();
        if (depth == 1) {
          result.push_back(current_vector);
        }
        break;
      case ',':
      case ' ':
      case '\t':
        input_ss.get();
        break;
      default:  // All other characters should be part of the numbers.
        if (depth != 2) {
          std::stringstream err_ss;
          err_ss << "Numbers at depth other than 2. Char was '" << char(input_ss.peek()) << "'.";
          error_return = err_ss.str();
          return result;
        }
        float value;
        input_ss >> value;
        if (!!input_ss) {
          current_vector.push_back(value);
        }
        break;
      }
    }
    if (depth != 0) {
      error_return = "Unterminated vector string.";
    } else {
      error_return = "";
    }
    return result;
  }