Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointCloud2 doesn't get displayed, NaN values for positions #365

Closed
CodingSaturn opened this issue Mar 22, 2021 · 4 comments
Closed

PointCloud2 doesn't get displayed, NaN values for positions #365

CodingSaturn opened this issue Mar 22, 2021 · 4 comments

Comments

@CodingSaturn
Copy link

CodingSaturn commented Mar 22, 2021

Hello there,

I want to use ros3djs for visualizing a point cloud in the browser.
I took a look at the provided example code with the point cloud. However I don't have a kinnect at hand to try it with live data.
I only have a bagfile from an xtion camera, so I though I could modify the code.
Am I wrong with the assumption, that I only have to change the topic and maybe the fixed_frame value? This is what I did:

// Setup a client to listen to TFs.
    var tfClient = new ROSLIB.TFClient({
      ros : ros,
      angularThres : 0.01,
      transThres : 0.01,
      rate : 10.0,
      // fixedFrame : '/camera_link'
      fixedFrame : '/base_link'
    });

    var cloudClient = new ROS3D.PointCloud2({
        ros: ros,
        tfClient: tfClient,
        rootObject: viewer.scene,
        // topic: '/camera/depth_registered/points',
        topic: '/xtion/depth_registered/points',
        material: { size: 0.05, color: 0xff00ff }
    });

If I start all the things from the commandline that are mentioned in the example and then open the page in the browser, I see the "canvas" but no pointcloud. I have tested displaying the pointcloud in rviz and there it works just fine. When opening the console, I get the error:

THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values. This is true. If I take a look into the object, it says that "position" is an array with 30000 float32 values which are all NaN.
Screenshot from 2021-03-22 16-04-28

UPDATE:
The NaN values are returned from the following lines with the getFloat

 for(var i = 0; i < n; i++){
    base = i * pointRatio * msg.point_step;
    debugger;
    this.points.positions.array[3*i    ] = dv.getFloat32(base+x, littleEndian);
    this.points.positions.array[3*i + 1] = dv.getFloat32(base+y, littleEndian);
    this.points.positions.array[3*i + 2] = dv.getFloat32(base+z, littleEndian);

    if(this.points.colors){
        color = this.points.colormap(this.points.getColor(dv,base,littleEndian));
        this.points.colors.array[3*i    ] = color.r;
        this.points.colors.array[3*i + 1] = color.g;
        this.points.colors.array[3*i + 2] = color.b;
    }
  }

The person in this issue seemed to have the same or similar problem. However the only answer is another linked issue and I after looking at it, I am unsure on how to proceed with this issue now.

As I am an absolute beginner, even with ros and rviz, I am unsure what could be wrong here? Is it maybe just superdelayed (I waited a few minutes though) because the point cloud is too big? Is something configured incorrectly? Are the points too small or could there be a problem with the tf_frame?

One other thing I was unsure about is whether or not I need this command if I am using the bagfile:
roslaunch openni_launch openni.launch depth_registration:=true
As when running it, the output is "No devices connected.... waiting for devices to be connected", so I figure, I only need it with a physical kinect?

I would be glad about any idea what I am doing wrong here, thanks in advance!

@CodingSaturn CodingSaturn changed the title PointCloud2 doesn't get displayed, PointCloud2 doesn't get displayed, NaN values for positions Mar 22, 2021
@JohanJarvi
Copy link

I am having the same issue here. However, if you look into the array - at least for me, the first 1000 points are actual values:
image

It is only after this that they start to be NaN for me. I am using Turtlebot3 Gazebo's /camera/depth/points topic.

@JohanJarvi
Copy link

After reading more yesterday I found out that it is in fact not a huge problem that there are NaN values because according to the internet and also this comment on another GitHub issue it is in fact normal for pointclouds to contain NaN values.

That being said - I actually fixed my issue by increasing the point counts because by default according to the JSDoc the "max_pts" is only 10000. So by increasing that to five million I actually see the full pointcloud:
image

Basically you would add a param to your cloud client definition:

    var cloudClient = new ROS3D.PointCloud2({
        ros: ros,
        tfClient: tfClient,
        rootObject: viewer.scene,
        // topic: '/camera/depth_registered/points',
        topic: '/xtion/depth_registered/points',
        material: { size: 0.05, color: 0xff00ff },
        max_pts: 5000000 // 5 million points
    });

Where max_pts: 5000000 // 5 million points is the new addition.

Beware of how often you are querying though because my old PC melts if I try to update the point cloud too often with this number of points.

@MatthijsBurgh
Copy link
Contributor

@CodingSaturn does this solution work for you too?

@MatthijsBurgh
Copy link
Contributor

Possible solution provided by #365 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants