2

I have a pcd file with x y z coordinates from point cloud.

Now I have another cpp file from where I print x y z coordinates on terminal. ( This is just the coordinates not a point cloud) I want to store this in another file in order to compare it with pcd file. How do I do it?

Sant
  • 41
  • 3

1 Answers1

0

Why do you need to store it directly from stdout? There are a couple of different ways to go about this that are probably easier.

You can simply publish the (x,y,z) data and record it with rosbag record and then export via rosbag_to_csv.

You could also just write the values to a file directly in the code instead of printing it out. Since you did not specify Python or C++ here is a quick example in Python

f = open('your_output_file.csv', 'a')
while not rospy.is_shutdown():
    #Whatever ops to get data
    x,y,z = get_the_data()
    output_str = str(x)+','+str(y)+','+str(z)
    f.write(output_str)

ROS will also automatically log output from rospy.log*() functions. You can control where this is stored by exporting the environmental variable ROS_LOG_DIR. Note that this may not work 100% correctly for print() statements

Finally, if you really really need to use stdout for some reason you can always redirect the output from however you're launching the node. Ex: roslaunch your_package your_launch.launch >> some_file.txt

BTables
  • 4,413
  • 2
  • 11
  • 30
  • Thank you. The quick response helped. I used the second option. The name of the file is foo.csv But I cannot seem to find the location of where it is stored. – Sant Dec 03 '21 at 21:53
  • std::ofstream myFile("foo.csv"); myFile << "x"; myFile << "y\n"; { double distance = sqrt(pow(point_x - x, 2.0) + pow(point_y - y, 2.0)); if (distance < rad) { std::cout<<"xcoord "< – Sant Dec 03 '21 at 21:57
  • @Sant you’re using a relative path for that file name so it will be in whatever folder the program is run out of. If you’re using a local workspace it would be something like `workspace/devel/lib/package_name`. It’s probably better and easier to give it an absolute path such as `/home/your_user/foo.csv` – BTables Dec 04 '21 at 01:39