(matlab coder) Unable to package?

3 visualizaciones (últimos 30 días)
cui,xingxing
cui,xingxing el 24 de Jul. de 2023
Editada: cui,xingxing el 25 de Jul. de 2023
When I try the following code for C++ class generation,It can be generated successfully, but it fails to be packaged, I get the following error, how can I solve it? your answer would be great appreciate.
open code generation report window and click "Package Code" button
  • select "hierarchical" mode
File cholesky does not exist
  • select "flat" mode
The "flat" mode has the following function rename conflict
For easy reproduction, my minimum code is as follows.
  • Create a new "+SlamGraph2D" directory in the current working directory, and then design a MATLAB class file "slamFactorGraph.m" in this package directory with the following content:
classdef slamFactorGraph<handle
% generate c++ class for corresponding to matlab class
properties (SetAccess = private, GetAccess = public)
NumNodes
NumFactors
end
properties (Access=private)
graph
end
methods
function obj = slamFactorGraph()
obj.NumNodes = 0;
obj.NumFactors = 0;
obj.graph = factorGraph();
end
function addRelFactor2D(obj,nodeIDs,measurement,guessPoseXYTheta)
% nodeIDs = generateNodeID(obj.graph,1,"factorTwoPoseSE2");
f = factorTwoPoseSE2(nodeIDs,Measurement=measurement);% odometry
addFactor(obj.graph,f);
nodeState(obj.graph,nodeIDs(1),guessPoseXYTheta);% guess value
obj.NumNodes = obj.graph.NumNodes;
obj.NumFactors = obj.graph.NumFactors;
end
function optimizeFactorGraph2D(obj)
fixNode(obj.graph,0) % fix the start point.
optns = factorGraphSolverOptions();
optimize(obj.graph,optns);
end
function poses = getNodeState2D(obj)
ids = obj.graph.nodeIDs(NodeType="POSE_SE2");
poses = obj.graph.nodeState(ids);
end
end
end
  • Then,Create a new "slamMapGraph2D.m" entry-point function file in the current working directory with the following contents.
function poses = slamMapGraph2D(measurement,fromID,toID,guesspose)%#codegen
%% custom factor graph
fg = SlamGraph2D.slamFactorGraph();
fg.addRelFactor2D([fromID,toID],measurement,guesspose);
fg.optimizeFactorGraph2D();
poses = fg.getNodeState2D();
end
  • Finally, use the following command to generate the C++ class, it succeeds, but the packaging fails
cfg = coder.config("lib","ecoder",true);
cfg.FilePartitionMethod = "MapMFileToCFile"; % 为每个文件生成C/C++文件,这样方便独立于slamFactorGraph.h,slamFactorGraph.cpp生成使用
cfg.Toolchain = "CMake";% since R2023a,Generate generic CMakeLists.txt file
cfg.GenerateComments = false;
cfg.GenCodeOnly = true;
cfg.CppInterfaceStyle ="Methods";
cfg.TargetLang = 'C++';
cfg.CppInterfaceClassName = 'myGraph';
cfg.InlineBetweenUserFunctions = 'Readability';
cfg.InlineBetweenUserAndMathWorksFunctions = 'Readability';
cfg.InlineBetweenMathWorksFunctions = 'Speed';
measurement = [1,2,3];
fromID = 1;
toID= 2;
guesspose = [1,2,3];
codegen -config cfg slamMapGraph2D -args {measurement,fromID,toID,guesspose} -lang:c++ -report
my env:
ubuntu 20.04
matlab 2023a

Respuesta aceptada

cui,xingxing
cui,xingxing el 25 de Jul. de 2023
Editada: cui,xingxing el 25 de Jul. de 2023
MATLAB's built-in packing function( "Package Code" button or packNGo) has not been updated in time for the new factorGraph support, and its underlying dependency is on third-party libraries such as ceres,eigen, etc. To fix this, you can manually copy the dependent source and header files from the generated "CMakeLists.txt".
I solved the third-party dependency packaging problem by the following CMake method
set(all_src_files ${MATLAB_ROOT}/toolbox/shared/ceres/builtins/libsrc/cerescodegen/cerescodegen_api.cpp
${MATLAB_ROOT}/toolbox/shared/ceres/builtins/libsrc/cerescodegen/factor_graph.cpp
...
omit large numbers of cpp files
set custom package path,
list(LENGTH all_src_files src_files_len)
message(STATUS "NUMBERS:${src_files_len}")
set(package_path ${CMAKE_CURRENT_SOURCE_DIR}/myPackage_codes)
foreach(item RANGE 5 110 1)
list(GET all_src_files ${item} currentSourceFile)
string(REPLACE ${MATLAB_ROOT}/toolbox/shared/robotics/externalDependency ${package_path}/src dstSourceFile ${currentSourceFile})
cmake_path(GET dstSourceFile PARENT_PATH dstSourceFolder)
file(COPY ${currentSourceFile} DESTINATION ${dstSourceFolder})
endforeach()
However, from "CMakeLists.txt" it seems that I can only see the directory of dependent headers, but I don't know exactly what headers are needed, the number of headers and the amount of space they take up!
---------------
By the way, on the above "simple" MATLAB code, the generated source code cpp file as many as 116, if the header file is also taken into account, ceres library include as many as 400 +, eigen library as many as 278. If I set cfg.FilePartitionMethod = "singleFile", it still generates the C++ classes as above, but the user functions/classes are not separate, but inline, I don't it is if a bug issue?

Más respuestas (0)

Productos


Versión

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by