Gear Shifting System MATLAB Function

15 次查看(过去 30 天)
I'm trying to create a gear shifting system as MATLAB Function Block. The system uses rpm value as input. If the speed exceeds the upper limit or goes below the lower limit, the gear needs to be changed. If the speed stays between the two limit values after the gear changes, the gear should maintain its (last output) value , but I could'nt figure out how to achieve this. I wrote a simple if else function but I don't know what to write for last "else" statement. I set the value of the "gear" parameter to 1 as a starting point in workspace. Can I get some help? I hope I've explained the situation properly.
function gearIn = set_GearIndex(rpm, gear)
if rpm > 5354.8387 & gear < 5
gearIn = gear+1;
elseif rpm < 3197.580 & gear > 1
gearIn = gear-1;
else
% What should I write here and how gear maintain its last value between this 2 limits? %
end

回答(2 个)

Benjamin Thompson
Benjamin Thompson 2022-2-14
Here is a general article about hysteresis, which refers to the idea of having a different threshold to use depending on the direction of the state transition you are making.
You function would need more information about thresholds that needs to be crossed to change gears. Start with the problem of just two gears then scale it up to all five.

Image Analyst
Image Analyst 2022-2-15
I don't think you need to do anything. Just leave it in the same gear. However you're not assigning gearIn. You need to always return gearIn regardless if you enter an if or not. So just initialize it like this:
function gearIn = set_GearIndex(rpm, gear)
gearIn = gear; % Initialize it so that it stays in the same gear.
if rpm > 5354.8387 & gear < 5
gearIn = gear+1; % Change it to a higher gear.
elseif rpm < 3197.580 & gear > 1
gearIn = gear-1; % Change to a lower gear.
end
end

类别

Help CenterFile Exchange 中查找有关 Assembly 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by