Pololu MicroMaestro no matching function error

Hi,

I am using the Pololu Arduino Library for their servo controller and I have been able to run some of the given example code and make it work with a servo.

Now I am trying to include this code into a larger piece so I would like to put it in an object for working with the MicroMaestro. I have a header file and an .ino file for this object but when I try to compile these files I get an no matching function for call to ‘MicroMaestro::MicroMaestro()’. Below is my code and the error.

servo_obj.h

#ifndef servo_obj_h
#define servo_obj_h

#include <PololuMaestro.h>
#include <Arduino.h>

// servo class
class servo_obj {
public:
servo_obj();
void set_target(int target, unsigned long interval);
bool is_servo_moving();
private:
MicroMaestro flap_driver;
unsigned long period;
unsigned long time_now;
};

#endif

servo_obj.ino

/*
Before using this example, you should go to the Serial Settings
tab in the Maestro Control Center and apply these settings:

Serial mode: UART, fixed baud rate
Baud rate: 9600
CRC disabled
Be sure to click “Apply Settings” after making any changes.
*/
#include “servo_obj.h”
#include <PololuMaestro.h>

/* On boards with a hardware serial port available for use, use
that port to communicate with the Maestro. For other boards,
create a SoftwareSerial object using pin 2 to receive (RX) and
pin 3 to transmit (TX). */
#ifdef SERIAL_PORT_HARDWARE_OPEN
#define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
#include <SoftwareSerial.h>
SoftwareSerial maestroSerial(2, 3);
#endif

/* Next, create a Maestro object using the serial port.

Uncomment one of MicroMaestro or MiniMaestro below depending
on which one you have. */
MicroMaestro maestro(maestroSerial);
//MiniMaestro maestro(maestroSerial);

servo_obj::servo_obj()
{
// Set the serial baud rate.
maestroSerial.begin(9600);
}

void servo_obj::set_target(int target, unsigned long interval)
{
/* setTarget takes the channel number you want to control, and
the target position in units of 1/4 microseconds. A typical
RC hobby servo responds to pulses between 1 ms (4000) and 2
ms (8000). */

// Set the target of channel 0 to 1500 us, and wait 2 seconds.
maestro.setTarget(0, 6000);
delay(2000);

// Set the target of channel 0 to 1750 us, and wait 2 seconds.
maestro.setTarget(0, 7000);
delay(2000);

// Set the target of channel 0 to 1250 us, and wait 2 seconds.
maestro.setTarget(0, 5000);
delay(2000);
}

This is the exact error I am getting

C:\Users\HP\Documents\all_sensors_readings\servo_obj.ino: In constructor ‘servo_obj::servo_obj()’:
C:\Users\HP\Documents\all_sensors_readings\servo_obj.ino:32:22: error: no matching function for call to ‘MicroMaestro::MicroMaestro()’
servo_obj::servo_obj()
^
In file included from C:\Users\HP\Documents\all_sensors_readings\servo_obj.h:4:0,
from C:\Users\HP\Documents\all_sensors_readings\all_sensors_readings.ino:14:
C:\Users\HP\Documents\Arduino\libraries\PololuMaestro/PololuMaestro.h:301:5: note: candidate: MicroMaestro::MicroMaestro(Stream&, uint8_t, uint8_t, bool)
MicroMaestro(Stream &stream,
^~~~~~~~~~~~
C:\Users\HP\Documents\Arduino\libraries\PololuMaestro/PololuMaestro.h:301:5: note: candidate expects 4 arguments, 0 provided
C:\Users\HP\Documents\Arduino\libraries\PololuMaestro/PololuMaestro.h:280:7: note: candidate: constexpr MicroMaestro::MicroMaestro(const MicroMaestro&)
class MicroMaestro : public Maestro
^~~~~~~~~~~~
C:\Users\HP\Documents\Arduino\libraries\PololuMaestro/PololuMaestro.h:280:7: note: candidate expects 1 argument, 0 provided
C:\Users\HP\Documents\Arduino\libraries\PololuMaestro/PololuMaestro.h:280:7: note: candidate: constexpr MicroMaestro::MicroMaestro(MicroMaestro&&)
C:\Users\HP\Documents\Arduino\libraries\PololuMaestro/PololuMaestro.h:280:7: note: candidate expects 1 argument, 0 provided

exit status 1

Compilation error: no matching function for call to ‘MicroMaestro::MicroMaestro()’

The MicroMaestro class doesn't have a constructor that takes no arguments. So this declaration can't work. You'll have to rethink how you're doing things.

And the way you're calling begin methods in constructors, I think you're going to run into the static initialization order fiasco.

Ok thanks for pointing that out. I was able to get around that by constructing the MicroMaestro obj right before the constructor for the class.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.