Arduino MicroMaestro Error: no matching function

Hi,

I have been able to run some example code and make it work with a servo but 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()’.

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);
 }

The error I get in Arduino IDE 2.3.2

 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()'

It turns out it was a cpp error. Because I was declaring a MicroMaestro obj in the header file but the arduino library doesn’t have a default constructor. I was able to instead declare it at the beginning of the class constructor.

Like this:

servo_obj::servo_obj()  :  flap_driver(maestro_serial) {

  // Set the serial baud rate.
  maestro_serial.begin(9600);

}

I am glad you were able to find the problem and get it working; thank you for letting us know.

Brandon