Hi there,
I hope somebody will be able to help me with a simple (at least I was thinking like this) code… I need to implement the algorithm in Labview has been designed in Matlab/Simulink. The trickiest part for me was implementation of Memory blocks (initial value=350 and initial value=0) that will be able to save values for the previous iterations.
function u2=fcn(speed,u2d)
if speed>120
u2=u2d+0.25;
else
u2=u2d;
end
![1.png 1.png]()
AI measures an electro-hydraulic drive speed. AO generates a control signal that will power up the drive-train. When the speed exceeds a threshold (120 in our case) the code should decrease the control voltage in order to decelerate the drive and stay below the threshold without any further changes (hence the control system should keep the latest “successful” voltage). The model above runs the drive at 350 rpm from its start.
In the algorithm I am doing the comparison speed>120 and sending its Boolean output to a switch with two inputs (0 – false) and u2d – true. The reason I’ve designed to use 0 is because I don’t want any changes to the control voltage before the algorithm kicks in. The code u2 = u2d + 0.05 is built on shift registers. And then u2/u2d I am subtracting from the control voltage to decrease it to the required level below 120 threshold.
The point is that after the comparison speed > 120 becomes “false”, I want to keep the value of the voltage (u2=u2d). But since I am using a switch in the top part, when it gives falls, it sends zero + 0.05 to the node AO0 and then the cycle starts again (these voltage spikes gives speed spikes). I was trying to use different combinations of switches and also case structures, but any results. I know that I miss something simple but could not figure what exactly. Will be great if somebody can help out with this case. Thank you in advance.