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