@@ -147,7 +147,8 @@ void AirsimROSWrapper::initialize_ros()
147147
148148 statistics_timer_ = nh_->create_wall_timer (dseconds{1 }, std::bind (&AirsimROSWrapper::statistics_timer_cb, this ));
149149 go_signal_timer_ = nh_->create_wall_timer (dseconds{1 }, std::bind (&AirsimROSWrapper::go_signal_timer_cb, this ));
150- go_timestamp_ = nh_->get_clock ()->now ();
150+
151+ go_timestamp_ = make_ts (airsim_client_.getCarState ().timestamp );
151152
152153 airsim_client_.enableApiControl (!manual_mode, vehicle_name);
153154
@@ -269,7 +270,7 @@ void AirsimROSWrapper::create_ros_pubs_from_settings_json()
269270 initialize_airsim ();
270271}
271272
272- rclcpp::Time AirsimROSWrapper::make_ts (uint64_t unreal_ts)
273+ rclcpp::Time AirsimROSWrapper::make_ts (uint64_t unreal_ts) const
273274{
274275 // unreal timestamp is a unix nanosecond timestamp just like ros.
275276 // We can do direct translation as long as ros is not running in simulated time mode.
@@ -305,7 +306,7 @@ nav_msgs::msg::Odometry AirsimROSWrapper::get_odom_msg_from_airsim_state(const m
305306{
306307 nav_msgs::msg::Odometry odom_enu_msg;
307308 odom_enu_msg.header .frame_id = " fsds/map" ;
308- odom_enu_msg.header .stamp = nh_-> get_clock ()-> now ( );
309+ odom_enu_msg.header .stamp = make_ts (car_state. timestamp );
309310 odom_enu_msg.child_frame_id = " fsds/FSCar" ;
310311 odom_enu_msg.pose .pose .position .x = car_state.getPosition ().x ();
311312 odom_enu_msg.pose .pose .position .y = car_state.getPosition ().y ();
@@ -508,7 +509,7 @@ void AirsimROSWrapper::imu_timer_cb()
508509 imu_msg.linear_acceleration_covariance [4 ] = imu_data.sigma_vrw *imu_data.sigma_vrw ;
509510 imu_msg.linear_acceleration_covariance [8 ] = imu_data.sigma_vrw *imu_data.sigma_vrw ;
510511 imu_msg.header .frame_id = " fsds/" + vehicle_name;
511- // imu_msg.header.stamp = nh_->get_clock()->now( );
512+ imu_msg.header .stamp = make_ts (imu_data. time_stamp );
512513 {
513514 ros_bridge::ROSMsgCounter counter (&imu_pub_statistics);
514515 imu_pub->publish (imu_msg);
@@ -559,9 +560,17 @@ void AirsimROSWrapper::gss_timer_cb()
559560
560561void AirsimROSWrapper::statictf_cb ()
561562{
563+ msr::airlib::CarApiBase::CarState state;
564+ {
565+ ros_bridge::Timer timer (&getCarStateStatistics);
566+ std::unique_lock<std::recursive_mutex> lck (car_control_mutex_);
567+ state = airsim_client_.getCarState (vehicle_name);
568+ lck.unlock ();
569+ }
570+
562571 for (auto & static_tf_msg : static_tf_msg_vec_)
563572 {
564- static_tf_msg.header .stamp = nh_-> get_clock ()-> now ( );
573+ static_tf_msg.header .stamp = make_ts (state. timestamp );
565574 static_tf_pub_.sendTransform (static_tf_msg);
566575 }
567576}
@@ -683,7 +692,7 @@ void AirsimROSWrapper::lidar_timer_cb(const std::string& lidar_name, const int l
683692 }
684693 lidar_msg = get_lidar_msg_from_airsim (lidar_name, lidar_data); // todo make const ptr msg to avoid copy
685694 lidar_msg.header .frame_id = " fsds/" + lidar_name;
686- lidar_msg.header .stamp = nh_-> get_clock ()-> now ( );
695+ lidar_msg.header .stamp = make_ts (lidar_data. time_stamp );
687696
688697 {
689698 ros_bridge::ROSMsgCounter counter (&lidar_pub_vec_statistics[lidar_index]);
0 commit comments