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

Rviz Marker not receving any published data

asked 2022-04-21 08:22:26 -0500

hichriayoub gravatar image

updated 2022-04-21 08:23:07 -0500

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-04-23 12:55:47 -0500

Mike Scheutzow gravatar image
  1. In your class marker, self.pt_x is not an array. It is a single float. So your for loop in the point_cloud() callback does nothing useful.
  2. Currently the code in main() executes only once, then execution sits in rospy.spin() forever. So you are calling self.pub.publish() either once or never (probably never.)
  3. Once you fix item (1), you could invoke the Marker message create & publish after the for loop in point_cloud() callback. Whether you should publish every time the callback executes depends on how often you think the point_cloud() callback is going to be called.
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-04-21 08:22:26 -0500

Seen: 70 times

Last updated: Apr 23 '22