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

perf(pointcloud_preprocessor): prevent excessive log and speed up a bit #6843

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,78 +242,88 @@
// For performance, avoid transform computation if unnecessary
bool need_transform = points.header.frame_id != base_link_frame_;

// For performance, do not instantiate `rclcpp::Time` inside of the for-loop
double imu_stamp{0.0};
if (use_imu_ && !angular_velocity_queue_.empty()) {
imu_stamp = rclcpp::Time(imu_it->header.stamp).seconds();
}

// If there is a point that cannot be associated, record it to issue a warning
bool twist_time_stamp_is_too_late = false;
bool imu_time_stamp_is_too_late = false;

for (; it_x != it_x.end(); ++it_x, ++it_y, ++it_z, ++it_time_stamp) {
while (twist_it != std::end(twist_queue_) - 1 && *it_time_stamp > twist_stamp) {
++twist_it;
twist_stamp = rclcpp::Time(twist_it->header.stamp).seconds();
}

float v{static_cast<float>(twist_it->twist.linear.x)};
float w{static_cast<float>(twist_it->twist.angular.z)};

if (std::abs(*it_time_stamp - twist_stamp) > 0.1) {
RCLCPP_WARN_STREAM_THROTTLE(
get_logger(), *get_clock(), 10000 /* ms */,
"twist time_stamp is too late. Could not interpolate.");
twist_time_stamp_is_too_late = true;
v = 0.0f;
w = 0.0f;
}

if (use_imu_ && !angular_velocity_queue_.empty()) {
// For performance, do not instantiate `rclcpp::Time` inside of the for-loop
double imu_stamp = rclcpp::Time(imu_it->header.stamp).seconds();

for (;
(imu_it != std::end(angular_velocity_queue_) - 1 &&
*it_time_stamp > rclcpp::Time(imu_it->header.stamp).seconds());
++imu_it) {
}

while (imu_it != std::end(angular_velocity_queue_) - 1 && *it_time_stamp > imu_stamp) {
++imu_it;
imu_stamp = rclcpp::Time(imu_it->header.stamp).seconds();
}

if (std::abs(*it_time_stamp - imu_stamp) > 0.1) {
RCLCPP_WARN_STREAM_THROTTLE(
get_logger(), *get_clock(), 10000 /* ms */,
"imu time_stamp is too late. Could not interpolate.");
imu_time_stamp_is_too_late = true;
} else {
w = static_cast<float>(imu_it->vector.z);
}
}

const auto time_offset = static_cast<float>(*it_time_stamp - prev_time_stamp_sec);

point.setValue(*it_x, *it_y, *it_z);

if (need_transform) {
point = tf2_base_link_to_sensor_inv * point;
}

theta += w * time_offset;
baselink_quat.setValue(
0, 0, tier4_autoware_utils::sin(theta * 0.5f),
tier4_autoware_utils::cos(theta * 0.5f)); // baselink_quat.setRPY(0.0, 0.0, theta);
const float dis = v * time_offset;
x += dis * tier4_autoware_utils::cos(theta);
y += dis * tier4_autoware_utils::sin(theta);

baselink_tf_odom.setOrigin(tf2::Vector3(x, y, 0.0));
baselink_tf_odom.setRotation(baselink_quat);

undistorted_point = baselink_tf_odom * point;

if (need_transform) {
undistorted_point = tf2_base_link_to_sensor * undistorted_point;
}

*it_x = static_cast<float>(undistorted_point.getX());
*it_y = static_cast<float>(undistorted_point.getY());
*it_z = static_cast<float>(undistorted_point.getZ());

prev_time_stamp_sec = *it_time_stamp;
}

if (twist_time_stamp_is_too_late) {
RCLCPP_WARN_STREAM_THROTTLE(
get_logger(), *get_clock(), 10000 /* ms */,
"twist time_stamp is too late. Could not interpolate.");
}

if (imu_time_stamp_is_too_late) {
RCLCPP_WARN_STREAM_THROTTLE(
get_logger(), *get_clock(), 10000 /* ms */,
"imu time_stamp is too late. Could not interpolate.");
}

Check warning on line 326 in sensing/pointcloud_preprocessor/src/distortion_corrector/distortion_corrector.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

DistortionCorrectorComponent::undistortPointCloud increases in cyclomatic complexity from 21 to 23, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
return true;
}

Expand Down
Loading