Using boost::numeric::odeint inside the class

后端 未结 1 921
执笔经年
执笔经年 2021-01-25 13:58

For a simulation, I\'m using boost::numeric::odeint but I\'m having a problem. I\'m using the integrate function inside a method of one of my classes and I\'m having the error o

相关标签:
1条回答
  • 2021-01-25 14:33

    odeint needs an operator()( const state_type &x , state_type &dxdt , double dt )

    In your case, MotionGenerator does not have this operator, but you can bind the method motionScheme

    #include <functional>
    namespace pl = std::placeholders;
    
    // ...
    
    // not tested
    void MotionGeneration::execute()
    {
        state_type init_conf = { 0, -1.5708, 0, 0, 0, -1.5708, 0, -1.5708, 0, 0.5};
        boost::numeric::odeint::integrate(
            std::bind(&MotionGenerator::motionScheme, *this , pl::_1 , pl::_2 , pl::_3 ) , init_conf, 0.0, 1.0, 0.05, plot);
    }
    

    ```

    But,it would be easy to rename your method motionScheme to operator(), and simply pass *this to integrate.

    Edit: You can also use std::ref to avoid copies of your instance of MotionGenerator:

    void MotionGeneration::execute()
    {
        state_type init_conf = { 0, -1.5708, 0, 0, 0, -1.5708, 0, -1.5708, 0, 0.5};
        boost::numeric::odeint::integrate(
            std::bind(&MotionGenerator::motionScheme, std::ref(*this) , pl::_1 , pl::_2 , pl::_3 ) , init_conf, 0.0, 1.0, 0.05, plot);
    }
    
    0 讨论(0)
提交回复
热议问题