Skip to content

Commit

Permalink
Add --save argument
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed Jan 31, 2025
1 parent 31dca7b commit 685d0dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions ros2controlcli/doc/userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,16 @@ view_controller_chains
.. code-block:: console
$ ros2 control view_controller_chains -h
usage: ros2 control view_controller_chains [-h] [--spin-time SPIN_TIME] [-s] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
usage: ros2 control view_controller_chains [-h] [--spin-time SPIN_TIME] [-s] [--save] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] [--ros-args ...]
Generates a diagram of the loaded chained controllers into /tmp/controller_diagram.gv.pdf
Generates a diagram of the loaded chained controllers
options:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
-s, --use-sim-time Enable ROS simulation time
--save Save PDF to controller_diagram.pdf instead of viewing image
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node (default: controller_manager)
--include-hidden-nodes
Expand Down
14 changes: 11 additions & 3 deletions ros2controlcli/ros2controlcli/verb/view_controller_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ def show_graph(

s.attr(ranksep="2")
s.attr(rankdir="LR")
s.render(view=False)
if visualize:
s.view()
else:
s.render(filename="controller_diagram", view=False, cleanup=True)


def parse_response(list_controllers_response, list_hardware_response, visualize=True):
Expand Down Expand Up @@ -196,15 +197,22 @@ def parse_response(list_controllers_response, list_hardware_response, visualize=


class ViewControllerChainsVerb(VerbExtension):
"""Generates a diagram of the loaded chained controllers into /tmp/controller_diagram.gv.pdf."""
"""Generates a diagram of the loaded chained controllers."""

def add_arguments(self, parser, cli_name):
add_arguments(parser)
parser.add_argument(
"--save",
action="store_true",
help="Save PDF to controller_diagram.pdf instead of viewing image",
)
add_controller_mgr_parsers(parser)

def main(self, *, args):
with NodeStrategy(args).direct_node as node:
list_controllers_response = list_controllers(node, args.controller_manager)
list_hardware_response = list_hardware_interfaces(node, args.controller_manager)
parse_response(list_controllers_response, list_hardware_response, visualize=False)
parse_response(
list_controllers_response, list_hardware_response, visualize=not args.save
)
return 0

0 comments on commit 685d0dd

Please sign in to comment.