Changing image in an algebraic loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
3 Kommentare
Antworten (1)
Fangjun Jiang
am 29 Jun. 2020
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 Kommentare
Fangjun Jiang
am 29 Jun. 2020
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".
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!