Gear Shifting System MATLAB Function
15 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Benjamin Thompson
on 14 Feb 2022
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.
0 Comments
Image Analyst
on 15 Feb 2022
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
0 Comments
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!