Skip to content

Commit

Permalink
Try with the count digits
Browse files Browse the repository at this point in the history
  • Loading branch information
tizianoGuadagnino committed Oct 29, 2024
1 parent aff5e67 commit 810aaab
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ros/src/kinematic_icp_ros/utils/RosUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// SOFTWARE.
#include "kinematic_icp_ros/utils/RosUtils.hpp"

#include <cmath>
#include <cstdint>

namespace kinematic_icp_ros::utils {

std::optional<PointField> GetTimestampField(const PointCloud2::ConstSharedPtr msg) {
Expand Down Expand Up @@ -54,13 +57,23 @@ std::vector<double> NormalizeTimestamps(const std::vector<double> &timestamps) {

auto ExtractTimestampsFromMsg(const PointCloud2::ConstSharedPtr msg,
const PointField &timestamp_field) {
auto number_of_digits_decimal_part = [](const auto &stamp) {
const uint64_t converted_stamp = static_cast<uint64_t>(std::round(stamp));
return converted_stamp > 0 ? std::floor(std::log10(converted_stamp) + 1) : 1;
};
auto extract_timestamps =
[&msg]<typename T>(sensor_msgs::PointCloud2ConstIterator<T> &&it) -> std::vector<double> {
[&]<typename T>(sensor_msgs::PointCloud2ConstIterator<T> &&it) -> std::vector<double> {
const size_t n_points = msg->height * msg->width;
std::vector<double> timestamps;
timestamps.reserve(n_points);
for (size_t i = 0; i < n_points; ++i, ++it) {
timestamps.emplace_back(static_cast<double>(*it));
double stampd = static_cast<double>(*it);
// If the number of digits is greater than 10,
// the stamp is in nanoseconds instead of seconds, perform conversion
if (number_of_digits_decimal_part(*it) > 10) {
stampd *= 1e-9;
}
timestamps.emplace_back(stampd);
}
return timestamps;
};
Expand Down

0 comments on commit 810aaab

Please sign in to comment.