Throttle Control Issue - Matlab Code Block in Simulink

I am currently trying to set up some logic to simulate how a throttle would be controlled in a vehicle that I am simulating in reference to the vehicle's velocity. I am having trouble coming up with how to correctly model the behaviour I require. Below is my current code.
function [Throttle, CurrentThrottle] = fcn(u1,u2)
Vmin = 15*0.445;
Vmax = 30*0.445;
if(u1 < Vmin)
Throttle = 1;
CurrentThrottle = 1;
elseif(u1 > Vmax)
Throttle = 0;
CurrentThrottle = 0;
elseif u1 > u2
Throttle = 1;
CurrentThrottle = 1;
elseif u1 < u2
Throttle = 0;
CurrentThrottle = 0;
else
Throttle = 0;
CurrentThrottle = 0;
end
CurrentThrottle was a reference value that I am no longer using. I am trying to apply the throttle up to Vmax, then let the vehicle coast (meaning 0 throttle) until I reach Vmin. Then if I drop below Vmin, I would like to accelerate again. This is my latest, and nearly functional model. Others before have been much too complex...
u1 is the velocity input from the system, and u2 is the last velocity input from the system. Essentially: u1 = V(i) & u2 = V(i-1). Below is a picture of the model for reference.
Any help would be greatly appreciated.

 采纳的回答

You do not tell us what u1 and u2 are.
Your current code could be condensed to
function [Throttle, CurrentThrottle] = fcn(u1,u2)
Vmin = 15*0.445;
Vmax = 30*0.445;
if(u1 < Vmin)
Throttle = 1;
elseif(u1 > Vmax)
Throttle = 0;
elseif u1 > u2
Throttle = 1;
else
Throttle = 0;
end
CurrentThrottle = Throttle;
In turn that could be condensed to
function [Throttle, CurrentThrottle] = fcn(u1,u2)
Vmin = 15*0.445;
Vmax = 30*0.445;
Throttle = u1 < Vmin | (u1 <= Vmax & u1 > u2 );
CurrentThrottle = Throttle;
It is not obvious that this is wrong: it depends on what u1 and u2 mean.
What I suspect is that in the time right after u1 stops being less than Vmin, that u1 is not greater than u2 and so the throttle switches off again before it reaches Vmax.

3 个评论

I have updated the question to reflect the missing information. I think I mostly understand where the problem is, but I cannot wrap my head around how to make this function correctly. I have spent way too much time just messing with this small element in my model...
Also, I am not entirely familiar with how you are using the code in your last example in regards to the throttle. Could you possibly explain a little more or offer a resource for me to reference? I have always sided with the modeling side, and my coding is not the strongest..
You do not show any drag in your model, so it is not clear what would reduce the velocity while coasting?
In any case, you do not need to know the previous velocity: you need to know the previous throttle state:
if u1 < Vmin
Throttle = 1;
elseif u1 > Vmax
Throttle = 0;
else
Throttle = Previous_Throttle;
end
Drag force, force of gravity, rolling resistance, traction force, weight transfer, and available motor power are all included in the model, I just have not shown them for the sake of not flooding this post with images. After implementing your code suggested above, it works flawlessly. Thank you for your help.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by