├── .gitignore
├── LICENSE
├── README.md
├── examples
├── html_example
│ ├── camera.html
│ ├── imu_node.html
│ ├── index.html
│ └── node1.html
└── markdown_example
│ ├── README.md
│ ├── camera.md
│ ├── imu_node.md
│ └── node1.md
├── rosautodoc
├── __init__.py
├── docWriter.py
├── formatConverters.py
└── masterProxy.py
├── scripts
└── rosautodoc
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 |
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rosautodoc
2 |
3 | The rosautodoc project provides a python executable that can automatically
4 | generate documentation for ROS nodes that are running on the system.
5 |
6 | ## Why should I care?
7 |
8 | This tool makes it possible to quickly generate initial documentation of
9 | the interface for a specific ROS node (or several nodes) based on how it
10 | performs at runtime. This eliminates the need to search through your code
11 | to make sure you document all the ROS parameters being used, or all the
12 | topics that your node is subscribing to. This script manages all of that
13 | for you -- you just need to fill in the descriptions of the API.
14 |
15 | ## Installation
16 |
17 | Follow these instructions to download and install this project:
18 |
19 | git clone https://github.com/bponsler/rosautodoc
20 | cd rosautodoc
21 | sudo python setup.py install
22 |
23 | ## How does this work?
24 |
25 | The rosautodoc script creates a proxy server that stands between a ROS system and the
26 | ROS master to intercept all requests made by nodes. This allows the proxy server to
27 | keep track of all publishers, subscribers, parameters, and services used by each
28 | node and then use this information to create documentation for the node.
29 |
30 | ## Usage
31 |
32 | This section describes how to use this project to automatically generate documentation.
33 |
34 | $ rosautodoc --help
35 | usage: rosautodoc [-h] [--output-dir OUTPUT_DIR] [--proxy-port PROXY_PORT]
36 | [--doc-format DOC_FORMAT]
37 | [node [node ...]]
38 |
39 | Automatically document the API for a ROS node.
40 |
41 | positional arguments:
42 | node The name of the nodes to document. If empty, all nodes
43 | will be documented
44 |
45 | optional arguments:
46 | -h, --help show this help message and exit
47 | --output-dir OUTPUT_DIR
48 | The directory where documentation should be written
49 | --proxy-port PROXY_PORT
50 | The port to use for the ROS master proxy server
51 | --doc-format DOC_FORMAT
52 | The format of the documentation to generate (markdown,
53 | html)
54 |
55 | # Examples
56 |
57 | First, run the ROS master in one terminal (using the default master URI http://localhost:11311):
58 |
59 | roscore
60 |
61 | Next, run the auto doc script in another terminal:
62 |
63 | mkdir /tmp/my_documentation
64 | rosautodoc --proxy-port=33133 --output=/tmp/my_documentation
65 |
66 | Finally, run your node in another terminal, and be sure to connect it to the same port that the rosautodoc script is using:
67 |
68 | export ROS_MASTER_URI=http://localhost:33133
69 | rosrun my_package my_node
70 |
71 | Once your node has finished starting up, you can stop the rosautodoc process which will
72 | write one documentation file for every node on the system. The documentation will be
73 | located in the /tmp/my_documentation directory.
74 |
75 | Alternatively, you can document only a specific node:
76 |
77 | rosautodoc --proxy-port=33133 --output=/tmp/my_documentation /ns/my_node_name
78 |
79 | The following command can be used to generate HTML documentation:
80 |
81 | rosautodoc --proxy-port=33133 --doc-format=html --output=/tmp/my_documentation
82 |
83 | This will generate an HTML documentation page for every node in your system and
84 | also a main index.html page that links to all the node documentation pages.
85 |
86 | You can also generate documentation for only a specific set of nodes.
87 |
88 | rosautodoc --proxy-port=33133 node1 node2 node3
89 |
90 | This command will generated a markdown (the default documentation format) file
91 | for the three nodes provides: node1, node2, and node3. It will also generate
92 | a main README.md file that links to the individual node documentation pages.
93 |
94 | Note that since the --output-dir argument was not provided, the documentation
95 | will be generated in the current working directory by defualt.
96 |
97 | # Example documentation
98 |
99 | For example documentation view one of the following pages:
100 |
101 | - [Example Markdown documentation](examples/markdown_example/README.md)
102 | - [Example HTML documentation (raw)](examples/html_example/index.html)
103 | - [Example HTML documentation (rendered)](https://rawgit.com/bponsler/rosautodoc/master/examples/html_example/index.html)
104 |
--------------------------------------------------------------------------------
/examples/html_example/camera.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | The /camera node
4 |
5 | Parameters:
6 |
7 | - ~/device [TODO: type] -- TODO: description
8 |
9 |
10 | Services:
11 |
12 | - ~/calibrate [TODO: type] -- TODO: description
13 |
14 |
15 | Subscribers:
16 |
17 | Publishers:
18 |
19 | - ~/camera_info [sensor_msgs/CameraInfo] -- TODO: description
20 | - ~/image [sensor_msgs/Image] -- TODO: description
21 |
22 |
23 |
--------------------------------------------------------------------------------
/examples/html_example/imu_node.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | The /imu_node node
4 |
5 | Parameters:
6 |
7 | - ~/imu_device [TODO: type] -- TODO: description
8 |
9 |
10 | Services:
11 |
12 | Subscribers:
13 |
14 | Publishers:
15 |
16 | - ~/imu_data [sensor_msgs/Imu] -- TODO: description
17 |
18 |
19 |
--------------------------------------------------------------------------------
/examples/html_example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | ROS system documentation
4 | Nodes
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/html_example/node1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | The /node1 node
4 |
5 | Parameters:
6 |
7 | - /another_param [TODO: type] -- TODO: description
8 | - ~/my_config_param [TODO: type] -- TODO: description
9 |
10 |
11 | Services:
12 |
13 | - ~/trigger [TODO: type] -- TODO: description
14 | - ~/shutdown [TODO: type] -- TODO: description
15 |
16 |
17 | Subscribers:
18 |
19 | - ~/odom [nav_msgs/Odometry] -- TODO: description
20 |
21 |
22 | Publishers:
23 |
24 | - ~/counter [std_msgs/Int32] -- TODO: description
25 | - ~/running [std_msgs/Bool] -- TODO: description
26 | - /global_topic [std_msgs/Float32] -- TODO: description
27 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/markdown_example/README.md:
--------------------------------------------------------------------------------
1 | # ROS system documentation
2 | ## Nodes
3 |
4 | - [/node1](node1.md)
5 | - [/camera](camera.md)
6 | - [/imu_node](imu_node.md)
7 |
--------------------------------------------------------------------------------
/examples/markdown_example/camera.md:
--------------------------------------------------------------------------------
1 | # The /camera node
2 |
3 | ## Parameters:
4 | - ~/device [TODO: type] -- TODO: description
5 |
6 | ## Services:
7 | - ~/calibrate [TODO: type] -- TODO: description
8 |
9 | ## Subscribers:
10 |
11 | ## Publishers:
12 | - ~/camera_info [sensor_msgs/CameraInfo] -- TODO: description
13 | - ~/image [sensor_msgs/Image] -- TODO: description
14 |
--------------------------------------------------------------------------------
/examples/markdown_example/imu_node.md:
--------------------------------------------------------------------------------
1 | # The /imu_node node
2 |
3 | ## Parameters:
4 | - ~/imu_device [TODO: type] -- TODO: description
5 |
6 | ## Services:
7 |
8 | ## Subscribers:
9 |
10 | ## Publishers:
11 | - ~/imu_data [sensor_msgs/Imu] -- TODO: description
12 |
--------------------------------------------------------------------------------
/examples/markdown_example/node1.md:
--------------------------------------------------------------------------------
1 | # The /node1 node
2 |
3 | ## Parameters:
4 | - /another_param [TODO: type] -- TODO: description
5 | - ~/my_config_param [TODO: type] -- TODO: description
6 |
7 | ## Services:
8 | - ~/trigger [TODO: type] -- TODO: description
9 | - ~/shutdown [TODO: type] -- TODO: description
10 |
11 | ## Subscribers:
12 | - ~/odom [nav_msgs/Odometry] -- TODO: description
13 |
14 | ## Publishers:
15 | - ~/counter [std_msgs/Int32] -- TODO: description
16 | - ~/running [std_msgs/Bool] -- TODO: description
17 | - /global_topic [std_msgs/Float32] -- TODO: description
18 |
--------------------------------------------------------------------------------
/rosautodoc/__init__.py:
--------------------------------------------------------------------------------
1 | from formatConverters import *
2 | from docWriter import *
3 | from masterProxy import *
4 |
--------------------------------------------------------------------------------
/rosautodoc/docWriter.py:
--------------------------------------------------------------------------------
1 | from os.path import join
2 |
3 | from formatConverters import FileExtension, MarkdownToHtml, MARKDOWN, HTML
4 |
5 |
6 | # String to tag things as needing work
7 | TODO_DESC = "TODO: description"
8 |
9 |
10 | class NodeInfo:
11 | """The NodeInfo class contains all the information pertaining to
12 | a single ROS Node. This keeps track of the published topics,
13 | subscribed topics, parameters, and services used or provided
14 | by this node.
15 |
16 | """
17 |
18 | def __init__(self, nodeName):
19 | """Create a NodeInfo object.
20 |
21 | * nodeName -- the name of the node
22 |
23 | """
24 | self.__nodeName = nodeName
25 |
26 | # Info about a node
27 | self.__params = []
28 | self.__pubs = {}
29 | self.__subs = {}
30 | self.__services = {}
31 |
32 | def getCleanName(self):
33 | """Get a clean name for this node so that it can be used
34 | as a filename.
35 |
36 | """
37 | # Create a node name that can be used as a filename
38 | cleanNodeName = self.__nodeName.replace("/", "_")
39 | if cleanNodeName.startswith("_"):
40 | cleanNodeName = cleanNodeName[1:]
41 |
42 | return cleanNodeName
43 |
44 | def addParam(self, param):
45 | """Add a parameter to this node.
46 |
47 | * param -- the parameter
48 |
49 | """
50 | if param not in self.__params:
51 | self.__params.append(param)
52 |
53 | def addPub(self, topic, pubType):
54 | """Add a published topic to this node.
55 |
56 | * topic -- the published topic
57 | * pubType -- the type of data
58 |
59 | """
60 | self.__pubs[topic] = pubType
61 |
62 | def addSub(self, topic, subType):
63 | """Add a subscribed topic to this node.
64 |
65 | * topic -- the subscription topic
66 | * pubType -- the type of data
67 |
68 | """
69 | self.__subs[topic] = subType
70 |
71 | def addService(self, service, serviceType):
72 | """Add a service to this node.
73 |
74 | * service -- the service
75 | * serviceType -- the type of service
76 |
77 | """
78 | self.__services[service] = serviceType
79 |
80 | def document(self, outputDir, docFormat=MARKDOWN):
81 | """Document the information pertaining to the nodes.
82 |
83 | * outputDir -- the directory where the documentation will be output
84 | * docFormat -- the desired format of the documentation
85 |
86 | """
87 | lines = [
88 | "# The %s node" % self.__nodeName,
89 | "",
90 | ]
91 |
92 | # Document parameters
93 | lines.extend([
94 | "## Parameters:",
95 | ])
96 | for name in sorted(self.__params):
97 | name = self.__removeNamespace(name)
98 | lines.append("- %s [TODO: type] -- %s" % (name, TODO_DESC))
99 |
100 | # Document services
101 | lines.extend([
102 | "",
103 | "## Services:",
104 | ])
105 | sortedServices = sorted(self.__services.keys())
106 | for name in sortedServices:
107 | serviceType = self.__services[name]
108 | name = self.__removeNamespace(name)
109 | lines.append("- %s [%s] -- %s" % (name, serviceType, TODO_DESC))
110 |
111 | # Document subscriptions
112 | lines.extend([
113 | "",
114 | "## Subscribers:",
115 | ])
116 | sortedSubs = sorted(self.__subs.keys())
117 | for name in sortedSubs:
118 | subType = self.__subs[name]
119 | name = self.__removeNamespace(name)
120 | lines.append("- %s [%s] -- %s" % (name, subType, TODO_DESC))
121 |
122 | # Document publications
123 | lines.extend([
124 | "",
125 | "## Publishers:",
126 | ])
127 | sortedPubs = sorted(self.__pubs)
128 | for name in sortedPubs:
129 | pubType = self.__pubs[name]
130 | name = self.__removeNamespace(name)
131 | lines.append("- %s [%s] -- %s" % (name, pubType, TODO_DESC))
132 |
133 | cleanNodeName = self.getCleanName()
134 | extension = FileExtension.get(docFormat)
135 | filename = join(outputDir, "%s.%s" % (cleanNodeName, extension))
136 |
137 | # Convert the markdown format
138 | if docFormat == HTML:
139 | lines = MarkdownToHtml.convert(lines)
140 |
141 | # Write the data to the file
142 | fd = open(filename, "w")
143 | fd.write("%s\n" % "\n".join(lines))
144 | fd.close()
145 |
146 | def __removeNamespace(self, namespace):
147 | """Update the given namespace to remove the private namespace
148 | for this node, if it exists.
149 |
150 | * namespace -- the namespace item (topic, parameter, etc)
151 |
152 | """
153 | if namespace.startswith(self.__nodeName):
154 | namespace = namespace.replace(self.__nodeName, "~", 1)
155 | return namespace
156 |
157 |
158 | class RosDocWriter:
159 | """The RosDocWriter class manages data for a set of nodes
160 | and makes it possible to generate documentation for all of
161 | those nodes.
162 |
163 | """
164 |
165 | def __init__(self, nodeNames):
166 | """Create a RosDocWriter object.
167 |
168 | * nodeNames -- the list of node names to monitor (all nodes
169 | will be monitored if the list is empty)
170 |
171 | """
172 | self.__nodeNames = nodeNames
173 |
174 | self.__nodes = {}
175 | for nodeName in nodeNames:
176 | self.__nodes[nodeName] = NodeInfo(nodeName)
177 |
178 | def addParam(self, nodeName, param):
179 | """Add a parameter to a node.
180 |
181 | * nodeName -- the node
182 | * param -- the parameter
183 |
184 | """
185 | if self.__hasNode(nodeName):
186 | self.__getNode(nodeName).addParam(param)
187 |
188 | def addPub(self, nodeName, topic, pubType):
189 | """Add a published topic to a node.
190 |
191 | * nodeName -- the node
192 | * topic -- the published topic
193 | * pubType -- the type of data
194 |
195 | """
196 | if self.__hasNode(nodeName):
197 | self.__getNode(nodeName).addPub(topic, pubType)
198 |
199 | def addSub(self, nodeName, topic, subType):
200 | """Add a subscribed topic to a node.
201 |
202 | * nodeName -- the node
203 | * topic -- the subscribed topic
204 | * subType -- the type of data
205 |
206 | """
207 | if self.__hasNode(nodeName):
208 | self.__getNode(nodeName).addSub(topic, subType)
209 |
210 | def addService(self, nodeName, service, serviceType):
211 | """Add a service to a node.
212 |
213 | * nodeName -- the node
214 | * service -- the service topic
215 | * serviceType -- the type of data
216 |
217 | """
218 | if self.__hasNode(nodeName):
219 | self.__getNode(nodeName).addService(service, serviceType)
220 |
221 | def document(self, outputDir, docFormat=MARKDOWN):
222 | """Document the information pertaining to the nodes.
223 |
224 | * outputDir -- the directory where the documentation will be output
225 | * docFormat -- the desired format of the documentation
226 |
227 | """
228 | for nodeName, node in self.__nodes.iteritems():
229 | print " Documenting %s..." % nodeName
230 | node.document(outputDir, docFormat)
231 |
232 | # Write a manifest file to link to all other nodes, if there are
233 | # multiple nodes being documented
234 | if len(self.__nodes) > 0:
235 | print "Creating documentation manifest..."
236 | self.__writeManifest(outputDir, docFormat)
237 |
238 | def __writeManifest(self, outputDir, docFormat=MARKDOWN):
239 | """Write the documentation manifest file which links to the
240 | documentation for all nodes.
241 |
242 | * outputDir -- the directory where the documentation will be output
243 | * docFormat -- the desired format of the documentation
244 |
245 | """
246 | extension = FileExtension.get(docFormat)
247 | filename = "index" if docFormat == HTML else "README"
248 | manifest = join(outputDir, "%s.%s" % (filename, extension))
249 |
250 | lines = [
251 | "# ROS system documentation"
252 | "",
253 | "## Nodes",
254 | "",
255 | ]
256 |
257 | # Add links to all nodes in alphabetical order
258 | sortedNodes = sorted(self.__nodes.keys())
259 | for nodeName in sortedNodes:
260 | node = self.__nodes[nodeName]
261 | cleanNodeName = node.getCleanName()
262 |
263 | link = "- [%s](%s.md)" % (nodeName, cleanNodeName)
264 | if docFormat == HTML:
265 | link = '- %s' % (cleanNodeName, nodeName)
266 |
267 | lines.append(link)
268 |
269 | # Convert the markdown format
270 | if docFormat == HTML:
271 | lines = MarkdownToHtml.convert(lines)
272 |
273 | # Write the data to the manifest file
274 | fd = open(manifest, "w")
275 | fd.write("%s\n" % "\n".join(lines))
276 | fd.close()
277 |
278 | def __hasNode(self, nodeName):
279 | """Determine if this node is being monitored.
280 |
281 | * nodeName -- the node
282 |
283 | """
284 | return (len(self.__nodeNames) == 0 or nodeName in self.__nodes)
285 |
286 | def __getNode(self, nodeName):
287 | """Get the NodeInfo object.
288 |
289 | * nodeName -- the name of the node
290 |
291 | """
292 | if nodeName not in self.__nodes:
293 | self.__nodes[nodeName] = NodeInfo(nodeName)
294 | return self.__nodes[nodeName]
295 |
--------------------------------------------------------------------------------
/rosautodoc/formatConverters.py:
--------------------------------------------------------------------------------
1 | # Set of valid doc formats
2 | MARKDOWN = "markdown"
3 | HTML = "html"
4 |
5 | # List of supported documentation formats
6 | SUPPORTED_DOC_FORMATS = [
7 | MARKDOWN,
8 | HTML,
9 | ]
10 |
11 |
12 | class FileExtension:
13 | """The FileExtension class makes it possible to get the file extension
14 | based on the format of the file.
15 |
16 | """
17 |
18 | @classmethod
19 | def get(cls, docFormat):
20 | """Return the file extension string (e.g., "html") for the
21 | desired documentation format.
22 |
23 | * docFormat -- the documentation format identifier
24 |
25 | """
26 | extensionMap = {
27 | MARKDOWN: "md",
28 | HTML: "html",
29 | }
30 |
31 | return extensionMap.get(docFormat)
32 |
33 |
34 | class MarkdownToHtml:
35 | """The MarkdownToHtml class deals with converting markdown content
36 | to HTML content.
37 |
38 | """
39 |
40 | @classmethod
41 | def convert(cls, lines):
42 | """Conver the given markdown data (as a list of strings) into HTML
43 | content (also as a list of strings).
44 |
45 | * lines -- the input list of markdown lines
46 |
47 | """
48 | htmlLines = [
49 | "",
50 | ""
51 | "",
52 | ]
53 |
54 | writingList = False
55 | for line in lines:
56 | isList = False
57 | if line.startswith("## "):
58 | # Subsection
59 | data = line[3:]
60 | line = "%s
" % data
61 | elif line.startswith("# "):
62 | # Section
63 | data = line[2:]
64 | line = "%s
" % data
65 | elif line.startswith("- "):
66 | # List entry
67 | isList = True
68 | if not writingList:
69 | htmlLines.append("")
70 | writingList = True
71 |
72 | data = line[2:]
73 | line = "- %s
" % data
74 | elif len(line.strip()) > 0:
75 | # Normal text content
76 | line = "%s
" % line
77 |
78 | # Close a list that has ended
79 | if not isList and writingList:
80 | htmlLines.append("
")
81 | writingList = False
82 |
83 | htmlLines.append(line)
84 |
85 | # Close the list if one was being created
86 | if writingList:
87 | htmlLines.append("")
88 |
89 | htmlLines.extend([
90 | "",
91 | ])
92 |
93 | return htmlLines
94 |
--------------------------------------------------------------------------------
/rosautodoc/masterProxy.py:
--------------------------------------------------------------------------------
1 | import socket
2 | import argparse
3 | from os.path import exists, abspath, curdir
4 |
5 | import xmlrpclib
6 | from SimpleXMLRPCServer import SimpleXMLRPCServer
7 |
8 | from docWriter import RosDocWriter
9 | from formatConverters import MARKDOWN, SUPPORTED_DOC_FORMATS
10 |
11 | import rosgraph
12 |
13 |
14 | class RosMasterFunctions:
15 | """The RosMasterFunctions class provides a class that exports all
16 | of the XMLRPC functions provided by the ROS master. This class
17 | intercepts calls to some of those methods in order to keep track
18 | of the publishers, subscribers, services, and parameters used by
19 | nodes. This class then makes it possible to generate documentation
20 | for that information.
21 |
22 | """
23 | RosMasterHost = "localhost"
24 | RosMasterPort = 11311
25 |
26 | # List of all methods supported by the ROS master
27 | RosMasterMethods = [
28 | "getPid",
29 | "registerService",
30 | "unregisterService",
31 | "registerSubscriber",
32 | "unregisterSubscriber",
33 | "registerPublisher",
34 | "unregisterPublisher",
35 | "lookupNode",
36 | "getPublishedTopics",
37 | "getTopicTypes",
38 | "getSystemState",
39 | "getUri",
40 | "lookupService",
41 | "deleteParam",
42 | "setParam",
43 | "getParam",
44 | "searchParam",
45 | "subscribeParam",
46 | "unsubscribeParam",
47 | "hasParam",
48 | "getParamNames",
49 | ]
50 |
51 | # List of ROS parameters to ignore
52 | FilterParameters = [
53 | "/tcp_keepalive",
54 | "/use_sim_time",
55 | ]
56 |
57 | # List of published ROS topics to ignore
58 | FilterPublishedTopic = [
59 | "/rosout",
60 | ]
61 |
62 | # List of subscribed ROS topics to ignore
63 | FilterSubscribedTopics = [
64 | ]
65 |
66 | # List of ROS services to ignore
67 | FilterServices = [
68 | ]
69 |
70 | def __init__(self, nodeNames):
71 | """Create a RosMasterFunctions object.
72 |
73 | * nodeNames -- the list of node names to document
74 |
75 | """
76 | masterUri = 'http://%s:%s' % (self.RosMasterHost, self.RosMasterPort)
77 |
78 | # Create an XMLRPC client to connect to the ROS master
79 | self.__client = xmlrpclib.ServerProxy(masterUri)
80 |
81 | # Register all ROS master methods with this class to allow custom
82 | # functionality to be executed prior to sending the data to the
83 | # ROS master
84 | for method in self.RosMasterMethods:
85 | wrapper = self.__getWrapper(method)
86 | setattr(self, method, wrapper)
87 |
88 | self.__nodeNames = nodeNames
89 |
90 | # Add a prefix slash if one is not given
91 | for i in range(len(self.__nodeNames)):
92 | if not nodeNames[i].startswith("/"):
93 | self.__nodeNames[i] = "/%s" % nodeNames[i]
94 |
95 | self.__docWriter = RosDocWriter(self.__nodeNames)
96 |
97 | def document(self, outputDir, docFormat=MARKDOWN):
98 | """Document the information pertaining to the nodes.
99 |
100 | * outputDir -- the directory where the documentation will be output
101 | * docFormat -- the desired format of the documentation
102 |
103 | """
104 | self.__docWriter.document(outputDir, docFormat)
105 |
106 | def __getWrapper(self, method):
107 | """Return a XMLRPC wrapper function which can optionally intercept
108 | a call to the given ROS master XMLRPC method.
109 |
110 | * method -- is the desired ROS master XMLRPC function to call
111 |
112 | """
113 | def wrap(*args):
114 | """Callback function for an XMLRPC function.
115 |
116 | * args -- the method input arguments
117 |
118 | """
119 | # If this class has a method callback registered, then
120 | # make sure we call the callback. Otherwise, just pass
121 | # the call through to the true ROS master server
122 | try:
123 | callback = "_%s" % method
124 | if hasattr(self, callback):
125 | callbackFn = getattr(self, callback)
126 | callbackFn(*args)
127 | except Exception, e:
128 | import traceback
129 | traceback.print_exc()
130 |
131 | # Pass the call through to the ROS master
132 | masterFn = getattr(self.__client, method)
133 | return masterFn(*args)
134 |
135 | return wrap
136 |
137 | def _registerPublisher(self, callerId, topic, topicType, callerApi):
138 | """Intercept callback for the registerPublisher function.
139 |
140 | * callerId -- the caller id (calling node name)
141 | * topic -- the publisher topic
142 | * topicType -- the type of the publisher
143 | * callerApi -- the caller API string
144 |
145 | """
146 | if topic not in self.FilterPublishedTopic:
147 | self.__docWriter.addPub(callerId, topic, topicType)
148 |
149 | def _registerSubscriber(self, callerId, topic, topicType, callerApi):
150 | """Intercept callback for the registerSubscriber function.
151 |
152 | * callerId -- the caller id (calling node name)
153 | * topic -- the subscriber topic
154 | * topicType -- the type of the subscriber
155 | * callerApi -- the caller API string
156 |
157 | """
158 | if topic not in self.FilterSubscribedTopics:
159 | self.__docWriter.addSub(callerId, topic, topicType)
160 |
161 | def _registerService(self, callerId, service, serviceApi, callerApi):
162 | """Intercept callback for the registerService function.
163 |
164 | * callerId -- the caller id (calling node name)
165 | * service -- the service topic
166 | * serviceApi -- the service API string
167 | * callerApi -- the caller API string
168 |
169 | """
170 | if service not in self.FilterServices:
171 | # The type of the service is not included in the XMLRPC call
172 | self.__docWriter.addService(callerId, service, "TODO: type")
173 |
174 | def _getParam(self, callerId, key):
175 | """Intercept callback for the getParam function.
176 |
177 | * callerId -- the caller id (calling node name)
178 | * key -- the parameter name
179 |
180 | """
181 | if key not in self.FilterParameters:
182 | self.__docWriter.addParam(callerId, key)
183 |
184 | def _hasParam(self, callerId, key):
185 | """Intercept callback for the hasParam function.
186 |
187 | * callerId -- the caller id (calling node name)
188 | * key -- the parameter name
189 |
190 | """
191 | if key not in self.FilterParameters:
192 | self.__docWriter.addParam(callerId, key)
193 |
194 | def _setParam(self, callerId, key, value):
195 | """Intercept callback for the setParam function.
196 |
197 | * callerId -- the caller id (calling node name)
198 | * key -- the parameter name
199 | * value -- the parameter value
200 |
201 | """
202 | if key not in self.FilterParameters:
203 | self.__docWriter.addParam(callerId, key)
204 |
205 |
206 | class RosMasterProxy:
207 | """The RosMasterProxy class implements an XMLRPC proxy server to
208 | intercept calls to the ROS master. These calls are monitored and
209 | documentation can be generated containing that information.
210 |
211 | """
212 |
213 | def __init__(self,
214 | nodeName,
215 | hostname="localhost",
216 | port=33133,
217 | verbose=False):
218 | """Create a RosMasterProxy object.
219 |
220 | * nodeName -- the name of the node to document
221 | * hostname -- the hostname for the proxy server
222 | * port -- the port for the proxy
223 | * verbose -- true for verbose mode
224 |
225 | """
226 | # Create the XMLRPC server
227 | self.__server = SimpleXMLRPCServer(
228 | (hostname, port),
229 | logRequests=verbose)
230 |
231 | # Register XMLRCP introspection methods like:
232 | # system.listMethods, system.methodHelp and system.methodSignature
233 | # NOTE: These are not supported by the proper ROS master
234 | self.__server.register_introspection_functions()
235 |
236 | # Support multi-call methods which are used by roslaunch
237 | self.__server.register_multicall_functions()
238 |
239 | # Register the XMLRPC functions to support the ROS master API
240 | self.__masterFunctions = RosMasterFunctions(nodeName)
241 | self.__server.register_instance(self.__masterFunctions)
242 |
243 | def start(self):
244 | """Start the RosMasterProxy"""
245 | # Run the server's main loop
246 | self.__server.serve_forever()
247 |
248 | def document(self, outputDir, docFormat=MARKDOWN):
249 | """Document the information pertaining to the nodes.
250 |
251 | * outputDir -- the directory where the documentation will be output
252 | * docFormat -- the desired format of the documentation
253 |
254 | """
255 | self.__masterFunctions.document(outputDir, docFormat)
256 |
257 |
258 | def main():
259 | """The main function for the rosautodoc application."""
260 | parser = argparse.ArgumentParser(
261 | description='Automatically document the API for a ROS node.')
262 | parser.add_argument(
263 | 'nodes',
264 | metavar="node",
265 | type=str, nargs='*',
266 | help='The name of the nodes to document. If empty, ' +
267 | 'all nodes will be documented')
268 | parser.add_argument(
269 | '--output-dir',
270 | type=str,
271 | default=abspath(curdir),
272 | help='The directory where documentation should be written')
273 | parser.add_argument(
274 | '--proxy-port',
275 | type=int,
276 | default=33133,
277 | help='The port to use for the ROS master proxy server')
278 | parser.add_argument(
279 | '--doc-format',
280 | type=str,
281 | default=MARKDOWN,
282 | help="The format of the documentation to generate " +
283 | "(%s)" % ", ".join(SUPPORTED_DOC_FORMATS))
284 |
285 | args = parser.parse_args()
286 |
287 | # Grab command line arguments
288 | nodeNames = args.nodes
289 | outputDir = args.output_dir
290 | proxyPort = args.proxy_port
291 | docFormat = args.doc_format.lower()
292 |
293 | # Make sure the format is valid
294 | if docFormat not in SUPPORTED_DOC_FORMATS:
295 | print "ERROR: unknown doc-format argument: %s" % docFormat
296 | exit(2)
297 |
298 | # Ensure that the output directory exists
299 | if not exists(outputDir):
300 | print "ERROR: the output directory does not exist: %s" % outputDir
301 | exit(3)
302 |
303 | # Make sure the ROS master is running
304 | try:
305 | rosgraph.Master('/rostopic').getPid()
306 | except socket.error:
307 | print "ERROR: failed to communicate with the ROS master!"
308 | exit(4)
309 |
310 | # Create the ROS master proxy node
311 | masterProxy = RosMasterProxy(nodeNames, port=proxyPort)
312 |
313 | try:
314 | print "Starting server..."
315 | masterProxy.start()
316 | except (KeyboardInterrupt, SystemExit):
317 | pass
318 |
319 | # Document the information about the node
320 | print "Documenting..."
321 | masterProxy.document(outputDir, docFormat=docFormat)
322 |
--------------------------------------------------------------------------------
/scripts/rosautodoc:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from rosautodoc import main
3 |
4 |
5 | if __name__ == '__main__':
6 | main()
7 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from distutils.core import setup
3 |
4 |
5 | setup(
6 | name='rosautodoc',
7 | version='1.0',
8 | description='Automatically generate documentation for ROS nodes',
9 | author='Brett Ponsler',
10 | author_email='ponsler@gmail.com',
11 | url='https://github.com/bponsler/rosautodoc',
12 | packages=['rosautodoc'],
13 | scripts=['scripts/rosautodoc']
14 | )
15 |
--------------------------------------------------------------------------------