Converting x, y, z array to point cloud data
Hello ROS developers, I am trying to convert a2D array to a point cloud value and publish it thereby visualising it in rviz. Can anyone guide me to solve the below issue which I am facing during the conversion ? This is the code and I get the error stated below that.
def scanProcessing(msg):
laserProj = LaserProjection()
cloud_out = laserProj.projectLaser(msg)
xyz_array = ros_numpy.point_cloud2.pointcloud2_to_xyz_array(cloud_out)
stamp = rospy.Time.now()
frame_id = 'odom'
xyz_coordinate = [[x[i],y[i], z[i]] for i in range(len(x))]
print(xyz_array)
header = std_msgs.msg.Header()
header.stamp = rospy.Time.now()
header.frame_id = 'map'
cloud_msg = ros_numpy.point_cloud2.array_to_pointcloud2(xyz_array, stamp, frame_id)
pointcloud_publisher.publish(cloud_msg)
if __name__ == "__main__":
rospy.init_node('scan_processor')
pointcloud_publisher = rospy.Publisher("/my_pointcloud_topic", PointCloud, queue_size=1)
scanSubscriber = rospy.Subscriber('/robot2/scan', LaserScan, scanProcessing, queue_size=1)
rospy.spin()
The Error observed is:
[ERROR] [1614671648.584787, 6.342000]: bad callback: <function scanProcessing at 0x7f88928728b0>
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "pointCloud_v8.py", line 120, in scanProcessing
cloud_msg = ros_numpy.point_cloud2.array_to_pointcloud2(xyz_array, stamp, frame_id)
File "/opt/ros/noetic/lib/python3/dist-packages/ros_numpy/point_cloud2.py", line 147, in array_to_pointcloud2
cloud_msg.fields = dtype_to_fields(cloud_arr.dtype)
File "/opt/ros/noetic/lib/python3/dist-packages/ros_numpy/point_cloud2.py", line 92, in dtype_to_fields
for field_name in dtype.names:
TypeError: 'NoneType' object is not iterable
P.S: As I understand this is a bit basic question. I would really appreciate some answers which could help me to continue my ROS journey
Edit 1: To emphasize more on the issue side from the comments :
Inside the function array_to_pointcloud2 there is a conversion to a 2D array. After which an object of pointCloud2 is created and the field attribute is associated with the data type of the array which in my case is 'float64' So basically dtype = 'foat64' All all good till the below function, iteration over dtype.names takes place which is None (which is logical), is there anything which we must do to tag it along with the dtype ?
def dtype_to_fields(dtype):
fields = []
for field_name in dtype.names:
np_field_type, field_offset = dtype.fields[field_name]
pf = PointField()
pf.name = field_name
if np_field_type.subdtype:
item_dtype, shape = np_field_type.subdtype
pf.count = np.prod(shape)
np_field_type = item_dtype
else:
pf.count = 1 ...(more code)...
Could you be more specific? For troubleshooting, you can do check your variables and check the output by printing it and compare with this link
Over here, check the variables.
The gist is that the iteration takes place over an non iterate-able object. I think I am missing to add some parameters which I would be happy to learn from others if they find it correctly.
Hello, can you please! describe what hardware you are using over here?
I am getting the scan topics from rplidar which is attached to a bot and I run the ros master on a ubuntu 20.04 pc (which does the conversion of scan to pcd , filtering and some computations and then converting back to point cloud data). Not sure why hardware comes into pplay over here.
I have done integration with 3d camera and not explored lidar. Sorry bro
Yeah No problem. I am able to convert the laser scan to point cloud data but stuck up in reversing