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/autotest/param_metadata/mdemit.py
Views: 1799
1
"""
2
Emit parameter documentation in markdown format
3
"""
4
5
from param import known_param_fields
6
from emit import Emit
7
import re
8
import os
9
10
# Parameter groups disabled at compile time (Vehicle-specific)
11
sub_blacklist = ['AVOID_', 'CIRCLE_', 'FLOW', 'MIS_', 'PRX', 'RALLY_', 'RCMAP_', 'RPM', 'TERRAIN_', 'WPNAV_']
12
13
# Parameter groups with redundant information (ie RCn_, SERVOn_)
14
# We can keep the documentation concise by only documenting these once
15
nparams = ['RCn_', 'SERVOn_', 'SRn_', 'BTNn_']
16
17
class MDEmit(Emit):
18
19
def __init__(self, *args, **kwargs):
20
Emit.__init__(self, *args, **kwargs)
21
fname = 'Parameters.md'
22
self.nparams = []
23
self.f = open(fname, mode='w')
24
25
self.blacklist = None
26
27
# Flag to generate navigation header for BlueRobotics' ArduSub docs
28
if os.getenv('BRDOC') is not None:
29
self.header = """---\nlayout: default\ntitle: "Parameters"\npermalink: /parameters/\nnav:"""
30
31
self.preamble = """\nThis is a complete list of the parameters which can be set via the MAVLink protocol in the EEPROM of your autopilot to control vehicle behaviour. This list is automatically generated from the latest ardupilot source code, and so may contain parameters which are not yet in the stable released versions of the code. Some parameters may only be available for developers, and are enabled at compile-time."""
32
self.t = ''
33
34
def close(self):
35
# Write navigation header for BlueRobotics' ArduSub docs
36
if os.getenv('BRDOC') is not None:
37
self.f.write(self.header)
38
self.f.write('\n---\n')
39
40
self.f.write(self.preamble)
41
self.f.write(self.t)
42
self.f.close()
43
44
def start_libraries(self):
45
pass
46
47
def emit(self, g):
48
nparam = False # Flag indicating this is a parameter group with redundant information (ie RCn_, SERVOn_)
49
50
if g.reference == 'ArduSub':
51
self.blacklist = sub_blacklist
52
53
if self.blacklist is not None and g.reference in self.blacklist:
54
return
55
56
pname = g.reference
57
58
# Check to see this is a parameter group with redundant information
59
rename = re.sub('\d+', 'n', g.reference)
60
if rename in nparams:
61
if rename in self.nparams:
62
return
63
else:
64
self.nparams.append(rename)
65
pname = rename
66
nparam = True
67
68
# Markdown!
69
tag = '%s Parameters' % pname
70
tag = tag.replace('_', '')
71
link = tag.replace(' ', '-')
72
73
# Add group to navigation header for BlueRobotics' ArduSub docs
74
if os.getenv('BRDOC') is not None:
75
self.header += "\n- %s: %s" % (link.split('-')[0],link.lower())
76
77
t = '\n\n# %s' % tag
78
79
for param in g.params:
80
if not hasattr(param, 'DisplayName') or not hasattr(param, 'Description'):
81
continue
82
d = param.__dict__
83
name = param.name.split(':')[-1]
84
if nparam:
85
name = re.sub('\d+', 'n', name, 1)
86
tag = '%s: %s' % (name, param.DisplayName)
87
t += '\n\n## %s' % tag
88
if d.get('User', None) == 'Advanced':
89
t += '\n\n*Note: This parameter is for advanced users*'
90
t += "\n\n%s" % param.Description
91
92
for field in param.__dict__.keys():
93
if not self.should_emit_field(param, field):
94
continue
95
if field not in ['name', 'DisplayName', 'Description', 'User', 'SortValues'] and field in known_param_fields:
96
if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):
97
values = (param.__dict__[field]).split(',')
98
t += "\n\n|Value|Meaning|"
99
t += "\n|:---:|:---:|"
100
for value in values:
101
v = value.split(':')
102
if len(v) != 2:
103
raise ValueError("Bad value (%s)" % v)
104
t += "\n|%s|%s|" % (v[0], v[1])
105
else:
106
t += "\n\n- %s: %s" % (field, param.__dict__[field])
107
self.t += t
108
109