ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The code you have shown us is actually taking the location of the first point in the point cloud, so is it not certain where on the cluster that point will be. We would not expect this point to be the centre of the cluster. The structured nature of the point clouds from the kinect mean it's likely to be on the corner as you see but it won't always be.
You're trying to determine the grasp pose required to pickup the block, unfortunately this problem is a fair bit more complicated than your current solution. What happens if the block is placed at a diagonal angle? Ideally you really want to estimate the location and pose of the object so you can reliably determine the grasp pose.
A simple solution that ignores the orientation for now is to find the centre of the cluster. To do this you want to find the minimum and maximum x, y and z values in the point cloud. The centre can then be calculated as being half way between these min max values. This method will only work if the box is orthogonally aligned and doesn't determine it's size.
A more complex but robust method would be to use RANSAC to detect the faces of the cube and or extract the edges of the cloud and use RANSAC to detect the edge lines of the cube. This way you could detect the position, orientation and size of the cube. This would allow a suitable grasp to be found in the vast majority of cases, but it's a complex process to develop.
Hope this gives you some ideas.