Browse Source

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).
release/1.12
JacobCrabill 4 years ago committed by Daniel Agar
parent
commit
73ef22ae77
  1. 6
      src/drivers/uavcan_v1/Uavcan.cpp

6
src/drivers/uavcan_v1/Uavcan.cpp

@ -423,10 +423,10 @@ void UavcanNode::sendHeartbeat() @@ -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() @@ -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;
}
}

Loading…
Cancel
Save