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

Way to modify messages in rostopic without tweaking stuffs in ros driver

asked 2021-10-18 17:04:37 -0600

kidpaul gravatar image

updated 2021-10-18 23:19:44 -0600

This is an example sensor message from my robot topic (/base_imu/data):

header: 
  seq: 286841
  stamp: 
    secs: 1634593671
    nsecs: 585787017
  frame_id: "base_imu_frame"
orientation: 
  x: 0.000403192
  y: 0.019378814
  z: -0.9942339840000001
  w: 0.105465872
orientation_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
angular_velocity: 
  x: 0.00122173
  y: -0.0002138
  z: 0.0
angular_velocity_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
linear_acceleration: 
  x: -0.05120641
  y: -0.39003008
  z: 9.7951648
linear_acceleration_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

As shown above, the covariance matrices are blank and I want to fill this message with my own experimental values. The problem is that I'm currently setting these values by 1) subscribing the topic 2) set the values and publish because I cannot access to a ros driver of this robot and modify the code. However, I personally don't like this method (redundancy & message filtering) and want to try any better way to directly set those values. I appreciate if someone can give me some information regarding this.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-10-19 03:13:16 -0600

gvdhoorn gravatar image

updated 2021-10-19 03:14:47 -0600

The problem is that I'm currently setting these values by 1) subscribing the topic 2) set the values and publish because I cannot access to a ros driver of this robot and modify the code. However, I personally don't like this method (redundancy & message filtering) and want to try any better way to directly set those values.

well, as messages are exchanged peer-to-peer between nodes, unfortunately there isn't a "better way" afaik.

What did you have in mind yourself?

I can only think of one other way to approach this (if we exclude non-ROS-based approaches), and that would be injecting them (ie: your covariances) on the consumer side (ie: the node which subscribes to these messages). If that node is under your control (ie: you can change the source), you could change its subscriber callback to first pre-process the incoming messages.

If it's not under your control, I believe subscribe-process-publish is what you'll need to do,

Note that you don't need to write a "whole new node" for this. topic_tools/transform can do most of the work for you. You just need to provide the correct expression.

edit flag offensive delete link more

Comments

Regarding injecting things by simultaneous dependencies, you can always use the string ros message type and boost serialize to avoid changing your topics and just maintaining an object doing that

Vic gravatar image Vic  ( 2021-10-19 03:18:44 -0600 )edit

I'm not sure I understand your suggestion.

The OP has a robot with a driver which publishes sensor_msgs/Imu messages without the covariance fields set to correct/expected values.

How can std_msgs/String (or string) help in that case?

gvdhoorn gravatar image gvdhoorn  ( 2021-10-19 03:32:33 -0600 )edit

Using boost::serialization and creating a serializable matrix object, you can put it in/out of your string object using the <> operator. For creating a serializable matrix object : https://stackoverflow.com/questions/1...

You set your matrix with correct/expected values. Serialize it, turn it in string. Send in your topic, get it on the other side (assuming you program both the nodes), unserialize it, get the right thing.

Vic gravatar image Vic  ( 2021-10-19 04:04:33 -0600 )edit

Ok, so ignore the typed messaging system completely and (de)serialise (from) to a string (ie: plain memory) and exchange those buffers.

I would not recommend to do that in a typed system like ROS, but that's up to you of course.

Question remains: how would this help the OP with his problem? Where other ROS nodes must be able to consume the updated sensor_msgs/Imu messages? The problem doesn't seem to be receiving the messages, changing them or republishing them. The OP is asking whether there is any "better way".

assuming you program both the nodes

it doesn't seem like that's the case, as the OP writes:

I cannot access to a ros driver of this robot and modify the code.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-19 04:06:09 -0600 )edit

My bad, failed to correctly understand the problem, you're right

Vic gravatar image Vic  ( 2021-10-19 06:20:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-10-18 17:04:37 -0600

Seen: 250 times

Last updated: Oct 19 '21