Skip to content

Commit 15529ae

Browse files
authored
Merge pull request #447 from IMRCLab:feature_status
status and log message improvements
2 parents 6019132 + 6a9d1c3 commit 15529ae

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

crazyflie/launch/launch.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ def generate_launch_description():
8787
name='teleop',
8888
remappings=[
8989
('emergency', 'all/emergency'),
90-
('takeoff', 'cf6/takeoff'),
91-
('land', 'cf6/land'),
92-
('cmd_vel_legacy', 'cf6/cmd_vel_legacy'),
93-
('cmd_full_state', 'cf6/cmd_full_state'),
94-
('notify_setpoints_stop', 'cf6/notify_setpoints_stop'),
90+
('takeoff', 'all/takeoff'),
91+
('land', 'all/land'),
92+
# uncomment to manually control (and update teleop.yaml)
93+
# ('cmd_vel_legacy', 'cf6/cmd_vel_legacy'),
94+
# ('cmd_full_state', 'cf6/cmd_full_state'),
95+
# ('notify_setpoints_stop', 'cf6/notify_setpoints_stop'),
9596
],
9697
parameters=[teleop_params]
9798
),

crazyflie/scripts/gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def on_status(self, msg, name) -> None:
225225
battery_ok = False
226226
self.robotmodels[name].battery_text = battery_text
227227

228-
radio_text = f'{msg.rssi} dBm; Unicast: {msg.num_rx_unicast} / {msg.num_tx_unicast}; Broadcast: {msg.num_rx_broadcast} / {msg.num_tx_broadcast}'
228+
radio_text = f'{msg.rssi} dBm; Unicast: {msg.num_rx_unicast} / {msg.num_tx_unicast}; Broadcast: {msg.num_rx_broadcast} / {msg.num_tx_broadcast}; Latency: {msg.latency_unicast} ms'
229229
self.robotmodels[name].radio_text = radio_text
230230

231231
# save status here

crazyflie/src/crazyflie_server.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -816,26 +816,28 @@ class CrazyflieROS
816816
msg.num_tx_broadcast = deltaTxBc;
817817
previous_stats_broadcast_ = statsBc;
818818

819+
msg.latency_unicast = last_latency_in_ms_;
820+
819821
publisher_status_->publish(msg);
820822

821823
// 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);
824826
}
825827
if (msg.num_tx_unicast > 0) {
826828
float unicast_receive_rate = msg.num_rx_unicast / (float)msg.num_tx_unicast;
827829
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);
829831
}
830832
}
831833

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);
834836
}
835837
if (msg.num_tx_broadcast > 0) {
836838
float broadcast_receive_rate = msg.num_rx_broadcast / (float)msg.num_tx_broadcast;
837839
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);
839841
}
840842
}
841843
}
@@ -869,7 +871,7 @@ class CrazyflieROS
869871
if (stats.ack_count > 0) {
870872
float ack_rate = stats.sent_count / stats.ack_count;
871873
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);
873875
}
874876
}
875877

@@ -893,9 +895,10 @@ class CrazyflieROS
893895
void on_latency(uint64_t latency_in_us)
894896
{
895897
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);
897899
}
898900
last_on_latency_ = std::chrono::steady_clock::now();
901+
last_latency_in_ms_ = (uint16_t)(latency_in_us / 1000.0);
899902
}
900903

901904
private:
@@ -949,6 +952,7 @@ class CrazyflieROS
949952
// link statistics
950953
rclcpp::TimerBase::SharedPtr link_statistics_timer_;
951954
std::chrono::time_point<std::chrono::steady_clock> last_on_latency_;
955+
uint16_t last_latency_in_ms_;
952956
float warning_freq_;
953957
float max_latency_;
954958
float min_ack_rate_;
@@ -1357,19 +1361,23 @@ class CrazyflieServer : public rclcpp::Node
13571361
// a) check if the rate was within specified bounds
13581362
if (mocap_data_received_timepoints_.size() >= 2) {
13591363
double mean_rate = 0;
1364+
double min_rate = std::numeric_limits<double>::max();
1365+
double max_rate = 0;
13601366
int num_rates_wrong = 0;
13611367
for (size_t i = 0; i < mocap_data_received_timepoints_.size() - 1; ++i) {
13621368
std::chrono::duration<double> diff = mocap_data_received_timepoints_[i+1] - mocap_data_received_timepoints_[i];
13631369
double rate = 1.0 / diff.count();
13641370
mean_rate += rate;
1371+
min_rate = std::min(min_rate, rate);
1372+
max_rate = std::max(max_rate, rate);
13651373
if (rate <= mocap_min_rate_ || rate >= mocap_max_rate_) {
13661374
num_rates_wrong++;
13671375
}
13681376
}
13691377
mean_rate /= (mocap_data_received_timepoints_.size() - 1);
13701378

13711379
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);
13731381
}
13741382
} else if (mocap_enabled_) {
13751383
// b) warn if no data was received

crazyflie_interfaces/msg/Status.msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ uint32 num_rx_broadcast # number of received broadcast packets during the last
2929
uint32 num_tx_broadcast # number of broadcast packets sent during the last period
3030
uint32 num_rx_unicast # number of received unicast packets during the last period
3131
uint32 num_tx_unicast # number of unicast packets sent during the last period
32+
uint16 latency_unicast # latency (in ms) for unicast packets

0 commit comments

Comments
 (0)