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

Revision history [back]

click to hide/show revision 1
initial version

I'm more familiar with ROS2 than ROS1, but it could be the lines:

current_time = rospy.Time.now()
h.stamp = current_time

The stamp component of the Header message must be a Time message: std_msgs/Time

stamp being a time message is shown here: std_msgs/Header

Double-check the return-value of rospy.Time.now(). It might be giving you some python Time object that you need to convert to a Time message object.

I was getting a similar error with ROS2 and rclpy when publishing odometry information:

    # Somewhere in a callback function...

    **current_time = self.get_clock().now()**

    q = Quaternion()
    q.x = 0.0
    q.y = 0.0
    q.z = sin(self.position_theta / 2)
    q.w = cos(self.position_theta / 2)

    t = TransformStamped()
    **t.header.stamp = current_time.to_msg()**
    t.header.frame_id = self.odom_frame_id
    t.child_frame_id = self.base_frame_id
    t.transform.translation.x = self.position_x
    t.transform.translation.y = self.position_y
    t.transform.translation.z = 0.0
    t.transform.rotation = q
    self.transform_broadcaster.sendTransform(t)

The ROS2 rclpy Time objects have a Time.to_msg() function to handle this.

You will either need to separately create a Time message and do h.stamp = time_msg, or you will need to see if you can just do h.stamp = current_time.to_msg() or similar.

Good luck!

I'm more familiar with ROS2 than ROS1, but it could be the lines:

current_time = rospy.Time.now()
h.stamp = current_time

The stamp component of the Header message must be a Time message: std_msgs/Time

stamp being a time message is shown here: std_msgs/Header

Double-check the return-value of rospy.Time.now(). It might be giving you some python Time object that you need to convert to a Time message object.

I was getting a similar error with ROS2 and rclpy when publishing odometry information:

    # Somewhere in a callback function...

    **current_time = self.get_clock().now()**
current_time = self.get_clock().now()  # Here I grab the current time, rclpy function is slightly different from rospy

    q = Quaternion()
    q.x = 0.0
    q.y = 0.0
    q.z = sin(self.position_theta / 2)
    q.w = cos(self.position_theta / 2)

    t = TransformStamped()
    **t.header.stamp = current_time.to_msg()**
t.header.stamp = current_time.to_msg()  # Here the time is converted to a Time message when we set 'stamp'
    t.header.frame_id = self.odom_frame_id
    t.child_frame_id = self.base_frame_id
    t.transform.translation.x = self.position_x
    t.transform.translation.y = self.position_y
    t.transform.translation.z = 0.0
    t.transform.rotation = q
    self.transform_broadcaster.sendTransform(t)

The ROS2 rclpy Time objects have a Time.to_msg() function to handle this.

You will either need to separately create a Time message and do h.stamp = time_msg, or you will need to see if you can just do h.stamp = current_time.to_msg() or similar.

Good luck!