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

How to retrieve list from ros parameter server that is not comma-separated

asked 2020-05-17 09:55:39 -0600

LukeAI gravatar image

updated 2020-05-17 11:53:22 -0600

I need to be able to read some parameters from my code, (ultimately into openCV matrices)

I can correctly read a parameter from the ros parameter server like this (with commas)

/cam_left_left_info_pub/projection_matrix/data 
[1041.022827, 0.0, 938.549637, 0.0, 0.0, 1045.705078, 602.181309, 0.0, 0.0, 0.0, 1.0, 0.0]
/cam_left_left_info_pub/projection_matrix/rows
3
/cam_left_left_info_pub/projection_matrix/cols
4

using this code:

      // 1D vector for temporarily holding matrix elements
      std::vector<double> _data;

      // matrix dimensions
      int _rows, _cols;

      // read from param server
      nodehandle.getParam(param + std::string("/data"), _data);
      nodehandle.getParam(param + std::string("/rows"), _rows);
      nodehandle.getParam(param + std::string("/cols"), _cols);

      // init matrix and copy
      cv::Mat(_rows, _cols, CV_64F, _data.data()).copyTo(*cv_matrix);

      // check if values were read correctly
      std::cout << "my matrix: " << std::endl << cv_matrix << std::endl;

but this data (NO COMMAS) does not work, the data is read as seemingly random numbers.

/cam_left_left_info_pub/distortion_coefficients/data
[-0.034062 0.026819 0.000826 -0.002720 0.000000]
/cam_left_left_info_pub/distortion_coefficients/rows
1
/cam_left_left_info_pub/distortion_coefficients/cols
5

How Can I read data in the format: [0.1 0.2 0.3] from the rosparameter server into a std::vector?

* EDIT: Context of this problem *

I am writing a camera_info publisher The output of the ROS camera_calibration package

Is a YAML file. Here is a complete example:

image_width: 1920
image_height: 1200
camera_name: narrow_stereo
camera_matrix:
  rows: 3
  cols: 3
  data: [1043.889715, 0.000000, 946.091722, 0.000000, 1045.536555, 601.201155, 0.000000, 0.000000, 1.000000]
distortion_model: plumb_bob
distortion_coefficients:
  rows: 1
  cols: 5
  data: [-0.034062 0.026819 0.000826 -0.002720 0.000000]
rectification_matrix:
  rows: 3
  cols: 3
  data: [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
projection_matrix:
  rows: 3
  cols: 4
  data: [1041.022827, 0.000000, 938.549637, 0.000000, 0.000000, 1045.705078, 602.181309, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]

I publish these values in my launch file like this:

<rosparam file="$(find calibration_publisher)/cfg/$(arg cam_name).yaml" />
edit retag flag offensive close merge delete

Comments

Linking the issue you posted on the ros-perception/image_pipeline tracker: ros-perception/image_pipeline#533.

gvdhoorn gravatar image gvdhoorn  ( 2020-05-17 15:26:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-17 10:58:49 -0600

gvdhoorn gravatar image

The format in which you write down parameters in a launch file (or via rosparam) or even in a plain .yaml file is (as the filename implies): YAML.

YAML supports two notations for lists:

  • on a single line: my_list: [a, b, c, d, .., z], and
  • a more verbose formatting:

    my_list:
      - a
      - b
      - c
      - d
      - ..
      - z
    

No other forms are supported.

So:

How Can I read data in the format: [0.1 0.2 0.3] from the rosparameter server into a std::vector?

I would say "you can't", as what you show is not a valid notation for lists in YAML.

Perhaps it would be good / informative if you could explain why you would like to avoid commas.

edit flag offensive delete link more

Comments

thanks for reply, have edited question to add more context.

LukeAI gravatar image LukeAI  ( 2020-05-17 11:53:41 -0600 )edit

So this is an xy-problem.

gvdhoorn gravatar image gvdhoorn  ( 2020-05-17 15:20:33 -0600 )edit

It's not entirely clear what you want to do, but have you considered using camera_info_manager to do all the heavy lifting?

gvdhoorn gravatar image gvdhoorn  ( 2020-05-17 15:24:26 -0600 )edit

I have a bunch of rosbags with /image_raw but no /cam_info, I am writing a cam_info publisher that reads the YAML and adds the /cam_info (copying across the timestamps and frame from the corresponding image_raw msgs, as they are published.

This node will be used both for replaying historical bags and also for being launched with the camera driver in future to provide the camera_info publications.

I have implemented this myself, partly because I already had some code that did 80% of the work already and I couldn't find any clear easy to understand examples of camera_info_manager and partly because it didn't look too complex and I want to get a good understanding of the nuts and bolts of the ros image pipeline.

LukeAI gravatar image LukeAI  ( 2020-05-17 18:23:09 -0600 )edit

From what you say, it looks like this formatting may be a bug and I simply need to edit all the camera YAMLs to correct them.

LukeAI gravatar image LukeAI  ( 2020-05-17 18:24:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-05-17 09:55:39 -0600

Seen: 418 times

Last updated: May 17 '20