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

Additional lidar_handler to set the timestamp of the pointcloud from specific rotation angle #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/os_cloud_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class OusterCloud : public nodelet::Nodelet {
lidar_frame = tf_prefix + "os_lidar";
auto timestamp_mode_arg = pnh.param("timestamp_mode", std::string{});
use_ros_time = timestamp_mode_arg == "TIME_FROM_ROS_TIME";
if (pnh.getParam("time_reference_angle", time_reference_angle) &&
((time_reference_angle > 360.0) || (time_reference_angle < 0.0))){
NODELET_WARN_STREAM("OusterCloud: time_reference_angle " << time_reference_angle <<
" invalid and will be ignored!");
time_reference_angle = NULL;
}
}

std::string get_metadata(ros::NodeHandle& nh) {
Expand Down Expand Up @@ -121,6 +127,8 @@ class OusterCloud : public nodelet::Nodelet {
void create_subscribers(ros::NodeHandle& nh) {
auto lidar_handler = use_ros_time
? &OusterCloud::lidar_handler_ros_time
: time_reference_angle
? &OusterCloud::lidar_handler_sensor_reference_angle_time
: &OusterCloud::lidar_handler_sensor_time;

lidar_packet_sub =
Expand Down Expand Up @@ -152,6 +160,31 @@ class OusterCloud : public nodelet::Nodelet {
info.lidar_to_sensor_transform, sensor_frame, lidar_frame, msg_ts));
}

void lidar_handler_sensor_reference_angle_time(const PacketMsg::ConstPtr& packet) {
if (!(*scan_batcher)(packet->buf.data(), ls)) return;
auto ts_v = ls.timestamp();
auto m_id_v = ls.measurement_id();

std::uint16_t min_valid_idx = std::find_if(ts_v.data(), ts_v.data() + ts_v.size(),
[](uint64_t h) { return h != 0; }) - ts_v.data();
std::uint16_t max_valid_idx = *std::max_element(m_id_v.data(), m_id_v.data() + m_id_v.size());

auto time_reference_idx = int(m_id_v.size() - floor( m_id_v.size() * (time_reference_angle/360.0) ));

auto scan_ts = std::chrono::nanoseconds{ts_v(time_reference_idx)};

if (time_reference_idx < min_valid_idx || time_reference_idx > max_valid_idx){
scan_ts = std::chrono::nanoseconds{ts_v(min_valid_idx)};

double min_angle = 360.0 - (double(max_valid_idx) / double(m_id_v.size()))*360.0;
double max_angle = 360.0 - (double(max_valid_idx) / double(m_id_v.size()))*360.0;
NODELET_WARN_THROTTLE(2.0, "OusterCloud: time_reference_angle %.2f degree not within available azimuth range"
" of [%.2f %.2f] degree! \nUsing Timestamp of earliest valid package at %f degree!",
time_reference_angle, min_angle, max_angle, max_angle);
}
convert_scan_to_pointcloud_publish(scan_ts, to_ros_time(scan_ts));
}

void lidar_handler_sensor_time(const PacketMsg::ConstPtr& packet) {
if (!(*scan_batcher)(packet->buf.data(), ls)) return;
auto ts_v = ls.timestamp();
Expand Down Expand Up @@ -224,6 +257,7 @@ class OusterCloud : public nodelet::Nodelet {
tf2_ros::TransformBroadcaster tf_bcast;

bool use_ros_time;
double time_reference_angle = NULL;
};

} // namespace nodelets_os
Expand Down