Closed alonsollorente closed 1 month ago
@alonsollorente this line looks wrong: double time_stamp = *reinterpret_cast<const double*>(point_ptr + i * msg->point_step + time_stamp_offset);
It basically means: "Interpret these eight bytes as a double". But if you know that time is stored as a std::uint32_t
, the following would be correct: std::uint32_t time_stamp = *reinterpret_cast<const std::uint32_t*>(point_ptr + i * msg->point_step + time_stamp_offset);
, and correspondingly in RCLCPP_INO
: time=%u
Also: this is not very robust:
msg->fields[5].name = "time";
msg->fields[4].name = "ring";
I would suggest to at least check whether the original names are time_stamp and channel, respectively.
@mvieth Thanks for your reply! Concerning your suggestion, if I run the code as you suggested I don't get the time value even in the raw data.
Concerning your second suggestion, is true that this is not the desirable way to go, but as I cannot change the field's name in another way this was a temporary solution to try to use the fromROSMsg()
function. Furthermore, the original fields are named channel
and time_stamp
.
Are you absolutely sure that the time should be a non-zero value, or is it possible that the message indeed only contains "0" in this field for all points? Have you perhaps checked the documentation of the lidar sensor, or similar? I see that e.g. the intensity is also zero for all points, is this expected? Maybe the sensor just does not fill these two fields?
Concerning your second suggestion, is true that this is not the desirable way to go, but as I cannot change the field's name in another way this was a temporary solution to try to use the fromROSMsg() function. Furthermore, the original fields are named channel and time_stamp.
My suggestion was to do something like:
if(msg->fields.size() >= 6 && msg->fields[5].name == "time_stamp") {
msg->fields[5].name = "time";
} else {
// throw error
}
if(msg->fields.size() >= 5 && msg->fields[4].name == "channel") {
msg->fields[4].name = "ring";
} else {
// throw error
}
This would protect you if (for whatever reason):
I'm actually using the simulated LiDAR data from the AWSIM project. Could it be that the numbers that I was seeing were not really measurings? Why would they appear, then?
Regarding the intensity value, it is known that is zero since was configured like that in the simulation environment.
@mvieth Problem solved! You were right and the problem was not on the function itself, but on the data side. I wasn't publishing the timestamp properly. I fixed some missing links in the simulator side and everything is working easy. Thank you for your time and help!
You're welcome. Great that you found the solution.
Hi everyone!
I'm having a pretty annoying bug related with ROS2 LiDAR data processing with the PCL library. My goal is to just apply the
fromROSMsg()
function to mysensor_msgs.msg.PointCloud2
lidar data coming from some recordings I have in a rosbag.This is the code I'm using to achieve that:
As key considerations to understand the code, it's important for you to know that, originally, the name of the ring and time fields of the raw message were channel and time_stamp. That's why, before the processing of the point cloud, I wrote:
And accordingly in the point/point cloud definition for the PCL library, I defined:
As you will see in the next attached figure, the time it's defined in uint32_t, since the data type is defined as number 6 (see sensor_msgs/PointField ROS2 definiton).
Executing this script while running a bag file, will end up in giving me the following output:
As you can see, all the values from the raw point cloud data are mapped into the pcl object, but the time. It is a bit confusing, since the ring values are mapped but not the time. I'm not getting any error from PCL side, so I don't know if it's something from the visualization part or something dumb that I'm missing.
If you need any further details, do not hesitate to ask!
Thanks in advance! 👍🏼
Some details about my environment: