Changing image in an algebraic loop
1 次查看(过去 30 天)
显示 更早的评论
Hey guys,
I have a binary image which feeds a function in SIMULINK. The function changes parts of the binary image (a map) into free space (zeros) by writing it over with zeros. This runs in a algebraic loop with a delay block. So the output of the function, which is "newmap" gets back as "oldmap" into the function. I did the loop such that this changes permanently stay on the image. You can imagine an areay which of the image which was white (1) is now black (0).
small part of the code:
function newmap = fcn(map, cond, oldmap)
newmap = map;
if (cond ~= 0)
oldmap( ceil(abs(uRobot-(coneU*(1/12)))) :floor((uRobot+(coneU*(1/12)))), vRobot:floor((vRobot+sV)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(2/12)))) :floor((uRobot+(coneU*(2/12)))), floor((vRobot+sV)):floor((vRobot+sV*2)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(3/12)))) :floor((uRobot+(coneU*(3/12)))), floor((vRobot+sV*2)):floor((vRobot+sV*3)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(4/12)))) :floor((uRobot+(coneU*(4/12)))), floor((vRobot+sV*3)):floor((vRobot+sV*4)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(5/12)))) :floor((uRobot+(coneU*(5/12)))), floor((vRobot+sV*4)):floor((vRobot+sV*5)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(6/12)))) :floor((uRobot+(coneU*(6/12)))), floor((vRobot+sV*5)):(cv1_p) ) = 0;
newmap = oldmap;
end
So, while I unterstand that this is running in a constant loop I want that if something in the original image (input: map) changes, it should also effect the image based on the algebraic loop.
to specify the problem: there is this input called map (binary image) into the function as one can see from the picture or code. The if-statement overwrites specific areas on the map right? Ok, but when the input "map" changes over time, it does not effect the output. The output updmap/newmap goes straight into an image viewer block. So it takes it when the simulation starts and than ignores it.
I hope someone understands my problem
Thank you & best regards
回答(1 个)
Fangjun Jiang
2020-6-29
A better way in this case is to use persistent variable. doc persistent
But a loop with memory or delay block should also work. What is inside your "algebraic loop" subsystem. I think you need to debug your model first. Put an image viewer block on map to make sure input is changing first.
5 个评论
Fangjun Jiang
2020-6-29
You need to be more precise and accurate. "If statement" won't run in an infinity loop.
The MATLAB Function block is executed at every simulation step. If (cond ~= 0) is always satisfied, then nothing is wrong here. You need to look outside of this block to see when and how "cond" is affected by the output of "newmap". Otherwise, if the value of "cond" never changes, then the "if statement" is always executed in every simulation step. That is probably what you mean "infinity loop".
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!