@@ -816,26 +816,28 @@ class CrazyflieROS
816
816
msg.num_tx_broadcast = deltaTxBc;
817
817
previous_stats_broadcast_ = statsBc;
818
818
819
+ msg.latency_unicast = last_latency_in_ms_;
820
+
819
821
publisher_status_->publish (msg);
820
822
821
823
// warnings
822
- if (msg.num_rx_unicast > msg.num_tx_unicast ) {
823
- RCLCPP_WARN (logger_, " Unexpected number of unicast packets. Sent: %d. Received: %d" , msg.num_tx_unicast , msg.num_rx_unicast );
824
+ if (msg.num_rx_unicast > msg.num_tx_unicast * 1.05 /* allow some slack */ ) {
825
+ RCLCPP_WARN (logger_, " [%s] Unexpected number of unicast packets. Sent: %d. Received: %d" , name_. c_str () , msg.num_tx_unicast , msg.num_rx_unicast );
824
826
}
825
827
if (msg.num_tx_unicast > 0 ) {
826
828
float unicast_receive_rate = msg.num_rx_unicast / (float )msg.num_tx_unicast ;
827
829
if (unicast_receive_rate < min_unicast_receive_rate_) {
828
- RCLCPP_WARN (logger_, " Low unicast receive rate (%.2f < %.2f). Sent: %d. Received: %d" , unicast_receive_rate, min_unicast_receive_rate_, msg.num_tx_unicast , msg.num_rx_unicast );
830
+ RCLCPP_WARN (logger_, " [%s] Low unicast receive rate (%.2f < %.2f). Sent: %d. Received: %d" , name_. c_str () , unicast_receive_rate, min_unicast_receive_rate_, msg.num_tx_unicast , msg.num_rx_unicast );
829
831
}
830
832
}
831
833
832
- if (msg.num_rx_broadcast > msg.num_tx_broadcast ) {
833
- RCLCPP_WARN (logger_, " Unexpected number of broadcast packets. Sent: %d. Received: %d" , msg.num_tx_broadcast , msg.num_rx_broadcast );
834
+ if (msg.num_rx_broadcast > msg.num_tx_broadcast * 1.05 /* allow some slack */ ) {
835
+ RCLCPP_WARN (logger_, " [%s] Unexpected number of broadcast packets. Sent: %d. Received: %d" , name_. c_str () , msg.num_tx_broadcast , msg.num_rx_broadcast );
834
836
}
835
837
if (msg.num_tx_broadcast > 0 ) {
836
838
float broadcast_receive_rate = msg.num_rx_broadcast / (float )msg.num_tx_broadcast ;
837
839
if (broadcast_receive_rate < min_broadcast_receive_rate_) {
838
- RCLCPP_WARN (logger_, " Low broadcast receive rate (%.2f < %.2f). Sent: %d. Received: %d" , broadcast_receive_rate, min_broadcast_receive_rate_, msg.num_tx_broadcast , msg.num_rx_broadcast );
840
+ RCLCPP_WARN (logger_, " [%s] Low broadcast receive rate (%.2f < %.2f). Sent: %d. Received: %d" , name_. c_str () , broadcast_receive_rate, min_broadcast_receive_rate_, msg.num_tx_broadcast , msg.num_rx_broadcast );
839
841
}
840
842
}
841
843
}
@@ -869,7 +871,7 @@ class CrazyflieROS
869
871
if (stats.ack_count > 0 ) {
870
872
float ack_rate = stats.sent_count / stats.ack_count ;
871
873
if (ack_rate < min_ack_rate_) {
872
- RCLCPP_WARN (logger_, " Ack rate: %.1f %%" , name_.c_str (), ack_rate * 100 );
874
+ RCLCPP_WARN (logger_, " [%s] Ack rate: %.1f %%" , name_.c_str (), ack_rate * 100 );
873
875
}
874
876
}
875
877
@@ -893,9 +895,10 @@ class CrazyflieROS
893
895
void on_latency (uint64_t latency_in_us)
894
896
{
895
897
if (latency_in_us / 1000.0 > max_latency_) {
896
- RCLCPP_WARN (logger_, " [%s] Latency : %.1f ms" , name_.c_str (), latency_in_us / 1000.0 );
898
+ RCLCPP_WARN (logger_, " [%s] High latency : %.1f ms" , name_.c_str (), latency_in_us / 1000.0 );
897
899
}
898
900
last_on_latency_ = std::chrono::steady_clock::now ();
901
+ last_latency_in_ms_ = (uint16_t )(latency_in_us / 1000.0 );
899
902
}
900
903
901
904
private:
@@ -949,6 +952,7 @@ class CrazyflieROS
949
952
// link statistics
950
953
rclcpp::TimerBase::SharedPtr link_statistics_timer_;
951
954
std::chrono::time_point<std::chrono::steady_clock> last_on_latency_;
955
+ uint16_t last_latency_in_ms_;
952
956
float warning_freq_;
953
957
float max_latency_;
954
958
float min_ack_rate_;
@@ -1357,19 +1361,23 @@ class CrazyflieServer : public rclcpp::Node
1357
1361
// a) check if the rate was within specified bounds
1358
1362
if (mocap_data_received_timepoints_.size () >= 2 ) {
1359
1363
double mean_rate = 0 ;
1364
+ double min_rate = std::numeric_limits<double >::max ();
1365
+ double max_rate = 0 ;
1360
1366
int num_rates_wrong = 0 ;
1361
1367
for (size_t i = 0 ; i < mocap_data_received_timepoints_.size () - 1 ; ++i) {
1362
1368
std::chrono::duration<double > diff = mocap_data_received_timepoints_[i+1 ] - mocap_data_received_timepoints_[i];
1363
1369
double rate = 1.0 / diff.count ();
1364
1370
mean_rate += rate;
1371
+ min_rate = std::min (min_rate, rate);
1372
+ max_rate = std::max (max_rate, rate);
1365
1373
if (rate <= mocap_min_rate_ || rate >= mocap_max_rate_) {
1366
1374
num_rates_wrong++;
1367
1375
}
1368
1376
}
1369
1377
mean_rate /= (mocap_data_received_timepoints_.size () - 1 );
1370
1378
1371
1379
if (num_rates_wrong > 0 ) {
1372
- RCLCPP_WARN (logger_, " [all] Motion capture rate off (#: %d, Avg: %.1f)" , num_rates_wrong, mean_rate);
1380
+ RCLCPP_WARN (logger_, " [all] Motion capture rate off (#: %d, Avg: %.1f, Min: %.1f, Max: %.1f )" , num_rates_wrong, mean_rate, min_rate, max_rate );
1373
1381
}
1374
1382
} else if (mocap_enabled_) {
1375
1383
// b) warn if no data was received
0 commit comments