By the way, the "for" loop size (the numOfTrackedChannels variable), when run from Matlab has value 6. Hence, it is an interesting question how Matlab Coder can see this value of being infinite.
Codegen bug - infinite "while" loop generated in place of simple "for" loop
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dusko Vujadinovic
el 4 de En. de 2022
Respondida: Sumit Ghosh
el 10 de En. de 2022
It looks that I encountered the codegen bug. I have a MEX application with multiple entries, i.e. I run the Matlab code as skeleton that calls a few MEX files. For one of them the code apparently ends up in the infinite loop. When I do not run the MEX file for that function (in the coder.runTest() I do not select that function to run as MEX file), so I simply run .m function instead - to code behaves fine.
Also, apparently since the codegen wrongly decides to generate the infinite loop it does not generate any code after that infinite loop. That "for" loop that gets generated as infinite "while" loop is a simple one - one line "printf" (see below). If I simply comment out the loop, the code gets generated, on the first glance it looks OK - but its behaviour is odd, it does not work as from Matlab - yet to debug it in C environment, to provide more details. By the way, for almost 6 months I have been generating the code which was working fine, but suddenly I have plenty of problems. I also encountered other problems where my generated code does not behave as Matlab code, but I am focused right now to only this problem with infinite loop being wrong generated, since that one seems a simple to see.
If this atracts the attention from Matlab supports I am happy to send relevant files.
Matlab "for" loop code:
% why codegen here generates infinite while loop?
for channelNr = 1: numOfTrackedChannels
fprintf('Chan%2u: Nk_ms: %u, codePhase_chips: %4f, pseudoRanges_ms: %4f, fractPseudoRanges_ms: %4f, predictedPseudoranges_ms: %4f, satClockBias_ms: %4f\n',...
uint32(channelNr), uint32(Nk_ms(channelNr)), codePhase_chips(channelNr), pseudoRanges_ms(channelNr), fractionalPseudoRanges_ms(channelNr), predictedPseudoranges_ms(channelNr), satClockBias_ms(channelNr));
end
Generated "while" infinite loop: (
/* why codegen here generates infinite while loop? */
/* 'calcUserPos:58' for channelNr = 1: numOfTrackedChannels */
while (1) {
/* 'calcUserPos:59' fprintf('Chan%2u: Nk_ms: %u, codePhase_chips: %4f, pseudoRanges_ms: %4f, fractPseudoRanges_ms: %4f, predictedPseudoranges_ms: %4f, satClockBias_ms: %4f\n',... */
/* 'calcUserPos:60' uint32(channelNr), uint32(Nk_ms(channelNr)), codePhase_chips(channelNr), pseudoRanges_ms(channelNr), fractionalPseudoRanges_ms(channelNr), predictedPseudoranges_ms(channelNr), satClockBias_ms(channelNr)); */
d0 = muDoubleScalarRound(Nk_ms_data[0]);
if (d0 < 4.294967296E+9) {
if (d0 >= 0.0) {
u2 = (uint32_T)d0;
} else {
u2 = 0U;
}
} else if (d0 >= 4.294967296E+9) {
u2 = MAX_uint32_T;
} else {
u2 = 0U;
}
c_print_processing(u2, codePhase_chips_data[0], pseudoRanges_ms_data[0],
fractionalPseudoRanges_ms_data[0],
predictedPseudoranges_ms, satClockBias_ms_data[0],
&validatedHoleFilling_f2, &validatedHoleFilling_f3,
&validatedHoleFilling_f4, &validatedHoleFilling_f5,
&validatedHoleFilling_f6, &validatedHoleFilling_f7);
mexPrintf("Chan%2u: Nk_ms: %u, codePhase_chips: %4f, pseudoRanges_ms: %4f, fractPseudoRanges_ms: %4f, predictedPseudoranges_ms: %4f, satCl"
"ockBias_ms: %4f\n", 1U, validatedHoleFilling_f2,
validatedHoleFilling_f3, validatedHoleFilling_f4,
validatedHoleFilling_f5, validatedHoleFilling_f6,
validatedHoleFilling_f7);
}
5 comentarios
Sumit Ghosh
el 10 de En. de 2022
A bug has been created for the development team.
Someone will update this post once some progress is made.
Respuesta aceptada
Sumit Ghosh
el 10 de En. de 2022
This problem is fixed in R2018b and later.
You can try in R2018b or later. If you can't upgrade, please reach out to Technical Support.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!