Menu

Examples for using the c++ interface

2021-03-15
2023-04-04
  • Gustav Vallinder

    Hello!

    Thank you for providing Grampc!

    Are there any resources for understanding how to use the c++ interface a bit better?
    I couldn't find anything mentioned in the manual.

    Best regards,
    Gustav

     
  • Andreas Völz

    Andreas Völz - 2021-03-16

    Hello Gustav,

    the usage of the C++ interface is mostly identical to the C interface. Instead of implementing all functions in a probfct_TEMPLATE.c-file, one derives from grampc::ProblemDescription, i.e.

    class TemplateProblemDescription : public grampc::ProblemDescription
    {
    public:
        virtual void ocp_dim(typeInt *Nx, typeInt *Nu, typeInt *Np, typeInt *Ng, typeInt *Nh, typeInt *NgT, typeInt *NhT) override
        {
            *Nx = 2;
            *Nu = 1;
            *Np = 0;
            *Ng = 0;
            *Nh = 0;
            *NgT = 0;
            *NhT = 0;
        }
    
        // ...
    };
    

    Of advantage is that you only have to override and implement the methods that are relevant to your problem. For example, if you don't use RODAS as integrator, you don't have to define and implement the functions related to the mass matrix.

    Solving the problem looks similar to

    TemplateProblemDescription problem;
    grampc::Grampc solver(&problem);
    solver.setopt_int("MaxGradIter", 2);
    solver.setparam_real("Thor", 1.5);
    solver.run();
    std::cout << solver.getSolution()->unext[0] << std::endl;
    

    If you need a complete example, I can convert one of the existing examples to the C++ notation. For a more complex usage, you could have a look at github.com/grampc-d/grampc-d, which is a framework for distributed MPC that is based on GRAMPC and uses the C++ interface.

    Regards,
    Andreas

     
  • Gustav Vallinder

    Hello again!

    Thank you for the response , it was helpful!

    I would be happy to see one of the existing examples in the C++ notation just to see how you intend it to be used. Hopefully it could be beneficial to anyone else visiting this discussion forum aswell.

    Once again thanks for the help,
    Gustav

     
  • Malte

    Malte - 2023-04-04

    Hello all!
    Thanks for the small example. Is there an existing C++ example by now?

    Best regards
    Malte

     

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.