Invalid number of arguments error publishing
I am trying to publish cluster points from the list of points and labels created through HDBSCAN, after appending the label number to each respective point I am getting an error with my publisher saying the the input data is incorrect as labeled below:
ERROR] [1639689960.828037]: bad callback: <function callback at 0x7f69527bb160>
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "dbscan_lidar.py", line 34, in callback
talker(cluster_labels, p)
File "dbscan_lidar.py", line 52, in talker
pub.publish(cluster_list)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 879, in publish
data = args_kwds_to_message(self.data_class, args, kwds)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py", line 122, in args_kwds_to_message
return data_class(*args)
File "/opt/ros/noetic/lib/python3/dist-packages/sensor_msgs/msg/_PointCloud.py", line 106, in __init__
super(PointCloud, self).__init__(*args, **kwds)
File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 354, in __init__
raise TypeError('Invalid number of arguments, args should be %s' % str(self.__slots__) + ' args are' + str(args))
TypeError: Invalid number of arguments, args should be ['header', 'points', 'channels'] args are(<class 'hdbscan_py.msg._cluster.cluster'>,)
import hdbscan
import rospy
from rospy.core import rospyinfo
from sensor_msgs.msg import PointCloud, PointCloud2
import numpy as np
import pcl
import ros_numpy
import time
from hdbscan_py.msg import cluster as cluster_list
from rospy.numpy_msg import numpy_msg
rospy.init_node('hdbscan')
pub = rospy.Publisher('cluster', numpy_msg(PointCloud), queue_size=1)
#This is utilizing the data to cluster
def callback(data):
tstart = time.time()
pc = ros_numpy.numpify(data)
points=np.zeros((pc.shape[0], 3))
points[:,0]=pc['x']
points[:,1]=pc['y']
points[:,2]=pc['z']
p = pcl.PointCloud(np.array(points, dtype=np.float32))
#Utilizes PointCloud points generated to passthrough HDBSCAN
clusterer = hdbscan.HDBSCAN(min_cluster_size=15, min_samples=1, alpha=1.3).fit(p)
cluster_labels = clusterer.fit_predict(p)
#cloudpoints =
#rospy.loginfo(cluster_labels)
tstop = time.time()
talker(cluster_labels, p)
rospy.loginfo(tstop-tstart)
def talker(cluster_labels, p):
#pubClusters =
cluster_list_msg=cluster_list()
#ChannelFloats32 has 1:1 with each point
#cluster=[]
for cluster_labels in range(np.size(p)):
cluster_list_msg.cluster.append(p[cluster_labels])
#cluster_list_msg[cluster_labels[cluster_index]].append(p[cluster_index])
rospy.loginfo('Test')
#pubClusters.publish(cluster_list)
pub.publish(cluster_list)
#This is subscribing to the sensor data
def listener():
rospy.Subscriber('/wamv/sensors/lidars/lidar_wamv/points', PointCloud2, callback)
rospy.spin()
if __name__=='__main__':
listener()
In the future, please format error messages and source code using the 101010 button. I did it for you this time.