I'm Peter, I'm a robotics educator and researcher.
- I'm currently working on a bunch of packages for robotics, machine vision and block diagram simulation.
Simulate dynamic systems expressed in block diagram form using Python
License: MIT License
test that this actually works. we know single level imports work
Hi, good job. this is a very useful software
I'm trying to use PSO optimization algorithm along with your software, but in the first step, I can not run any example of your software and I have no idea why!
I installed all modules except spatialmath, because it can not be installed. I installed spatialmath-python instead that I think it is ok.
I downloaded the project, and want to run eg1.py in example folder and I get some errors. what is going wrong? can you help me please?
this is one of my errors:
Traceback (most recent call last):
File "C:\Users\argha\Desktop\rasa\bdsim-master\bdsim-master\examples\eg1.py", line 8, in
sim.blocks()
AttributeError: 'BDSim' object has no attribute 'blocks'
thank you in advance...
i'm trying to simulate a block diagrame that contain a pid controller,and from what i know pid transfert fonction is
as we can see this is not a proper transfert function (degree of the numerator > degree of the denominator) and from the documentation i found that this is not suported .so when i try to define the pid in the code like this
it throws this error
i want to know if there is any solution or we cant implement a pid yet with this package ?
thank you.
Hi, bdedit
can't start when bdsim
is installed from PyPI:
# apt-get -y install python3-pyqt5
# pip3 install bdsim==0.9.0
(snip, no errors)
$ bdedit
Traceback (most recent call last):
File "/usr/local/bin/bdedit", line 5, in <module>
from bdsim.bdedit import main
File "/usr/local/lib/python3.8/dist-packages/bdsim/bdedit/__init__.py", line 14, in <module>
from .interface import *
File "/usr/local/lib/python3.8/dist-packages/bdsim/bdedit/interface.py", line 15, in <module>
from bdsim.bdedit.block_importer import *
File "/usr/local/lib/python3.8/dist-packages/bdsim/bdedit/block_importer.py", line 14, in <module>
from examples import docstring_parser as parser
ModuleNotFoundError: No module named 'examples'
$ find /usr/local/lib/python3.8/dist-packages/bdsim/ -name '*examples*'
(nothing found)
Dear Peter,
I appreciate your work. I have a brief question using bdedit.
I tried to use a custom function in the bdedit. Is it possible or not?
From the code (bdsim), I can easily understand that I can create a specific function or lambda for the block.
However, I don't clearly understand how to use the function block from bdedit side.
Or can I create bdedit from bdsim directly? I read that I can load bd file to bdsim.
But, I couldn't find anything regarding vice versa.
Thank you in advanced.
bdedit
relies on PyQt5, which has a GPL license, and that seems to create problems with PyQT5
Here is the license for PyQT5: PyQt5 is released under the GPL v3 license and under a commercial license that allows for the development of proprietary applications.
bdsim
has a MIT license, but including PyQT5 makes the application a GPL application, unless buying a commercila license.
An alternative would be to switch from PyQT5 to PySide6
The main notable difference between PyQT5 and PySide6 is licensing โ with PyQt6 being available under a GPL or commercial license, and PySide6 under a LGPL license.
The PySide6 wheel is an alias to other two wheels PySide6_Essentials and PySide6_Addons, which contains a predefined list of Qt Modules.
Switching from PyQT to PySide is documented here. Little more complicated than sed -i s/PyQT5/pyside/g source.py
but can be done easily...
Moreover, QT recommend to use PySide6.
QTCreator can be used with PySide6.
Hi, nice project. Quick question:
I'm following your README and trying to run the graphical editor. When I navigate to the examples folder and type "bdedit eg1.bd", I get "ValueError: bdfile eg1.py not found".
Obviously the file doesn't exist, but there doesn't seem to be any *.bd files in the repo. Can you provide example .bd files? Why are they not present?
Thanks!
This leads to issues in conda-forge, where packaging fails as the setup.py reads in contents from RELEASE.
For bugs with the graphical tool bdedit
please use the bdedit
bug report template.
BUG
connecting output of INTEGRATOR to LTI_SS (or LTI_SISO) block fails with this error message:
[lti_siso block: PLANT.deriv]: exception AssertionError
deriv: block PLANT returns wrong shape (4,), should be (2,)
File "/home/grunberg/algopower/bdsim2/bdsim/blockdiagram.py", line 1128, in deriv
raise AssertionError(
input 0 from integrator.0 [ndarray]
[0.]
To Reproduce
#!/usr/bin/env python
import sys
import numpy as np
import bdsim
print(f'Python {sys.version=}')
#print(f'bdsim version {bdsim.__version__}')
print(f'numpy version {np.__version__}')
sim = bdsim.BDSim()
bd = sim.blockdiagram()
tc1=10
tc2=40
a=1/tc1
b=1/tc2
num = [a*b]
den = [1, a+b, a*b]
# blocks
ref = bd.STEP(T=1, off=0, on=1.0,name='ref')
integrator = bd.INTEGRATOR(gain=1)
#gain = bd.GAIN(5)
plant = bd.LTI_SISO(num, den, name='PLANT')
# connections
bd.connect(ref, integrator)
bd.connect(integrator, plant)
print(bd.blocklist)
bd.compile(verbose=False)
sim.report(bd)
out = sim.run(bd, 5)
print(out)
Expected behavior
Should compile and run without error
Operating environment (please complete the following information):
Additional context
Looking at the inputs to the deriv method of the LTI_SS class in the example above:
The problem is that ref (in the example above) from a STEP is a signal u=[1.0], but the output of the INTEGRATOR block is u=[array([1.0])]. In the LTI_SS.deriv function, self.B @ np.array(u) causes a problem, as the STEP signal makes this shape (2,) vs. INTEGRATOR output shape (2,1). Since the A@x shape is (2,) adding a shape (2,) to a shape (2,1) causes broadcasting and produces a shape (2,2) which is then flattened into (4,) which is the wrong number of outputs.
I will post a pull request fix which corrects this in LTS_SS.deriv. An alterative fix to change the output of the INTEGRATOR block to match STEP output - the choice of fix depends on other blocks and if the two signals here are OK or whether all signals should be forced to a list of floats rather than a list of arrays.
Running a simple block with just a PID controller, I get the error "PID object has no attribute 'bd'"", see below.
I believe the problem is that in the PID class, super() is not called until the end, yet the first line of code in the init function is subsystem = self.bd.runtime.blockdiagram()
at which point self.bd does not yet exist.
In trying to fix this, I am not sure what PID should be subclassed from, as Deriv uses SubsystemBlock, but PID uses SubSystem, and LTI_SS uses TransferBlock.
I could try to fix this with a hint as to which class it should be based on. Also the PID documentation refers to 2 inputs (ref and plant output) but the code seems to have 1 input.
Thanks for what looks like a great package.
Python sys.version='3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]'
bdsim version 1.1.1
* Simulate temperature control system
package roboticstoolbox not found
package machinevisiontoolbox not found
Traceback (most recent call last):
File "/home/grunberg/algopower/./bug.py", line 17, in <module>
controller = bd.PID(P=10, D=0, I=1, I_band=100)
File "/home/grunberg/venv/blocks/lib/python3.10/site-packages/bdsim/run_sim.py", line 969, in block_init_wrapper
block = cls(*args, bd=bd, **kwargs) # call __init__ on the block
File "/home/grunberg/venv/blocks/lib/python3.10/site-packages/bdsim/blocks/transfers.py", line 625, in __init__
subsystem = self.bd.runtime.blockdiagram()
AttributeError: 'PID' object has no attribute 'bd'
The file is
#!/usr/bin/env python
'''
Simulate temperature control system
'''
import matplotlib.pyplot as plt
import sys
import numpy as np
import scipy.signal as signal
import bdsim
print(f'Python {sys.version=}')
print(f'bdsim version {bdsim.__version__}')
sim = bdsim.BDSim()
bd = sim.blockdiagram()
ref = bd.STEP(T=1, off=0, on=.3,name='ref')
controller = bd.PID(P=10, D=0, I=1, I_band=100)
scope = bd.SCOPE(styles=['k','r--'])
# connect
bd.connect(ref, controller,scope[0])
bd.connect(controller, scope[1])
bd.compile()
sim.report(bd)
out = sim.run(bd, 100)
print(out)
Hi @petercorke,
thanks a lot for sharing such a tool, it seems to be quite interesting.
I saw that in the README it is written that:
The biggest is that
bdsim
is based on a very standard variable-step integrator from the scipy library. For discontinuous inputs (step, square wave, triangle wave, piecewise constant) the transitions get missed. This also makes it inaccurate to simulate hybrid discrete-continuous time systems. We really need a better integrator, perhapsodedc
from SciLab could be integrated.
Unfortunately I do not have a lot of time on working on this, but if anyone is interested in working on this, a good example of an integration of an advanced integrator that support for example hybrid system can be found in the FMPy project. In particular, the fmpy.sundials.cvode
contains a Python interface to the Sundials' CVODE integrator. An example of use of such interface for integrating a hybrid system (bouncing ball) can be found in https://github.com/CATIA-Systems/FMPy/blob/e1927a128a9552f20304587c54c716750e73b05f/tests/test_cvode.py .
Hi @petercorke,
I raised this issue in a comment earlier which is that a cannot launch bdedit on my computer and every time I run the file bdedit.py
I get a message saying (ModuleNotFoundError: No module named 'PyQt5').
I have MacBook Pro (2017), and as you said bdedit is not necessary to execute the diagrams, but I have worked with Simulink before and I thought this would be an important tool to use especially because I don't have a strong background in coding as I am a mechanical engineer and so working with blocks might be more appropriate for me.
This package is great, but if there were more examples and tutorials online on just how it install it and use it properly, it would be even better. Thanks for the hard work that has been done here for us to use such an important tool.
This project looks really interesting to me!
I tried to run the example eg1.py
, but I got the following error message:
- Example of continuous-time system
- Copyright (c) 2021- Peter Corke
package bdsim not found
package roboticstoolbox not found
package machinevisiontoolbox not found
Traceback (most recent call last):
File "/home/mhinkkan/GitHub/bdsim/examples/./eg1.py", line 13, in
demand = bd.STEP(T=1, name="demand")
^^^^^^^
AttributeError: 'BlockDiagram' object has no attribute 'STEP'
My setup is as follows:
I tried to run the example both from the command line and from the VSCode (in both cases using the virtual environment), with same end result. The same problem appears with other examples as well.
Describe the bug
Here this is the log I get on Ubuntu 22.04
$ bdedit
bdedit is beta code and prone to random crashing, save your work often
Traceback (most recent call last):
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface_scene.py", line 143, in determineFont
self._system_font = ImageFont.truetype("arial.ttf", 14)
File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 861, in truetype
return freetype(font)
File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 858, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 203, in init
self.font = core.getfont(
OSError: cannot open resource
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/gambler/pythonEnv/bin/bdedit", line 8, in
sys.exit(main())
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/bdedit.py", line 114, in main
window = InterfaceWindow(screen_resolution, args.debug)
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface_manager.py", line 35, in init
self.initUI(resolution, debug)
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface_manager.py", line 39, in initUI
self.interface = Interface(resolution, debug, self)
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface.py", line 78, in init
self.initUI(resolution, debug, parent)
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface.py", line 121, in initUI
self.scene = Scene(resolution, self.layout, main_window)
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface_scene.py", line 88, in init
self.determineFont()
File "/home/gambler/pythonEnv/lib/python3.10/site-packages/bdsim/bdedit/interface_scene.py", line 145, in determineFont
self._system_font = ImageFont.truetype("Arial.ttf", 14)
File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 861, in truetype
return freetype(font)
File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 858, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 203, in init
self.font = core.getfont(
OSError: cannot open resource
Hi Professor Corke, thank you for your precious work. when opening bdedit, I was encountering the following error (with the program crashing on startup):
Traceback (most recent call last):
File "/home/flavio/University/robotics/project/bdsim/bdsim/bdedit/interface_scene.py", line 143, in determineFont
self._system_font = ImageFont.truetype("arial.ttf", 14)
File "/home/flavio/Programs/anaconda3/envs/robotics/lib/python3.10/site-packages/PIL/ImageFont.py", line 996, in truetype
return freetype(font)
File "/home/flavio/Programs/anaconda3/envs/robotics/lib/python3.10/site-packages/PIL/ImageFont.py", line 993, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/home/flavio/Programs/anaconda3/envs/robotics/lib/python3.10/site-packages/PIL/ImageFont.py", line 248, in init
self.font = core.getfont(
OSError: cannot open resource
I don't know if this can be useful, but I (for now) fixed it by modifying this function :
def determineFont(self):
"""
This method sets the truetype font with which socket labels should be drawn.
Originally, this property was set within the sockets themselves, but when
they are constantly drawn/redrawn (i.e. when undo/redo is spammed) and as a
result, multiple attemps are made to access the truetype font, Windows issues
an OSError crashing the program... So since this font only needs to be defined
on startup, the font is accessed whenever the scene is created.
"""
try:
self._system_font = ImageFont.truetype("arial.ttf", 14)
except OSError:
self._system_font = ImageFont.load_default()
Thank you again
. Windows 10 + conda+ python3.9
. bdsim is installed by pip install git+https://github.com/petercorke/bdsim.git
. machinevision is installed by pip install git+https://github.com/petercorke/machinevision-toolbox-python.git
. roboticstoolbox is installed by pip install git+https://github.com/petercorke/robotics-toolbox-python.git
When i try to run the sample code, i got these returns
>>> import bdsim
>>> sim = bdsim.BDSim()
package bdsim not found
package roboticstoolbox not found
package machinevisiontoolbox not found
and then
>>> bd = sim.blockdiagram()
>>> sim.blocks()
0 blocks loaded
>>> demand = bd.STEP(T=1, name='demand')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'BlockDiagram' object has no attribute 'STEP'
any idea why this happens?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.