I am controlling a motor using the FRDM K64F, I am using a motor library from mbed.
When compiling it is picking up this error in the header files that come with the library.
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);
The error is contained in this file.
#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);
}
It calls the motor.h which is here:
#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
And finally I call them both from here:
#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));
}
Any ideas?