0

Hello I am subscribing to a topic, where another node publishes Float32MultiArrays to it. This multiarray has information about objects I detect through a camera, this means that the first number in the matrix is a ID of the object and the other properties are: position, rotation, scale and shear. I am only interested in the ID and therefore I only want to check this number. I have just taken the most important things out of the code. Due to the fact that I can't find that much documentation on Float32MultiArray, I want to hear if any of you know the syntax for it.

import rospy
from std_msgs.msg import Float32MultiArray

def callback(data):
    rospy.loginfo(data.data[1][1])

class GoForward():
    def __init__(self):
    # initiliaze
        rospy.init_node('GoForward', anonymous=False)

        rospy.Subscriber("objects", Float32MultiArray, callback)


if __name__ == '__main__':
    try:
        GoForward()
    except:
        rospy.loginfo("GoForward node terminated.")
giggitygoat
  • 99
  • 2
  • 11
  • 1
    What exactly is the problem with our code? Please describe what its result is in comparison to what you want to have. If there are any error messages please also post them here. – luator Apr 11 '17 at 07:00
  • 1
    As a side note: If you want the *first* element of an array, its index is `0`, not `1`. – luator Apr 11 '17 at 07:00
  • What I want is to be able to take a specific number out of this 3x4 matrix and use it to instantiate another function. – giggitygoat Apr 11 '17 at 13:38
  • I changed it to return data.data[0], but it seems like due to the reason everytime it is empty it gives the "tuple index out of range", which of course makes sense, but it works now but it spams the mentioned error. I can't think of a way to fix this error – giggitygoat Apr 11 '17 at 13:45
  • Well, before accessing `data.data`, you should check if it is empty (it is as easy as `if data.data: # do something with it...`) – luator Apr 12 '17 at 08:31

0 Answers0