Why I got error "msg does not have header"?

asked 2019-06-17 15:42:52 -0500

ZazAa gravatar image

updated 2019-06-17 16:07:50 -0500

jayess gravatar image

Hi,

I try to make a custom message with header to get the timestamp because my aim is to receive data from two topics and generate a graph. After some reading, I found that I need to synchronise the topics and take both topics into a single callback. So I use rostopic delay to check the header of my rostopic. I can get the header from the first custom but no this message.

This is the error:

[ERROR] [1560803887.275108]: msg does not have header

Here are my custom message:

Header header
float32[] distance

Here is my publisher that use the custom message:

#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
def distanceTrav():
   pub = rospy.Publisher('distanceTurtleTravelled', Int32, queue_size=1000)
   rospy.init_node('distanceTurtle', anonymous=True)
   rate = rospy.Rate(1) # 1hz
   dist = 1
   while not rospy.is_shutdown():
      rospy.loginfo(dist)
      pub.publish(dist)
      rate.sleep()
      dist = dist+1
if __name__ == '__main__':
   try:
      distanceTrav()
   except rospy.ROSInterruptException:
      pass

Here is my CMakelist:

cmake_minimum_required(VERSION 2.8.3) 
project(walabot)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  geometry_msgs
  message_generation
)

add_message_files(
  FILES
  signal.msg
  distanceTravelled.msg
)

generate_messages(
  DEPENDENCIES
  std_msgs
)

catkin_package(
  LIBRARIES walabot
  CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)
edit retag flag offensive close merge delete

Comments

In the future, please remove any unnecessary comments to make your question easier to read. I've done that for you here

jayess gravatar imagejayess ( 2019-06-17 16:09:10 -0500 )edit
1

Is this publisher the only node that you're running? I don't see that error when I run it. Also, you posted a custom message, but you're not using it

jayess gravatar imagejayess ( 2019-06-17 16:12:21 -0500 )edit

ah my bad, thank you for pointing that out

ZazAa gravatar imageZazAa ( 2019-06-17 17:47:34 -0500 )edit

Please give all the commands and nodes you run to produce that error output.

Geoff gravatar imageGeoff ( 2019-06-17 21:55:49 -0500 )edit

If you are trying to synchronise an Int32 message, then it won't work. The std_msgs/Int32 message does not have a header. What messages are you trying to synchronise?

Geoff gravatar imageGeoff ( 2019-06-17 21:57:54 -0500 )edit