rjhogan / Adept-2

Combined array and automatic differentiation library in C++
http://www.met.reading.ac.uk/clouds/adept/
Apache License 2.0
163 stars 29 forks source link

Seg Fault while initialzing a struct of adoubles #28

Closed Huzaifg closed 1 year ago

Huzaifg commented 1 year ago

I keep getting a segmentation fault when I try to initialize a struct of adoubles. See below the struct

struct VehParam{

    // Contructor for the 4 DOF parameters
    VehParam()
        : _l(0.5), _c1(1e-4), _c0(0.02), _R(0.08451952624), _I(1e-3), _gamma(0.334), _tau0(0.09), _omega0(161.185) , _step(1e-3) {}

    VehParam(adouble l, adouble c1, adouble c0, adouble R, adouble I, adouble gamma, adouble tau0, adouble omega0, double step)
    : _l(l), _c1(c1), _c0(c0), _R(R), _I(I), _gamma(gamma), _tau0(tau0), _omega0(omega0), _step(step) {}

    adouble _l; // length of car
    adouble _c1; // Motor resistance that multiplies linearly
    adouble _c0; // Motor resistance that is constant
    adouble _R;  // Radius of wheel
    adouble _I; // Moment of Inertia of wheel
    adouble _gamma; // Gear Ratio
    adouble _tau0; // Motor torque at 0 RPM
    adouble _omega0; // RPM at which motor toruqe goes to 0
    double _step; // Time step used in the integration
};

I initialize using VehParam veh1_param This does not happen when I only use doubles.

rjhogan commented 1 year ago

An "adouble" can't be initialised before a Stack object is created, because when created an adouble object registers itself on the Stack - can I assume that you didn't create a Stack? See section 2.3.1 of the Adept-2 user guide.

Huzaifg commented 1 year ago

Works now! Thanks!!