CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/CAN/fix2_gap.py
Views: 1799
1
#!/usr/bin/env python3
2
'''
3
test script to check if all CAN GPS nodes are producing Fix2 frames at the expected rate
4
'''
5
6
import dronecan, time
7
from dronecan import uavcan
8
9
# get command line arguments
10
from argparse import ArgumentParser
11
parser = ArgumentParser(description='Fix2 gap example')
12
parser.add_argument("--bitrate", default=1000000, type=int, help="CAN bit rate")
13
parser.add_argument("--node-id", default=100, type=int, help="CAN node ID")
14
parser.add_argument("--max-gap", default=0.25, type=float, help="max gap in seconds")
15
parser.add_argument("port", default=None, type=str, help="serial port or mavcan URI")
16
args = parser.parse_args()
17
18
# Initializing a DroneCAN node instance.
19
node = dronecan.make_node(args.port, node_id=args.node_id, bitrate=args.bitrate)
20
21
# Initializing a node monitor
22
node_monitor = dronecan.app.node_monitor.NodeMonitor(node)
23
24
last_fix2 = {}
25
26
def handle_fix2(msg):
27
nodeid = msg.transfer.source_node_id
28
tstamp = msg.transfer.ts_real
29
if nodeid not in last_fix2:
30
last_fix2[nodeid] = tstamp
31
return
32
dt = tstamp - last_fix2[nodeid]
33
last_fix2[nodeid] = tstamp
34
if dt > args.max_gap:
35
print("Node %u gap=%.3f" % (nodeid, dt))
36
37
# callback for printing ESC status message to stdout in human-readable YAML format.
38
node.add_handler(dronecan.uavcan.equipment.gnss.Fix2, handle_fix2)
39
40
while True:
41
try:
42
node.spin()
43
except Exception as ex:
44
print(ex)
45
46