After publishing the messages from another package, I am using darknet_ros_3d package and writing a subscriber. For saving the messages into variables for the later use, I am following the answer mentioned in: https://robotics.stackexchange.com/a/21798/27972.

The code is given as follows:

import rospy
from sensor_msgs.msg import Image
from darknet_ros_msgs.msg import BoundingBoxes3d
from std_msgs.msg import Header
from std_msgs.msg import String

class darknet_ros_3d:

  def callback(self, msg):
    for box in msg.bounding_boxes:
        "Xmin: {}, Xmax: {} Ymin: {}, Ymax: {}, Zmin: {}, Zmax: {}".format(
        box.xmin, box.xmax, box.ymin, box.ymax)
    # save data into variables
    self.Xmin = box.xmin
    self.Xmax = box.xmax
    self.Ymin = box.ymin
    self.Ymax = box.ymax
    self.Zmin = box.zmin
    self.Zmax = box.zmax

  def __init__(self):
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber('/darknet_ros_3d/bounding_boxes', BoundingBoxes3d, self.callback)
    pose = [self.Xmin, self.Ymin, self.Zmin, self.Xmax, self.Ymax, self.Zmax]

if __name__ == '__main__':
  except KeyboardInterrupt:
    print("Shutting down")

I am getting the following error for the line

pose = [self.Xmin, self.Ymin, self.Zmin, self.Xmax, self.Ymax, self.Zmax]:
AttributeError: darknet_ros_3d instance has no attribute 'Xmin'

You have added an extra line to the __init__ function given in the referenced answer, and that code tries to use values which haven't been set yet.

To fix the error just remove the pose = [self.Xmin, ... , self.Zmax] line.


Not the answer you're looking for? Browse other questions tagged or ask your own question.