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

I have an error trying to subscribe to multiple topics, between them there are two of the same type, this is the error, please what can I do ?

asked 2019-12-18 10:01:24 -0500

Juan Carlos gravatar image

updated 2019-12-18 13:29:50 -0500

jayess gravatar image

this is the code:

#! /usr/bin/env python
import serial
import rospy
import message_filters
import numpy as np

from sensor_msgs.msg import Imu
from nav_msgs.msg import Odometry
from std_msgs.msg import Float32


class adq_datos(object):
        def __init__(self):
                self.datos = 0

                self.pwm = message_filters.Subscriber('/PWM', Float32)
                self.encoder = message_filters.Subscriber('/enc_data', Odometry)
                self.gps = message_filters.Subscriber('/gps', Float32)
                self.imu = message_filters.Subscriber('/mti/sensor/imu_free', Imu)

                self.ts = message_filters.TimeSynchronizer([self.pwm, self.encoder, self.gps, self.imu], 10)
                self.ts.registerCallback(self.synchronize_data)
                rospy.spin()

        def synchronize_data(self, data):
                self.datos = data.pose.covariance[5]
                print self.datos

if __name__=='__main__':
        try:
                rospy.init_node('save_data',anonymous=True, disable_signals=True)
                print "Nodo Creado"
                cv = adq_datos()
        except rospy.ROSInterruptException:
                pass

this is the error that show

[ERROR] [1576621538.678741]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x75b23850>>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
    self.signalMessage(msg)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
    cb(*(msg + args))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 216, in add
    my_queue[msg.header.stamp] = msg
AttributeError: 'Float32' object has no attribute 'header'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-18 13:40:04 -0500

jayess gravatar image

updated 2019-12-18 13:43:41 -0500

If I understand the message_filter correctly, the messages that you're using need to have a header because

The TimeSequencer filter guarantees that messages will be called in temporal order according to their header's timestamp.

A Float32 message only has a data field and no header. Since it's expecting a header where there isn't one, it throws an error. You'll need to use a message type that has a header.

Edit:

Also look into using an ApproximateTimeSynchronizer which

uses current ROS time in place of any missing header.stamp field:

edit flag offensive delete link more

Comments

Thank you!, published this tipic with a message type that had Header, use Odometry for this case and works well thanks.

Juan Carlos gravatar image Juan Carlos  ( 2019-12-30 00:09:26 -0500 )edit

Question Tools

Stats

Asked: 2019-12-18 09:49:40 -0500

Seen: 491 times

Last updated: Dec 18 '19