Replies: 5 comments 5 replies
-
To my knowledge, nobody is working on this right now. If you want to implement something at submit a PR, we'd be happy to consider it for inclusion in the library. There are some existing Python-based block diagram editors out there. In particular, take a look at pysimCoder by @robertobucher. |
Beta Was this translation helpful? Give feedback.
-
BDSim includes a graphical block diagram editor. Its format is a JSON file. It might be possible to convert that into an interconnect command, or create some other way to integrate with python-control, such as by use python-control system objects in BDSim. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your kind reply. I apologize for the delay, as I have been evaluating our technical options. A major advantage of python-control is that it is cross-platform (Windows, Mac, and Linux) and licensed under the BSD 3-Clause license. I want to ensure that my implementation preserves these benefits. It appears that pysimCoder only runs on Linux. And, I would prefer not to adopt BDSim because it depends on PyQt5, which has a more restrictive license. So, I am considering using one of the following tools for the plotting functionality. I would appreciate hearing your thoughts on this. Mermaid + browser / IPythonFeatures
# mermaid-test.ipynb
import tempfile
import webbrowser
def generate_mermaid_code():
# some jobs to do ...
return r"""
<pre class="mermaid">
graph LR
input@{ shape: stadium, label: "input" }
output@{ shape: stadium, label: "output" }
sumJun1@{ shape: sm-circ }
K["$$K$$"]
P["$$P\ :\begin{cases}\begin{aligned} \dot{x}(t) & = Ax(t) + Bu(t) \\\\ y(t) & = Cx(t) + Du(t) \end{aligned}\end{cases}$$"]
sep1@{ shape: f-circ }
input -->|"$$r$$"| sumJun1
sumJun1 --> |"$$e$$"| K
P --> |"$$y$$"| sep1
sep1 --> |"$$y$$"| output
K --> |"$$u$$"| P
sep1 --> |"$$-1 \times y$$"| sumJun1
classDef inout fill:#7ca;
class input,output inout
</pre>
"""
class InterconnectedSystem:
def _repr_html_(self):
html = f"""
<script src="https://cdn.jsdelivr.net/npm/mermaid@11.9.0/dist/mermaid.min.js"></script>
{generate_mermaid_code()}
<script>
if (window.mermaid) {{
mermaid.initialize({{startOnLoad:true}});
mermaid.init(undefined, document.querySelectorAll(".mermaid"));
}}
</script>
"""
return html
InterconnectedSystem() # Draws the block diagram in Jupyter Notebook ![]() NetworkXFeatures
# networkx-test.ipynb
import networkx as nx
import matplotlib.pyplot as plt
plt.rcParams.update({
"mathtext.fontset": "cm",
'pdf.fonttype': 42,
'ps.fonttype': 42,
})
# define node and labels
labels = {
1: r"$P$",
2: r"$\frac{s-1}{(s+1)(s-2)}$",
3: "TransferFunction()",
4: "K"
}
G = nx.DiGraph()
for n, label in labels.items():
G.add_node(n, label=label)
G.add_edges_from([(1, 2), (2, 3), (3, 1), (1, 4)])
# calculate node sizes based on label size
font_size = 16
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=False)
nx.draw_networkx_labels(G, pos, labels, font_size=font_size)
plt.show() ![]() |
Beta Was this translation helpful? Give feedback.
-
Hi @knttnk From the perspective of appearance, I think Mermaid definitely looks much better. My take is I think either is OK. Javascript-based renderers have the nice feature that they work anywhere, so that strengthens their. You might try creating your own library that works with python-control that has the desired functionality, that way the core developers can give it a try and think about how to best integrate it. One question, is your intention to provide a simulink-like user interface in which one can draw a block diagram, or simply a graphical representation of an I contemplated whether it might be possible to take any such system to create a block diagram, but I wasnt sure whether an automated process would render a system in a way that would be useful. It also seemed like it would be cumbersome to build something from scratch using matplotlib's built-in arrows, boxes, and latex renderer. Ultimately, I added connection table to the library as a stopgap solution to help with debugging, and more recently the new The solutions you posted might provide a path forward. |
Beta Was this translation helpful? Give feedback.
-
I've started developing a test library at https://github.com/knttnk/pyctrl-block-diagram. I think there are too many arrows in the diagrams. Do you have any suggestions for names, too many arrows, and others? ![]() ![]() ![]() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Are you planning to implement a feature for drawing block diagrams of
InterconnectedSystem
s?If I were to implement it and create a pull request, would you be willing to accept it?
Beta Was this translation helpful? Give feedback.
All reactions