Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/param_metadata/mdemit.py
Views: 1799
"""1Emit parameter documentation in markdown format2"""34from param import known_param_fields5from emit import Emit6import re7import os89# Parameter groups disabled at compile time (Vehicle-specific)10sub_blacklist = ['AVOID_', 'CIRCLE_', 'FLOW', 'MIS_', 'PRX', 'RALLY_', 'RCMAP_', 'RPM', 'TERRAIN_', 'WPNAV_']1112# Parameter groups with redundant information (ie RCn_, SERVOn_)13# We can keep the documentation concise by only documenting these once14nparams = ['RCn_', 'SERVOn_', 'SRn_', 'BTNn_']1516class MDEmit(Emit):1718def __init__(self, *args, **kwargs):19Emit.__init__(self, *args, **kwargs)20fname = 'Parameters.md'21self.nparams = []22self.f = open(fname, mode='w')2324self.blacklist = None2526# Flag to generate navigation header for BlueRobotics' ArduSub docs27if os.getenv('BRDOC') is not None:28self.header = """---\nlayout: default\ntitle: "Parameters"\npermalink: /parameters/\nnav:"""2930self.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."""31self.t = ''3233def close(self):34# Write navigation header for BlueRobotics' ArduSub docs35if os.getenv('BRDOC') is not None:36self.f.write(self.header)37self.f.write('\n---\n')3839self.f.write(self.preamble)40self.f.write(self.t)41self.f.close()4243def start_libraries(self):44pass4546def emit(self, g):47nparam = False # Flag indicating this is a parameter group with redundant information (ie RCn_, SERVOn_)4849if g.reference == 'ArduSub':50self.blacklist = sub_blacklist5152if self.blacklist is not None and g.reference in self.blacklist:53return5455pname = g.reference5657# Check to see this is a parameter group with redundant information58rename = re.sub('\d+', 'n', g.reference)59if rename in nparams:60if rename in self.nparams:61return62else:63self.nparams.append(rename)64pname = rename65nparam = True6667# Markdown!68tag = '%s Parameters' % pname69tag = tag.replace('_', '')70link = tag.replace(' ', '-')7172# Add group to navigation header for BlueRobotics' ArduSub docs73if os.getenv('BRDOC') is not None:74self.header += "\n- %s: %s" % (link.split('-')[0],link.lower())7576t = '\n\n# %s' % tag7778for param in g.params:79if not hasattr(param, 'DisplayName') or not hasattr(param, 'Description'):80continue81d = param.__dict__82name = param.name.split(':')[-1]83if nparam:84name = re.sub('\d+', 'n', name, 1)85tag = '%s: %s' % (name, param.DisplayName)86t += '\n\n## %s' % tag87if d.get('User', None) == 'Advanced':88t += '\n\n*Note: This parameter is for advanced users*'89t += "\n\n%s" % param.Description9091for field in param.__dict__.keys():92if not self.should_emit_field(param, field):93continue94if field not in ['name', 'DisplayName', 'Description', 'User', 'SortValues'] and field in known_param_fields:95if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):96values = (param.__dict__[field]).split(',')97t += "\n\n|Value|Meaning|"98t += "\n|:---:|:---:|"99for value in values:100v = value.split(':')101if len(v) != 2:102raise ValueError("Bad value (%s)" % v)103t += "\n|%s|%s|" % (v[0], v[1])104else:105t += "\n\n- %s: %s" % (field, param.__dict__[field])106self.t += t107108109