create a pole feedback control in javascript

To create a pole feedback control in JavaScript, one could use the Control System Toolbox provided by MathWorks. The toolbox contains several functions for designing and analyzing control systems, including functions for pole placement.

To illustrate how to create a pole feedback control in JavaScript, let's consider the following second-order system with transfer function:

index.tsx
               b
G(s) = -------------------
       s^2 + as + b
64 chars
4 lines

where a and b are constants.

To design a pole feedback control for this system, we need to place the closed-loop poles at specific locations in the complex plane. This can be achieved using the place function of the Control System Toolbox, which computes the feedback gain matrix K such that the eigenvalues of the closed-loop system match the desired pole locations.

Here's the JavaScript code to create a pole feedback control for the above system:

index.tsx
// Define the system transfer function
const a = 2;
const b = 5;
const num = [0, 0, b];
const den = [1, a, b];
const sys = controlSystem.tf(num, den);

// Define the desired pole locations
const poles = [-1, -2];

// Compute the feedback gain matrix
const K = controlSystem.place(sys.a, sys.b, poles);

// Create the closed-loop system
const sysCL = controlSystem.feedback(sys, controlSystem.matrixMultiply(K, sys.c), sys.d);

// Simulate the step response of the closed-loop system
const t = controlSystem.linspace(0, 10, 100);
const step = controlSystem.step(sysCL, t);

// Plot the step response
controlSystem.plot(t, step);
628 chars
23 lines

In this code, we first define the system transfer function as a ratio of polynomials, using the constants a and b defined earlier. We then define the desired pole locations as an array of complex numbers.

We then use the place function to compute the feedback gain matrix K that will place the closed-loop poles at the desired locations. The place function takes the state-space matrices of the system (A, B, C, and D) and the desired pole locations, and returns the feedback gain matrix.

We then create the closed-loop system using the feedback function, which takes the open-loop system, the feedback gain matrix, and optional values for the input and output channels, and returns the closed-loop system.

Finally, we simulate the step response of the closed-loop system using the step function and plot the result using the plot function.

This code should output a plot of the step response of the closed-loop system, which should converge to the desired setpoint with no overshoot.

gistlibby LogSnag