mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 18:03:34 +08:00
uavcan_v1: Fix heartbeat pub timestamp
The hrt_abstime value used to control the 1s pub rate was the value of the timestamp_usec of the CanardTransfer, which has a timeout of 100ms added to it. Since hrt_abstime is an unsigned datatype, if the hrt_elapsed_time() check was called <100ms apart, the negative value would result in a large hrt_elapsed_time, and the bus would be spammed with Heartbeat messages (or error messages from canardTxPush).
This commit is contained in:
committed by
Daniel Agar
parent
251f1a069b
commit
73ef22ae77
@@ -423,10 +423,10 @@ void UavcanNode::sendHeartbeat()
|
||||
heartbeat.uptime = _uavcan_node_heartbeat_transfer_id; // TODO: use real uptime
|
||||
heartbeat.health.value = uavcan_node_Health_1_0_NOMINAL;
|
||||
heartbeat.mode.value = uavcan_node_Mode_1_0_OPERATIONAL;
|
||||
|
||||
const hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
CanardTransfer transfer = {
|
||||
.timestamp_usec = hrt_absolute_time() + PUBLISHER_DEFAULT_TIMEOUT_USEC,
|
||||
.timestamp_usec = now + PUBLISHER_DEFAULT_TIMEOUT_USEC,
|
||||
.priority = CanardPriorityNominal,
|
||||
.transfer_kind = CanardTransferKindMessage,
|
||||
.port_id = uavcan_node_Heartbeat_1_0_FIXED_PORT_ID_,
|
||||
@@ -447,7 +447,7 @@ void UavcanNode::sendHeartbeat()
|
||||
PX4_ERR("Heartbeat transmit error %d", result);
|
||||
}
|
||||
|
||||
_uavcan_node_heartbeat_last = transfer.timestamp_usec;
|
||||
_uavcan_node_heartbeat_last = now;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user