DroneCAN: ошибки CRC узла GNSSPython

Программы на Python
Ответить
Anonymous
 DroneCAN: ошибки CRC узла GNSS

Сообщение Anonymous »

Я пытаюсь создать GNSS-узел Dronecan из stm32g4, используя fdcan, но с классической реализацией can (8-байтовые полезные нагрузки) я использую библиотеку canard для управления узлом. но при попытке получить код с помощью простого кода Python я получаю ошибки CRC. Насколько я знаю, CRC обрабатывается canardlib и должен работать по умолчанию. Это код Python, который я использую:

Код: Выделить всё

#!/usr/bin/env python3
'''
dump all messages in YAML format
'''

import dronecan, time, math
import can

can.BusABC.flush_tx_buffer = lambda self: None  # monkey-patch to avoid NotImplementedError in python-can
# get command line arguments
from argparse import ArgumentParser
parser = ArgumentParser(description='dump all DroneCAN messages')
parser.add_argument("--bitrate", default=1000000, type=int, help="CAN bit rate")
parser.add_argument("--node-id", default=100, type=int, help="CAN node ID")
parser.add_argument("--dna-server", action='store_true', default=False, help="run DNA server")
parser.add_argument("--port", default="can0", type=str, help="can0")
args = parser.parse_args()

# Initializing a DroneCAN node instance.
node = dronecan.make_node(args.port, node_id=args.node_id, bitrate=args.bitrate)

# Initializing a node monitor, so we can see what nodes are online
node_monitor = dronecan.app.node_monitor.NodeMonitor(node)

if args.dna_server:
# optionally start a DNA server
dynamic_node_id_allocator = dronecan.app.dynamic_node_id.CentralizedServer(node, node_monitor)

# callback for printing all messages in human-readable YAML format.
node.add_handler(None, lambda msg: print(dronecan.to_yaml(msg)))

# Running the node until the application is terminated or until first error.
try:
node.spin()
except KeyboardInterrupt:
pass
Это фрагмент моего кода на языке C:

Код: Выделить всё

static void send_NodeStatus(void)
{
uint8_t buffer[UAVCAN_PROTOCOL_NODESTATUS_MAX_SIZE];

node_status.uptime_sec = micros64() / 1000000ULL;
node_status.health = UAVCAN_PROTOCOL_NODESTATUS_HEALTH_OK;
node_status.mode = UAVCAN_PROTOCOL_NODESTATUS_MODE_OPERATIONAL;
node_status.sub_mode = 0;
// put whatever you like in here for display in GUI
node_status.vendor_specific_status_code = 0;

uint32_t len = uavcan_protocol_NodeStatus_encode(&node_status, buffer
#if CANARD_ENABLE_TAO_OPTION
, true
#endif
);

// we need a static variable for the transfer ID. This is
// incremeneted on each transfer, allowing for detection of packet
// loss
static uint8_t transfer_id;

canardBroadcast(&canard,
UAVCAN_PROTOCOL_NODESTATUS_SIGNATURE,
UAVCAN_PROTOCOL_NODESTATUS_ID,
&transfer_id,
CANARD_TRANSFER_PRIORITY_LOW,
buffer,
len);
}

Код: Выделить всё

*/
static void process1HzTasks(uint64_t timestamp_usec)
{
/*
Purge transfers that are no longer transmitted.  This can free up some memory
*/
canardCleanupStaleTransfers(&canard, timestamp_usec);

/*
Transmit the node status message
*/
send_NodeStatus();
}

Код: Выделить всё

void canardNode_Spin(){
processTxRxOnce(10);

const uint64_t ts = micros64();

if (canardGetLocalNodeID(&canard) == CANARD_BROADCAST_NODE_ID) {
// waiting for DNA
}

// see if we are still doing DNA
if (canardGetLocalNodeID(&canard) == CANARD_BROADCAST_NODE_ID) {
// we're still waiting for a DNA allocation of our node ID
if (millis32() > DNA.send_next_node_id_allocation_request_at_ms) {
request_DNA();
}
return;
}

if (ts >= next_1hz_service_at) {
next_1hz_service_at += 1000000ULL;
process1HzTasks(ts);
}
}
Это код драйвера stm32, используемого canard:

Код: Выделить всё

int16_t canardSTM32Transmit(const CanardCANFrame* const frame)
{
if (!frame || !CanHandle_) return -CANARD_STM32_ERROR_UNSUPPORTED_FRAME_FORMAT;

FDCAN_TxHeaderTypeDef txHeader = {0};
uint8_t data[8] = {0};
memcpy(data, frame->data, frame->data_len);

txHeader.Identifier = frame->id & 0x1FFFFFFF;
txHeader.IdType = (frame->id & CANARD_CAN_FRAME_EFF) ? FDCAN_EXTENDED_ID : FDCAN_STANDARD_ID;
txHeader.TxFrameType = (frame->id & CANARD_CAN_FRAME_RTR) ? FDCAN_REMOTE_FRAME : FDCAN_DATA_FRAME;
txHeader.DataLength = frame->data_len;
txHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
txHeader.BitRateSwitch = FDCAN_BRS_OFF;
txHeader.FDFormat = FDCAN_CLASSIC_CAN;
txHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

if (HAL_FDCAN_AddMessageToTxFifoQ(CanHandle_, &txHeader, data) != HAL_OK)
{
return 0;  // FIFO full
}

return 1;  // Queued successfully
}
Я получаю это сообщение на принимающей стороне:

Код: Выделить всё

health: 0 # OK
mode: 0 # OPERATIONAL
sub_mode: 0
vendor_specific_status_code: 0
Traceback (most recent call last):
File "/-/-/pythoncode/testpy.py", line 34, in 
node.spin()
~~~~~~~~~^^
File "/-/-/.local/lib/python3.13/site-packages/dronecan/node.py", line 439, in spin
execute_once()
~~~~~~~~~~~~^^
File "/-/-/.local/lib/python3.13/site-packages/dronecan/node.py", line 433, in execute_once
self._recv_frame(frame)
~~~~~~~~~~~~~~~~^^^^^^^
File "/-/-/.local/lib/python3.13/site-packages/dronecan/node.py", line 333, in _recv_frame
transfer.from_frames(transfer_frames)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/-/-/.local/lib/python3.13/site-packages/dronecan/transport.py", line 852, in from_frames
raise TransferError("CRC mismatch: expected {0:x}, got {1:x} for payload {2!r} (DTID {3:d})"
.format(crc, transfer_crc, payload_bytes, self.data_type_id))
dronecan.transport.TransferError: CRC mismatch: expected 5c82, got 5b19 for payload bytearray(b'\x04\x00\x00\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x033\x00\x00gnss') (DTID 1)
Если вам нужна какая-либо информация по отладке stm32, просто сообщите мне, и я смогу ее предоставить.

Подробнее здесь: https://stackoverflow.com/questions/798 ... crc-errors
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»