How to get xyz coordinates of pointcloud using Intel Real Sense D415?
I am working on Ubunto 20.4 with ROS noetic. I am having intel Real sense D415 camera by which I can visualize the point cloud on Rviz.
- I want to get xyz coordinates of each pointcloud and from that I want to separate min and max point xyz coordinates.
- After getting the min and max values of pointcloud i want to input my target xyz coordinates and want to compute the error difference.
I am very much new to ROS and doesn't have good programming experience as well. I will be very much thankful if anyone can share me any sample code or guide me step by step as i have searched almost all ROS forums but didn't get my answer.
I have gone through this code (https://www.programmersought.com/arti...) but it gives out several errors.
[ERROR] [1622062315.967796]: bad callback: <function callback_pointcloud at 0x7fe9857b61f0>
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/home/arif/catkin_ws/src/perception_pcl/pcl_ros/src/pcl_ros/xyz.py", line 14, in callback_pointcloud
print (" x : %.3f y: %.3f z: %.3f") %(p[0],p[1],p[2])
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
Kindly help me out, I will be very much thankful to you.
Concerning your error message: The example code you referenced was written for Python2 but
noetic
uses python3 which requires brackets around the print statement. The correct syntax here , however, would beprint (" x : %.3f y: %.3f z: %.3f" %(p[0], p[1], p[2]))
(mind the position of the brackets). I just want to point out that that kind of sting formatting in not very common anymore in python3. See e.g. here forstr.format
orf-strings
, which can be used more intuitively.If you are new to ROS/ coding my general advice would be to go through some of the beginner tutorials first (if you have not done so). ROS has good tutorials for different levels of experience here and there are tons of python tutorials out there.
You might also want to have a look at the realsense ros wrapper examples
Thank you so much for your comment, I have corrected my code, and now its working and giving the xyz values.