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

Invalid number of arguments error publishing

asked 2021-12-16 15:52:49 -0500

marioa gravatar image

updated 2021-12-17 08:08:31 -0500

Mike Scheutzow gravatar image

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()
edit retag flag offensive close merge delete

Comments

In the future, please format error messages and source code using the 101010 button. I did it for you this time.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-12-17 08:18:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-12-17 08:17:24 -0500

Mike Scheutzow gravatar image

updated 2021-12-17 08:19:18 -0500

You are using different message types (i.e. python classes) for what you specify when you create the publisher, and what you pass to publish(). Under most circumstances, these need to be the same.

edit flag offensive delete link more

Comments

I think I may have asked the wrong question, what I really meant to ask how can I convert my current msg type? is there any way to find the different types of conversions?

marioa gravatar image marioa  ( 2021-12-17 10:47:26 -0500 )edit

There is no formal way to find conversions. I think most people use a web search. I do notice that the numpy_msg.py file has examples of how it is meant to be used.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-12-18 07:38:02 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-12-16 15:52:49 -0500

Seen: 83 times

Last updated: Dec 17 '21