implementin NMPC in ROS using code generation
3 次查看(过去 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!