Can't solve port dimension errors in Simulink FOC model - matlab

I am trying to develop an FOC algorithm (see screenshots attached) using the Motor Control Blockset in Simulink, but I am getting the following errors (see screenshot attached). I don't know what I am doing wrong since I fed my d and q currents to my discrete PI controllers and fed the results straight into my Inverse Park Transform. I don't know how to solve this and any help would be greatly appreciated.
Simulink file OneDrive Link:
https://1drv.ms/u/s!AokIrMv_d8kz3BMaImhVY_guP_N-?e=Fu1a1e

I can't open your model. But from your screenshot I see the following:
The little numbers at the signal arrows denote how many signals are in this path. I think it should be always 1 (in your model), except for the three-phase currents, where it should be 3. So everywhere you find a 2 something is wrong.
The probable mistake is, that you Demux the PhaseCur in the lower right corner into only 2 signal paths. For whatever reason it appears that the Clarke transform only demands for the phases a and b, but not c. But instead of dropping c you feed it into the block together with a (or a and b together, with c aside, for that matter). So instead of a 2-Way-Demux before, use a 3-Way-Demux and get rid of phase c before the Clarke transform.
This is the most apparent mistake until now, try if it works.
The documentation of the Clarke transform block states:
The block accepts two signals out of the three phases (abc), automatically calculates the third signal, and outputs the corresponding components in the αβ reference frame. For example, the block accepts a and b input values where the phase-a axis aligns with the α-axis.

Related

Converter control simulation on simulink

I am struggling with a little project I decided to tackle. I am trying to replicate an example I found on a book using matlab simulink but I have no experience with simulink and control theory (I do understand the principles etc.).
The control block diagram is given but I do not understand some blocks and how to add my input (sine wave block on simulink)?
Here are the details:
Example I wish to reproduce
Schematic of the converter and desired control block diagram
If anyone could give me a little insight or direct me to some examples from which I could build on an understanding would be great!
Thank you in advance.
The portion entitled controller is the closed-loop feedback control for the system. K(s) would typically contain some type of PI control. In a more complicated control system, the structure of K(s) may be a little different, but will usually always contain an integration in order to ensure that the system eventually settles at the desired value.
The input Iref is your current command. In this case you would inject your sinusoid here which would produce a current waveform matching your desired output. If your desired output.
Output m is the modulating waveform produced by the controller. Everything inside the half-bridge converter section is a representation of the converter and everything that it is interfaced to (voltage sources).
The feedforward filter here is also a very important component. Since Vs contains an alternating waveform, the feed forward filter allows the system to respond to changes in Vs without relying on feedback compensation K(s). This helps to decouple current regulation from changes in voltage VD.
To start with the project, you can probably build the half bridge converter as shown. You can inject 400*cos(377t - pi/2) as VD.
For the feedback compensator K(s) you can feed the input into two gains (Ki and Kp) which you will select values for later. At the output of Ki insert an integrator (1/s) then sum the output of Kp and the integrator together.
For the feed-forward filter, you should probably just use a low pass filter with a gain of 1 at DC. The low pass filter prevents noise from entering the system. In this case you are running a simulation, so there will be no noise. However, the filter will eliminate any algebraic loops, which can cause warnings or errors in the simulation.
You can input your control signal at Iref.

Error on simple four link mechanism simulation with modelica

I'm trying to implement a 4 link mechanism and the model I've put together is shown here:
Revolute1 has a speed of 5 rad/s. All bars are 0.05 m in diameter. World settings are the default and you can see the bar vectors on the picture. Nothing else is changed.
When I try to run the simulation I get these errors on OpenModelica:
[1] 10:29:43 Symbolic Error
[Modelica.Mechanics.MultiBody.Parts: 238:5-238:62]: Model is structurally singular, error found sorting equations
[2] 10:33:25 Translation Error
Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!
What am I doing wrong? It seems pretty straight-forward. Thanks.
Apart from the required usage of Modelica.Mechanics.MultiBody.Joints.RevolutePlanarLoopConstraint for the planar four bar linkage also the model topology needs to be adapted, asuming bar2 is fixed to world. See the example model Planar4Bar.
You need to replace one of the Revolute joints with a RevolutePlanarLoopConstraint. Why? Citing the documentation:
If a planar loop is present, e.g., consisting of 4 revolute joints
where the joint axes are all parallel to each other, then there is no
unique mathematical solution if all revolute joints are modelled with
Joints.Revolute and the symbolic algorithms will fail. The reason is
that, e.g., the cut-forces in the revolute joints perpendicular to the
planar loop are not uniquely defined when 3-dim. descriptions of
revolute joints are used

Combination of two signals to determine the end signal sent through Simulink code

Goal
I'm trying to have a second signal (caused by force applied to a sensor's surface area), once it reaches a set minimum, to determine a servo motor's position. The motor's position is otherwise determined by a first signal (generated by EMGs that are measured with electrodes placed on a subject's body) that make give the servo preset positions when the signal crosses a certain threshold.
Schematic
I cannot seem to get the two signals to work together. Any corrections and recommendations on how to make the logic within Simulink function as intended would be immensely appreciated. I know little of the program and cannot find a good approach.
In your diagram you go from numeric values (Sensors) to logical ones (>=301) back to numeric (*90) and again to logical (AND). What you are doing may be possible but hides the intention. First of all I would recommend you to clearly distinguish between logical conditions and values, similar to the following model. To help you with that you can turn on data-type display from Format > Port/signal display > Signal data types followed by an Update (Ctrl-D).
Alternatively you could reduce the conditions as much as possible and operate only with values, such as
However I do not fully understand your requirements and I'm also not sure what the input of the servo is representing (Speed, position, ...)? Maybe you could explain the desired behaviour a bit more detailed? In particular how do you come up with the limits (301, 300, ...).

Generating square wave using Matlab embeded function

I intend to generate a square wave which is applied on a DSP.
I have written these codes and put them in an embeded Matlab function.
function y = fcn(u)
%#eml
t=0:0.001:1
h = sign(sin(125600*t+u));
y= (h+1)/2
where, u is a constant value of 0.582 which is used for shifting the square wave.
The problem is at the output in the simulation, instead of getting a square wave, I see only two straight lines of y=o and y=1.
Please let me know where is the problem that I can not get the square wave?
Note that the frequency of square wave must be 20 kHz. Therefore, I adjust the sampling time as 1e-7 s. And also its amplitude is between 0 and 1 In addition, due to this signal must be transferred to a DSP board, in the "solver option" I chose the type: " Fixed-step" and for the Solver: "Discrete (no continues state)".
Thanks a lot.
This is wrong on many levels.
First of all, you never define the time vector inside a MATLAB Function, that's what the Simulink engine does. Pass time as an input to your MATLAB Function block and use a Clock block to generate the time input.
Second, the above is fine for simulation, but it sounds like you are generating C code from the Simulink model to run it (in real-time) on your DSP. This is not my area of expertise, but from memory, I think you need to enable "absolute time" or something similar for the above to work with code generation. However, I think this is target-dependent and so I'm not sure whether this will work on your DSP.
In you function type plot(t,y) at the end. You are generating a 20khz square wave (assuming you are sampling at 1e-7). Essentially your generating it is working.
Now, what is the DSP board you are using/any information that is relevant to your problem?
I don't know what you are referring to when you say "Solver" either.
Is the "simulation" an oscilloscope or a program? Either way perhaps it is not triggering correctly? Is there an edge trigger option?

Rotational mechanical system in Simulink

I'm simulating a shaft system in Simulink, where I have to find the displacement of a mass. I'm not sure how to model this in Simulink because of the shaft and pulley. I'm looking through the documentation and the closest thing I see to a shaft is the wheel and axle block. But the shafts are connected by a flexible shaft, which is similar to a spring. Any ideas?
This is a fairly trivial task when using SimScape, which is especially made to simulate physical systems. You'll find most of the blocks you need ready from the library.
I've used SimScape to create a model of a complete hybrid truck... In Simulink it can be done, but you'll need to build your own differential equations for the task. In your case, the flexible axle could be translated to another block with a spring/damper system inside.
If you haven't got access to SimScape, you may also consider to use .m (matlab) files to write your differential equations. This can then be used as a block in Simulink, varying (only) a few parameters over time.
Take this step by step:
1. Draw a free body diagram, write out equations for all the forces as a function of displacement, velocity and acceleration of every element (including rotation obviously). For instance, you know that force on the box m will be *c*dy/dt* plus whatever the pulley experiences.
2. Sort out the rotation of the rod first. You know that *T=I*d(omega)/dt* if you get rid of the rest of the system. So, do something analogous to the car engine example of MatLab: Divide the input T by I to get the acceleration, integrate it to get velocity and one more time to get rotational displacement.
3. Keep adding bits one by one. First, you know that there will be a moment proportional to k*(theta_1-theta_2) acting. This will oppose the motion of rod 1 and act to create motion of rod 2. Add a new "branch" to your model to get theta_2 same way you got theta_1.
4. Go on including further elements...