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

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();

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



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

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

Hi @RafBerkvens , @jbohren , I'm facing the same problem, seq is incremented by publisher and I set
message.header.stamp = ros::Time::now(); in a callback function and i don't see anything in stamp while publishing. Please help

divi gravatar image divi  ( 2022-07-07 11:29:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

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 = # Note you need to call rospy.init_node() before this will work
edit flag offensive delete link more


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

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

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

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

Question Tools



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

Seen: 39,284 times

Last updated: Apr 09 '13