ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

void callback(const sensor_msgs::PointCloud2ConstPtr& msg){ int width = msg->width; int height = msg->height; int v = 1; int u = 1; int arrayPosition = v * msg->row_step + u * msg->point_step; int arrayPosX = arrayPosition + msg->fields[0].offset; // X has an offset of 0 int arrayPosY = arrayPosition + msg->fields[1].offset; // Y has an offset of 4 int arrayPosZ = arrayPosition + msg->fields[2].offset; // Z has an offset of 8

double X = 0.0;
double Y = 0.0;
double Z = 0.0;

memcpy(&X, &msg->data[arrayPosX], sizeof(double));
memcpy(&Y, &msg->data[arrayPosY], sizeof(double));
memcpy(&Z, &msg->data[arrayPosZ], sizeof(double));

ROS_INFO("X:%lf",X);
ROS_INFO("Y:%lf",Y);
ROS_INFO("Z:%lf",Z);

}

How do we obtain u and v value from unordered pointcloud2 message genereated by the camera?

Why Z value generated stays at 0 all the time?

void callback(const sensor_msgs::PointCloud2ConstPtr& msg){ msg){

int width = msg->width;
 int height = msg->height;
 int v = 1;
 int u = 1;
 int arrayPosition = v * msg->row_step + u * msg->point_step;
 int arrayPosX = arrayPosition + msg->fields[0].offset; // X has an offset of 0
 int arrayPosY = arrayPosition + msg->fields[1].offset; // Y has an offset of 4
 int arrayPosZ = arrayPosition + msg->fields[2].offset; // Z has an offset of 8

8
double X = 0.0;
double Y = 0.0;
double Z = 0.0;

memcpy(&X, &msg->data[arrayPosX], sizeof(double));
memcpy(&Y, &msg->data[arrayPosY], sizeof(double));
memcpy(&Z, &msg->data[arrayPosZ], sizeof(double));

ROS_INFO("X:%lf",X);
ROS_INFO("Y:%lf",Y);
ROS_INFO("Z:%lf",Z);

}

How do we obtain u and v value from unordered pointcloud2 message genereated by the camera?

Why Z value generated stays at 0 all the time?