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

Is there an easy way to publish std_msgs::Time from cli?

asked 2017-11-06 17:16:33 -0600

seanarm gravatar image

updated 2017-11-08 11:17:16 -0600

I'd like to publish the current ROS time to a topic from the command line. Is there some way to achieve this?

EDIT: Focusing my question a bit more-- I'd like to publish the equivalent of ros::Time::now() from cli.

edit retag flag offensive close merge delete

Comments

Can you add why you can't subscribe to the /clock topic directly?

gvdhoorn gravatar image gvdhoorn  ( 2017-11-07 01:52:46 -0600 )edit

It's for testing a particular node that subscribes to a std_msgs::Time msg. I realize there are other ways to do this, but I was hoping there was a quick way to specify a "now" message from the cli.

seanarm gravatar image seanarm  ( 2017-11-08 11:22:04 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-11-07 00:56:50 -0600

gvdhoorn gravatar image

updated 2017-11-08 11:36:44 -0600

Edit2: ah, I'd completely misunderstood you.

I was hoping there was a quick way to specify a "now" message from the cli.

rostopic pub should actuallys support this.

I'm not sure how well it is documented, but rostopic pub --substitute-keywords .. allows you to use a now keyword that should be substituted with the current time as a timestamp:

  -s, --substitute-keywords
                        When publishing with a rate, performs keyword ('now'
                        or 'auto') substitution for each message

I haven't checked, but you should be able to use something like:

rostopic pub -s -r 1 /some_topic std_msgs/Time 'now'

That publishes ros::Time::now() at a rate of 1 Hz.


Does rostopic pub .. not work for you?

The following works for me:

rostopic pub -r 1 /some_topic std_msgs/Time 'data: { secs: 1, nsecs: 2 }'

Edit: just noticed this:

I'd like to publish the current ROS time to a topic from the command line.

That would seem to be something else.

If I understand you correctly, you'd like to take the messages published on /clock and republish them on a different topic?

I haven't tested it, but topic_tools/transform should be able to do that. It would have to transform a rosgraph_msgs/Clock msg into a std_msgs/Time msg.

The documentation should help to construct the Python expression. #q261935 provides an example.

edit flag offensive delete link more

Comments

VictorLamoine gravatar image VictorLamoine  ( 2017-11-07 01:27:04 -0600 )edit

Question Tools

Stats

Asked: 2017-11-06 17:16:33 -0600

Seen: 4,225 times

Last updated: Nov 08 '17