Rviz Marker not receving any published data
Hello everyone i am trying to draw bounding boxes on my pointcloud i was able to write the code and it compiles without any error but i am having a problem the topic bounding_box i created when i want to check it with rostopic echo it doesn"t have any published data
here is a sample of my code
import time
import sys
import pyntcloud
import rospy
import sensor_msgs.point_cloud2
from sensor_msgs.msg import PointCloud2
from visualization_msgs.msg import Marker
from visualization_msgs.msg import MarkerArray
class marker() :
def __init__(self):
self.pt_x=0
self.pt_y=0
self.pt_z=0
self.pt_i=0
self.points=[]
self.pub = rospy.Publisher("/bounding_box", Marker, queue_size = 100)
rospy.sleep(1)
def point_cloud(self,msg):
print(msg.header.seq)
self.points=sensor_msgs.point_cloud2.read_points(msg, skip_nans=True)
for point in sensor_msgs.point_cloud2.read_points(msg, skip_nans=True):
self.pt_x = point[0]
self.pt_y = point[1]
self.pt_z = point[2]
self.pt_i = point[3]
def main(self):
rospy.Subscriber("/ti_mmwave/radar_scan_pcl_0", PointCloud2, self.point_cloud)
x = [self.pt_x]
y = [self.pt_y]
z = [self.pt_z]
if self.points != []:
centroid = (sum(x) / len(self.points), sum(y) / len(self.points),sum(z) / len(self.points))
marker = Marker()
marker.header.frame_id = "/map"
marker.type = marker.CUBE
marker.action = marker.ADD
marker.pose.orientation.x = 0
marker.pose.orientation.y = 0
marker.pose.orientation.z = 0
marker.pose.orientation.w = 1
marker.pose.position.x = centroid[0]
marker.pose.position.y = centroid[1]
marker.pose.position.z = centroid[2]
t = rospy.Duration()
marker.lifetime = t
marker.scale.x = 1
marker.scale.y = 1
marker.scale.z = 1
marker.color.a = 1
marker.color.r = 1.0
self.pub.publish(marker)
rate = rospy.Rate(5)
rate.sleep()
rospy.spin()
if __name__ == '__main__':
rospy.init_node("bounding_box")
x=marker()
x.main()
i would appreciate any help thank you a lot