Skip to content

Implementing Generic Input Output Functions #1149

Closed

Description

@natecheadle

Hello,

I am trying to use this library to model alternative implementations of various algorithms for current control of a 3 phase motor.

The basic outline is as follows:

Current-Target -> PI -> Inverse Park/Clarke -> SVM -> Motor Model -> Current Sense Model -> Park/Clarke -> Current Measured (feedback)

Specifically my question is it possible to have essentially generic function blocks that given a set of inputs return a set of outputs independent of time. My hope is to be able to have a few versions of these and drop them into the model for comparison. A trivial example I tried was attempting to get the park transform working. I tried the following of trying to hack a non-linear system to do this but it doesn't work (which I believe is expected):

import matplotlib.pyplot as plt
import numpy as np
import control as ct

def inverse_park_transformation_out(t, x, u, params):
    return [x[0],x[1]]

def inverse_park_transformation(t, x, u, params):
    q = u[0]
    d = u[1]
    angle = u[2]

    alpha = d * np.cos(angle) - q * np.sin(angle)
    beta = d * np.sin(angle) + q * np.cos(angle)

    return [alpha, beta]

inv_park = ct.nlsys(updfcn=inverse_park_transformation, outfcn=inverse_park_transformation_out, inputs=[
                    "q", "d", "angle"], outputs=["alpha", "beta"], states = ["alpha", "beta"],name="inv_park")

dt = 50e-6
f = 100
t = np.arange(0.0, 0.02, dt)
q = np.ones_like(t)
d = np.zeros_like(t)
angle = np.sin(2 * np.pi * f * t) * np.pi

t, y, s = ct.input_output_response(sys=inv_park, T=t, U=[q, d, angle], return_x=True)
plt.plot(t, q, label="V_q")
plt.plot(t, d, label="V_d")
plt.plot(t, angle, label="$\\theta$")
plt.plot(t, y[0], label="v_alpha")
plt.plot(t, y[1], label="v_beta")
plt.legend()
plt.show()

Activity

  1. locked and limited conversation to collaborators on May 29, 2025
  2. converted this issue into a discussion #1150 on May 29, 2025
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