0

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?

this
  • 5,229
  • 1
  • 22
  • 51
user3473406
  • 115
  • 1
  • 10
  • Did you compile with C++11 enabled? – NathanOliver Nov 19 '15 at 15:01
  • Who provides this abs() function? Typically it is in , but you don't include it. What is its definition (with all overloads)? – Vlad Feinstein Nov 19 '15 at 15:07
  • @VladFeinstein the problem is likely that there are different definitions of `abs` coming from different header files, and it might be tough to track down. – Mark Ransom Nov 19 '15 at 16:40
  • @Mark Ransom -That is exactly my point! I suspect there are overloads for `float` and `float&` (as noted in the error). I wonder WHY abs() would want to modify its parameter? Or else - WHY it want a reference? – Vlad Feinstein Nov 19 '15 at 17:17
  • I believe math.h is included within the I think I will have to track deeper into the mbed header files. – user3473406 Nov 19 '15 at 17:23

0 Answers0