implementin NMPC in ROS using code generation
조회 수: 4 (최근 30일)
이전 댓글 표시
Is it possible to to use Matlab code generation to implement a ROS node for NMPC?
I have defined a nlmpc object and I am perfoming closed-loop simulations in Matlab using the nlmpcmoveCodeGeneration() command after having created the coreData and onlineData struct using getCodeGenerationData().
Does anyone know if it is possible to implement a ROS node using code generation to import this same controller to ROS envionment? The reason behind this is that I have designed a controller using Matlab simulations, and I would now like to test the controller with real hardware that is operating with ROS.
Currently I am having the following error message when trying to use the code generation:
----------
>>
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.
Error in ==> nlmpcmoveCodeGeneration Line: 265 Column: 20
Code generation failed: View Error Report
Error using codegen
----------
I am using the following script for the code generation. I am using Matlab version 2023a on Ubuntu 20.04
cfg = coder.config("exe");
cfg.Hardware = coder.hardware("Robot Operating System (ROS)");
cfg.Hardware.DeployTo = "Localhost";
cfg.Hardware.BuildAction = "Build and run";
Cfg.DynamicMemoryAllocation = 'off';
cfg.HardwareImplementation.ProdLongLongMode = true;
codegen myTestnode -config cfg
Please let me know if someone has any experience with similiar problems with NMPC or if somone has any suggestions on how to proceed with this.
Thank you!
댓글 수: 4
Josh Chen
2023년 5월 11일
Hi Mikael,
This simplified function looks like a good point to start. Could you please also provide a dummy "coreData" and "onlineData" so that I can try this out on my end and see where it failed?
One thing I observe in this script is "~isempty(msg_get1.X>0)", I believe this will always return "true". If you would like to only run the code when receiving a message with X larger than 0, you can remove "~isempty()".
Thanks,
Josh
채택된 답변
Josh Chen
2023년 5월 12일
Hi Mikael,
Thanks for sharing this additional information. I think using "goal variable" is a smart idea for generating the ROS node with mpc. The error message you saw earlier indicates that the first argument for nlmpcmoveCodeGeneration need to be constant. Based on the script you provided, it seems you are not planning to change the value of "coreData" anyway.
To let MATLAB coder understand this global variable will be a constant, you can specify it with "-globals" and "coder.Constant":
>> global_values = {'coreData', coder.Constant(coreData), 'onlineData', onlineData};
>> codegen myTestnode -config cfg -globals global_values
Thanks,
Josh
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Code Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!