Skip to content

Commit f0d76ad

Browse files
committed
feat: improve timestamp accuracy
1 parent 0a08d87 commit f0d76ad

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/sensor_trigger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void SensorTrigger::run()
162162
bool to_high = gpio_handler_.set_gpio_pin_state(GPIO_HIGH);
163163
rclcpp::sleep_for(std::chrono::nanoseconds(pulse_width));
164164
rclcpp::Time now = rclcpp::Clock{RCL_SYSTEM_TIME}.now();
165-
int64_t now_sec = now.nanoseconds() / 1e9;
165+
int64_t now_sec = (now.nanoseconds() - pulse_width) / 1e9; // subtract pulse width to correct timestamp
166166
trigger_time_msg.sec = (int32_t)now_sec;
167167
trigger_time_msg.nanosec = (uint32_t)now_nsec;
168168
trigger_time_publisher_->publish(trigger_time_msg);

0 commit comments

Comments
 (0)