Coding: trying to define a variable using functions from different libraries (ERROR: cannot call member function)

We are trying to establish a variable (perc_piezo) in the AP_MotorsMatrix code while calling code from the RC_Channel code but we can’t figure out how to write call the RC_Channel while in MotorsMatirx. (output_piezo) is the function we tried to create to use it. Let us know if you have any questions.

  • tried adding #include
  • tried using float vs void

AP_MotorsMatrix.cpp (try #1)/ also same code written in RC_Channel.cpp

float RC_Channel::output_piezo(RC_Channel::aux_switch_pos_t &ret) const 
    // calculate position of flight mode switch
    const uint16_t inp = get_radio_in();
    if (inp > AUX_PWM_TRIGGER_LOW) { 
        perc_piezo= 0.0f;
        return 0.0f;                            
    } else if (inp < AUX_PWM_TRIGGER_HIGH) {
        perc_piezo= 1.0;
        return 1.0;
    } else {
        perc_piezo= 0.5;
        return 0.5;

AP_MotorMatrix.cpp (try #2)

float RC_Channel::output_piezo(RC_Channel::aux_switch_pos_t &ret) const 
    const uint16_t inp = RC_Channel::get_radio_in();

float RC_Channel::testfun() const{
    return 1.0f;
float perc_piezo=0.0f;


// pwm value above which the option will be invoked:
    static const uint16_t AUX_PWM_TRIGGER_HIGH = 1800;
// pwm value below which the option will be disabled:
    static const uint16_t AUX_PWM_TRIGGER_LOW = 1200;  

float output_piezo(aux_switch_pos_t &perc_piezo) const; 

Expected it to compile so we could change the values for perc_piezo between 0, 0.5, and 1. It didn’t compile because:

error: cannot call member function ‘int16_t RC_Channel::get_radio_in() const’ without object
const uint16_t inp = RC_Channel::get_radio_in();

what are you trying to do exactly? From this code it seems like you want to change a internal varable based on a rc input?

see this example