@@ -463,7 +463,8 @@ void MqttClient::ros2mqtt(const topic_tools::ShapeShifter::ConstPtr& ros_msg,
463
463
}
464
464
465
465
466
- void MqttClient::mqtt2ros (mqtt::const_message_ptr mqtt_msg) {
466
+ void MqttClient::mqtt2ros (mqtt::const_message_ptr mqtt_msg,
467
+ const ros::WallTime& arrival_stamp) {
467
468
468
469
std::string mqtt_topic = mqtt_msg->get_topic ();
469
470
Mqtt2RosInterface& mqtt2ros = mqtt2ros_[mqtt_topic];
@@ -492,8 +493,7 @@ void MqttClient::mqtt2ros(mqtt::const_message_ptr mqtt_msg) {
492
493
ros::serialization::deserialize (stamp_stream, stamp);
493
494
494
495
// compute ROS2MQTT latency
495
- ros::WallTime now_wall = ros::WallTime::now ();
496
- ros::Time now (now_wall.sec , now_wall.nsec );
496
+ ros::Time now (arrival_stamp.sec , arrival_stamp.nsec );
497
497
if (now.isZero ())
498
498
NODELET_WARN (
499
499
" Cannot compute latency for MQTT topic %s when ROS time is 0, is a ROS "
@@ -574,6 +574,9 @@ bool MqttClient::isConnectedService(IsConnected::Request& request,
574
574
575
575
void MqttClient::message_arrived (mqtt::const_message_ptr mqtt_msg) {
576
576
577
+ // instantly take arrival timestamp
578
+ ros::WallTime arrival_stamp = ros::WallTime::now ();
579
+
577
580
std::string mqtt_topic = mqtt_msg->get_topic ();
578
581
NODELET_DEBUG (" Received MQTT message on topic '%s'" , mqtt_topic.c_str ());
579
582
auto & payload = mqtt_msg->get_payload_ref ();
@@ -624,7 +627,7 @@ void MqttClient::message_arrived(mqtt::const_message_ptr mqtt_msg) {
624
627
625
628
// publish ROS message, if publisher initialized
626
629
if (!mqtt2ros_[mqtt_topic].ros .publisher .getTopic ().empty ()) {
627
- mqtt2ros (mqtt_msg);
630
+ mqtt2ros (mqtt_msg, arrival_stamp );
628
631
} else {
629
632
NODELET_WARN (
630
633
" ROS publisher for data from MQTT topic '%s' is not yet initialized: "
0 commit comments