I'm trying to use Arduino to control a robot base with 3 motors on it. I have a class to control each class individuality called SimpleMotor, and want a class to control the 3 SimpleMotors called Driver.
I'd like to be able to initialize 3 SimpleMotors, then initialize a Driver object with the motor objects. The following is my code and the error messages: Code: class SimpleMotor { public: int motorSpeed = 127; //value from 0-255 int hallPin; int enablePin; int in1Pin; int in2Pin;
SimpleMotor::SimpleMotor(int ePin, int d1Pin, int d2Pin) {
enablePin = ePin;
in1Pin = d1Pin;
in2Pin = d2Pin;
}
void SimpleMotor::Direction(bool dir) { //true is cw, false is ccw
if (dir) {
digitalWrite(in1Pin, HIGH);
digitalWrite(in2Pin, LOW);
}
else {
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, HIGH);
}
}
void SimpleMotor::WriteSpeed(int motorPower){
if(motorPower < 0) {Direction(0);}
else {Direction(1);}
analogWrite(enablePin, motorPower);
}
void SimpleMotor::Stop(){
analogWrite(enablePin, 0);
}
};
class Driver{
friend class SimpleMotor;
public:
SimpleMotor m1;
SimpleMotor m2;
SimpleMotor m3;
Driver::Driver(SimpleMotor motor1, SimpleMotor motor2, SimpleMotor motor3) {
m1 = motor1;
m2 = motor2;
m3 = motor3;
}
void Driver::Spin(int stickX){
if(stickX<0){
m1.Direction(0);
m2.Direction(0);
m3.Direction(0);
}
else{
m1.Direction(1);
m2.Direction(1);
m3.Direction(1);
}
m1.WriteSpeed((int) floor(stickX/4));
m2.WriteSpeed((int) floor(stickX/4));
m3.WriteSpeed((int) floor(stickX/4));
}
};
Errors:
HolonomicDriver:46:80: error: no matching function for call to 'SimpleMotor::SimpleMotor()'
Driver::Driver(SimpleMotor motor1, SimpleMotor motor2, SimpleMotor motor3) {
^
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:10:5: note: candidate: SimpleMotor::SimpleMotor(int, int, int)
SimpleMotor::SimpleMotor(int ePin, int d1Pin, int d2Pin) {
^~~~~~~~~~~
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:10:5: note: candidate expects 3 arguments, 0 provided
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate: constexpr SimpleMotor::SimpleMotor(const SimpleMotor&)
class SimpleMotor {
^~~~~~~~~~~
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate expects 1 argument, 0 provided
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate: constexpr SimpleMotor::SimpleMotor(SimpleMotor&&)
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate expects 1 argument, 0 provided
HolonomicDriver:46:80: error: no matching function for call to 'SimpleMotor::SimpleMotor()'
Driver::Driver(SimpleMotor motor1, SimpleMotor motor2, SimpleMotor motor3) {
^
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:10:5: note: candidate: SimpleMotor::SimpleMotor(int, int, int)
SimpleMotor::SimpleMotor(int ePin, int d1Pin, int d2Pin) {
^~~~~~~~~~~
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:10:5: note: candidate expects 3 arguments, 0 provided
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate: constexpr SimpleMotor::SimpleMotor(const SimpleMotor&)
class SimpleMotor {
^~~~~~~~~~~
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate expects 1 argument, 0 provided
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate: constexpr SimpleMotor::SimpleMotor(SimpleMotor&&)
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate expects 1 argument, 0 provided
HolonomicDriver:46:80: error: no matching function for call to 'SimpleMotor::SimpleMotor()'
Driver::Driver(SimpleMotor motor1, SimpleMotor motor2, SimpleMotor motor3) {
^
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:10:5: note: candidate: SimpleMotor::SimpleMotor(int, int, int)
SimpleMotor::SimpleMotor(int ePin, int d1Pin, int d2Pin) {
^~~~~~~~~~~
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:10:5: note: candidate expects 3 arguments, 0 provided
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate: constexpr SimpleMotor::SimpleMotor(const SimpleMotor&)
class SimpleMotor {
^~~~~~~~~~~
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate expects 1 argument, 0 provided
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate: constexpr SimpleMotor::SimpleMotor(SimpleMotor&&)
c:\Users\mmell\Documents\Arduino\HolonomicDriver\HolonomicDriver.ino:2:7: note: candidate expects 1 argument, 0 provided
exit status 1
Thanks!
friendhere if the methods of SimpleMotor are public.