Menu

Mex files building for other C source functions

2023-08-29
2023-08-29
  • Yifan Zhang

    Yifan Zhang - 2023-08-29

    Hi all,

    here is Yifan, first of all great thanks to all the development of such
    a magnificent work!

    I am currently working on a MPC-Control project which allows the
    controller to track a reference trajectory. For the purpose of tracking
    i have written some C functions to read and use the Trajectory data,
    besides i have also modified some original source file to to make this work.

    The Program runs in C (main.c file) pretty well, for the next step I
    would like to build a Simulink model in Matlab, for which it is
    necessary to install Grampc in matlab as said in the Manual. My question
    is, since I have changed some source and head file and also added some
    new one, can I still simply run the MAKE command in matlab? I've tried 
    it several times but it didn't work well, the error report is:

      * Error using mex
        /home/evan/Desktop/Desk_ubuntu/ADP/ADP_Repository/CMPC/GRAMPC_UAV_01/matlab/bin/grampc_init_Cmex.c:
        In function mexFunction:
        /home/evan/Desktop/Desk_ubuntu/ADP/ADP_Repository/CMPC/GRAMPC_UAV_01/matlab/bin/grampc_init_Cmex.c:40:2:
        error: too many arguments to function grampc_init
            40 |  grampc_init(&grampc, userparam);
               |  ^~~~~~~~~~~
        In file included from ../../include/grampc_alloc.h:16,
                          from ../../include/grampc.h:18,
                          from
        /home/evan/Desktop/Desk_ubuntu/ADP/ADP_Repository/CMPC/GRAMPC_UAV_01/matlab/bin/grampc_init_Cmex.c:17:
                          ../../include/grampc_init.h:369:6: note:
        declared here
           369 | void grampc_init(typeGRAMPC **grampc);
               |      ^~~~~~~~~~~
    
    
        Error in make (line 166)
                 eval(['mex -c ',CmexFiles{i},' -I',CHEADERPATH,'
        -I',MEXHEADERPATH,VERBOSE,DEBUG,TIMER]);
    

    Thanks a lot in advance.

    Best regards,

    Yifan Zhang

     
  • Andreas Völz

    Andreas Völz - 2023-08-29

    Dear Yifan Zhang,

    basically, you should still be able to use the Matlab/Simulink-interface of GRAMPC. However, depending on your modifications to the C-code of GRAMPC you also have to modify some parts of the mex-interface. From your error messages it appears that you have changed the interface of grampc_init, which then requires that you also change the function calls of grampc_init in all of the mex-files. If possible, I would suggest to keep the changes to the function definitions of GRAMPC as small as possible to minimize the necessary work for adapting the Matlab interface. From my experience, most custom usecases can be realized with some effort via the userparam field.

    Best regards,
    Andreas Völz

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.