ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
13

What is the proper way to create a Header with python?

asked 2013-04-08 01:38:36 -0500

updated 2014-01-28 17:16:05 -0500

ngrennan gravatar image

I seem unable to find what the proper procedure is to fill a std_msgs/Header field in a message using python.

I have found this for C++:

my_message message; // using a std_msgs/Header called header
message.header.stamp = ros::Time::now();
message.header.seq++;

This example builds its own timestamp, increases the sequence number (which was not predefined), and ignores the frame field. Is this correct, and, more importantly, what is the equivalent Python code?

edit retag flag offensive close merge delete

Comments

5

You should not set the sequence field, it is set when you publish a message containing the Header.

joq gravatar imagejoq ( 2013-04-08 11:14:08 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
17

answered 2013-04-08 05:35:05 -0500

jbohren gravatar image

updated 2013-04-09 06:12:14 -0500

Necessary imports:

import rospy
import std_msgs.msg

Create the structure:

h = std_msgs.msg.Header()
h.stamp = rospy.Time.now() # Note you need to call rospy.init_node() before this will work
edit flag offensive delete link more

Comments

How does this relate to the comment @joq posted on the original question, stating that the sequence field should not be set?

RafBerkvens gravatar imageRafBerkvens ( 2013-04-08 19:47:49 -0500 )edit
2

Updated the answer, seq is set for you by the publisher.

jbohren gravatar imagejbohren ( 2013-04-09 06:12:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-04-08 01:38:36 -0500

Seen: 15,617 times

Last updated: Apr 09 '13