|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | *****************************************************************************/ |
| 16 | + |
16 | 17 | #include "modules/drivers/lidar/seyond/src/seyond_driver.h" |
17 | 18 |
|
| 19 | +#include "cyber/time/time.h" |
| 20 | + |
18 | 21 | static const uint32_t KBUF_SIZE = 1024 * 1024 * 10; |
19 | 22 | static const double us_in_second_c = 1000000.0; |
20 | 23 | static const double ten_us_in_second_c = 100000.0; |
@@ -244,12 +247,28 @@ int32_t SeyondDriver::data_callback_(const InnoDataPacket *pkt) { |
244 | 247 | is_next_frame = true; |
245 | 248 | } |
246 | 249 |
|
| 250 | + uint64_t lidar_raw_ns = static_cast<uint64_t>(pkt->common.ts_start_us) * 1000; |
| 251 | + if (!param_.raw_packets_mode) { |
| 252 | + if (lidar_raw_ns < 1577836800000000000ULL) { |
| 253 | + if (ts_offset_ns_ == 0) { |
| 254 | + ts_offset_ns_ = |
| 255 | + apollo::cyber::Time::Now().ToNanosecond() - lidar_raw_ns; |
| 256 | + } |
| 257 | + } else { |
| 258 | + ts_offset_ns_ = 0; |
| 259 | + } |
| 260 | + } else { |
| 261 | + // There should be no software offset during playback of |
| 262 | + // the recorded package. |
| 263 | + ts_offset_ns_ = 0; |
| 264 | + } |
| 265 | + |
247 | 266 | packet_publish_cb_(pkt, is_next_frame); |
248 | 267 |
|
249 | 268 | if (is_next_frame) { |
250 | | - point_cloud_ptr_->mutable_header()->set_lidar_timestamp( |
251 | | - (static_cast<uint64_t>(pkt->common.ts_start_us)) * 1000); |
252 | | - point_cloud_ptr_->set_measurement_time(pkt->common.ts_start_us * 1e-6); |
| 269 | + uint64_t corrected_ns = lidar_raw_ns + ts_offset_ns_; |
| 270 | + point_cloud_ptr_->mutable_header()->set_lidar_timestamp(corrected_ns); |
| 271 | + point_cloud_ptr_->set_measurement_time(corrected_ns * 1e-9); |
253 | 272 | point_cloud_ptr_->set_height(1); |
254 | 273 | point_cloud_ptr_->set_width(frame_points_width_); |
255 | 274 | // data publish |
@@ -324,7 +343,8 @@ void SeyondDriver::convert_and_parse_(const InnoDataPacket *pkt) { |
324 | 343 |
|
325 | 344 | int32_t SeyondDriver::process_data_packet_(const InnoDataPacket *pkt) { |
326 | 345 | // calculate the point timestamp |
327 | | - current_ts_start_ = pkt->common.ts_start_us / us_in_second_c; |
| 346 | + current_ts_start_ = (static_cast<double>(pkt->common.ts_start_us) * 1e-6) + |
| 347 | + (static_cast<double>(ts_offset_ns_) * 1e-9); |
328 | 348 | // adapt different data structures form different lidar |
329 | 349 | if (CHECK_EN_XYZ_POINTCLOUD_DATA(pkt->type)) { |
330 | 350 | const InnoEnXyzPoint *pt = reinterpret_cast<const InnoEnXyzPoint *>( |
|
0 commit comments