Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of integrator of hybrid system on a Python project #2

Open
traversaro opened this issue Dec 2, 2020 · 6 comments
Open

Example of integrator of hybrid system on a Python project #2

traversaro opened this issue Dec 2, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@traversaro
Copy link

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, perhaps odedc 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 .

@petercorke
Copy link
Owner

Thanks for your interest, yours is the first comment!

I'm happy to work with anybody who'd like to contribute something in this area. I've got a few ideas sketched out about how I can use SciPy to do this better, but this project is on the back burner at the moment while I get the robotics and vision toolboxes up to a good level of maturity.

@sawyerbfuller
Copy link

Dear Peter, great piece of software. We recently introduced a similar feature in python-control called interconnect that uses a slightly different approach that entails naming signals. Your approach has the nice attribute that the code appears very simple. We will be keeping an eye on this!

I read with some interest your remark that python is still in need of an integrator for hybrid discrete-continuous systems; we are definitely in need of such a feature for python-control. Thanks @traversaro for the pointer.

@petercorke
Copy link
Owner

petercorke commented Aug 19, 2021 via email

@sawyerbfuller
Copy link

Hi @petercorke looks like maybe github stripped the attachment? You can email it directly to me if easier at minster@uw.edu .

Very interested in your gui work, because not having a simulink-like gui -- and/or a hybrid integrator we can use with interconnect -- has been a main limitation for students using python-control vs matlab in the controls class I have been teaching.

@petercorke petercorke added the enhancement New feature or request label Jul 6, 2023
@petercorke
Copy link
Owner

The Scipy solve_ivp integrator has event handling which might be usable. Would need to add a guard method to each block that throws events and pass a list of these to the solver.

@sawyerbfuller
Copy link

Looks like the docstrings in solve_ivp have been updated to clarify something that I had been confused by before: that setting t_eval seemed to have no effect on the points that were evaluated. Now it is clear that its purpose is only to specify which points are returned.

That said, indeed it looks like events could be used to specify time points to make sure to evaluate. But, it seems like specifiying evenly-spaced events would go through a quite roundabout process in the integrator if I understand correctly. You would need to specify a function that has repeated zero-crossings - the obvious choice being perhaps a sinusoid that crossed zero at every dt of each discrete-time system? And then the integrator would go and do a slow, interative zero-crossing search for each of those, rather than just evaluating at points you already knew ahead of time. This seems slow but better than nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants