错误:调用重载'abs(float&)'

时间:2015-11-19 14:51:03

标签: c++ mbed ambiguous-call

我正在使用FRDM K64F控制电机,我正在使用mbed的电机库。

编译时,它会在库附带的头文件中拾取此错误。

In member function 'void Motor::speed(float)':
/home/testing/testing/Motor.cpp:42:21: error: call of overloaded     'abs(float&)' is ambiguous
     _pwm = abs(speed);

错误包含在此文件中。

#include "testing/Motor.h"

#include "mbed-drivers/mbed.h"

Motor::Motor(PinName pwm, PinName fwd, PinName rev):
    _pwm(pwm), _fwd(fwd), _rev(rev) {

// Set initial condition of PWM
_pwm.period(0.001);
_pwm = 1;

// Initial condition of output enables
_fwd = 0;
_rev = 0;
}

void Motor::speed(float speed) {
_fwd = (speed > 0.0);
_rev = (speed < 0.0);
_pwm = abs(speed);
}

它调用motor.h,它在这里:

#ifndef MBED_MOTOR_H
#define MBED_MOTOR_H

#include "mbed-drivers/mbed.h"

class Motor {
public:


Motor(PinName pwm, PinName fwd, PinName rev);

/** Set the speed of the motor
 * 
 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
 */
void speed(float speed);

protected:
PwmOut _pwm;
DigitalOut _fwd;
DigitalOut _rev;

};

#endif

最后我从这里打电话给他们:

#include "mbed-drivers/mbed.h"
#include "testing/Motor.h"

Motor A(D8, D9, D10); // pwm, fwd, rev, can brake 

static void motor(void){
      for (float s= -1.0; s < 1.0 ; s += 0.1) {
        A.speed(s); 
    wait(0.02);
    }
}

void app_start(int, char**){
    minar::Scheduler::postCallback(motor).period(minar::milliseconds(500));
}

有什么想法吗?

0 个答案:

没有答案