Userhook functions and parameters issues

Hi all,

I’ve enabled the USER_PARAMS feature and added some extra parameters for an algorithm I’m working on. However, the default parameter values are not being applied and the params are always initialized to zero.
For instance, AP_GROUPINFO("_WV_CUTOFF", 14, UserParameters, wv_cutoff, 0.06f). The last argument of this function does nothing. I don’t know how to fix this myself.

I’ve also enabled the USERHOOK_AUXSWITCH. But there were compilation errors. I traced down the problem and found that channel_flag typedef changed. I fixed it by editing the RC_Channel.cpp to look like this:

#ifdef USERHOOK_AUXSWITCH
        case AUX_FUNC::USER_FUNC1:
            if (ch_flag == AuxSwitchPos::HIGH) {
                copter.userhook_auxSwitch1();
            }
            break;
        case AUX_FUNC::USER_FUNC2:
            if (ch_flag == AuxSwitchPos::HIGH) {
                copter.userhook_auxSwitch2();
            }
            break;
        case AUX_FUNC::USER_FUNC3:
            if (ch_flag == AuxSwitchPos::HIGH) {
                copter.userhook_auxSwitch3();
            }
            break;
#endif

Did you define wv_cutoff variable in UserParameters.h (within the UserParameters class) ?
Like: AP_Float wv_cutoff;

Also are your indexes are right? (“14” in your example). They should start from zero.

Will need to have a look at your code changes to advise. Scripting is a great alternative to user hooks.

Thanks for your reply!

Yes. I followed the examples given in the UserParameters.h and .cpp files. Just to be clear, I enabled User_Params in config.h. Then, I declared the variables (AP_Float wv_cutoff) and created the accessor (AP_Float get_wv_cutoff() const{return wv_cutoff; }) in UserParameters.cpp. The indexes are right, I have previously declared 14 other parameters.

When I run the SITL and connect it to the Mission Planner, I can see my parameters but there are all set to zero. The default values are not being applied.

The changes I made are exaclty as in the examples inside the UserParameters.cpp and .h.