Skip to content

Plotting while computing #1260

Open
Open

Description

@lcp5y3

At first thank's for all this work.
Disclaimer: This an help request and I'm not sure if it's the right place to ask for it.

I'm looking for a way to plot the IO_response while computing it. For long computing, it can be usefull to stop it if the result doesn't match the requirement before the end of the simulation.

Activity

  1. slivingston commented on Oct 27, 2026

    @slivingston
    Member

    Which method of control are you waiting on? If it is control.nlsys.input_output_response(), then the question may be: does SciPy solve_ivp allow early termination conditions or plotting during computation? (For a continuous time system, input_output_response calls solve_ivp.)

    Can you share an example of code for which you want plotting while computing?

  2. lcp5y3 commented on Oct 27, 2026

    @lcp5y3
    Author

    This is an example:

    import matplotlib.pyplot as plt
    import numpy as np
    import control as ct
    
    R = 0.0609   # Ohm
    L = 0.000023 # H
    Kt = 46      # mNm/A
    Ke = 0.0048  # V/rpm
    Kf = 0.275   # rpm/mNm
    J = 0.000138 # kgm²
    tf_uc = ct.tf([Kt],[L, R])
    tf_uc.name = "couple_tension"
    
    tf_cv = ct.tf([1],[J,Kf])
    tf_cv.name = "vitesse_couple"
    
    tf_ke = ct.tf([Ke],[1])
    tf_ke.name = "ke"
    
    mot_input = ct.summing_junction(inputs=['U','-ke'], output='Umot',name='sumU')
    
    couple_input = ct.summing_junction(inputs=['Cmot', '-Cr'], output='dC', name='sumC')
    
    moteur = ct.interconnect([tf_uc, tf_cv, tf_ke, mot_input, couple_input], name="moteur",
                             connections=[
                                 ['couple_tension.u', 'sumU.Umot'],
                                 ['sumC.Cmot', 'couple_tension.y'],
                                 ['vitesse_couple.u', 'sumC.dC'],
                                 ['ke.u', 'vitesse_couple.y'],
                                 ['sumU.ke', 'ke.y'],
                             ],
                             inplist=['sumU.U', 'sumC.Cr'], inputs=['U', 'Cr'],
                             outlist=['vitesse_couple.y'], outputs='vitesse'
                            )
    
    t = np.linspace(0,1,10000)
    U = np.concatenate((np.zeros(5000), 10* np.ones(5000)), axis=None)
    Cr = np.zeros(t.shape)
    moteur_step_res = ct.input_output_response(moteur, t, [U, Cr])

    In function of the simulation configuration ct.input_output_response can take time and it's where I'm asking if it's possible to plot output while computing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions