DroneCAN Python Library
raw JSON → 1.0.27 verified Fri May 01 auth: no python
Python implementation of the DroneCAN protocol stack (v1.0.27). Provides DSDL parsing, CAN bus communication, node management, and MAVLink bridging. Release cadence is irregular with occasional patches.
pip install dronecan Common errors
error ModuleNotFoundError: No module named 'dronecan.uavcan' ↓
cause Missing DSDL compilation or using wrong import path.
fix
Run
dronecan_dsdlc <path-to-dsdl-dir> to compile DroneCAN DSDL definitions first. error AttributeError: module 'dronecan' has no attribute 'make_node' ↓
cause Using an older version of dronecan that does not have `make_node`.
fix
Upgrade dronecan to >=1.0.0 with
pip install --upgrade dronecan. Warnings
gotcha The import path for DSDL types changed. Use `dronecan.uavcan.protocol.NodeStatus` instead of `dronecan.node.NodeStatus` after DSDL compilation. ↓
fix Use `from dronecan.uavcan.protocol import NodeStatus` after compiling DSDL.
breaking In Python 3.11+, the slcan driver may have issues. A fix was applied in v1.0.18, but ensure you are using a supported python-can version. ↓
fix Upgrade to dronecan >=1.0.18 and ensure python-can is up-to-date.
deprecated The old `dronecan.driver.slcan` driver is deprecated in favor of `dronecan.driver.slcan.Serial`. ↓
fix Use `dronecan.driver.slcan.Serial` instead of `dronecan.driver.slcan`.
Imports
- dronecan
import dronecan
Quickstart
import dronecan
# Initialize a node
node = dronecan.make_node('slcan0', node_id=100, bitrate=1000000)
# Start node
node.start()
# Subscribe to node status messages
def on_node_status(msg):
print(msg)
node.add_handler(dronecan.uavcan.protocol.NodeStatus, on_node_status)
# Spin forever
import time
while True:
try:
node.spin(timeout=1)
time.sleep(1)
except KeyboardInterrupt:
break
node.close()