I've been scratching my head at this for a few days now, I'm trying to make a class for a solar tracking program to make the main file neater and smaller because I plan on including several different things for the controller to do like WIFI, reading a temp sensor, etc. I'm using an esp32 for this project because of more processing power, WIFI, psram, and FreeRTOS. I've watched and read a lot of arduino/c++ tutorials trying to figure out where I went wrong but I cant seem to get this error to go away.
I'm basically trying to get maximum and minimum sensor values then averaging those values in 3 separate methods, each method has 4 integers they need to return to the averaging method for the 4 corresponding LDR sensors. From there the values from the averaging method need to be accessed by another method that will run the main tracking program and control outputs.
Could anybody help me out? Maybe walk me through where and how I went wrong.
Here is the tracking.h file
#ifndef tracking_h
#define tracking_h
#include <Arduino.h>
class tracking {
public:
// Sensor Pins //
#define TopLeft 32
#define TopRight 33
#define BottomLeft 34
#define BottomRight 35
// X Motor Pins //
#define LPWM_X 16 // LPWM for AXIS X connect to pin 5 on arduino
#define RPWM_X 17 // RPWM cfor AXIS X onnect to pin 6 on arduino
#define LEN_X 18 // L_EN for AXIS X connect to pin 9 on arduino
#define REN_X 19 // R_EN for AXIS X connect to pin 10 on arduino
// Y Motor Pins //
#define LPWM_Y 25 // LPWM for AXIS Y connect to pin 5 on arduino
#define LEN_Y 26 // L_EN for AXIS Y connect to pin 9 on arduino
#define RPWM_Y 27 // RPWM for AXIS Y connect to pin 6 on arduino
#define REN_Y 12 // R_EN for AXIS Y connect to pin 10 on arduino
int TL_SV; // top left sensor value
int TL_Min; // top left minimum sensor value
int TL_Max; // top left maximum sensor value
int TR_SV; // top right sensor value
int TR_Min; // top right minimum sensor value
int TR_Max; // top right maximum sensor value
int BL_SV; // bottom left sensor value
int BL_Min; // bottom left minimum sensor value
int BL_Max; // bottom right maximum sensor value
int BR_SV; // bottom right sensor value
int BR_Min; // bottom right minimum sensor value
int BR_Max; // bottom right maximum sensor value
int TOP;
int BOTTOM;
int LEFT;
int RIGHT;
tracking() { Serial.println("DBTECH-SOLAR-TRACKING-V1.0"); };
int sensor_max(int TL_Max, int TR_Max, int BL_Max, int BR_Max); // sensor maximum calibration
int sensor_min(int TL_Min, int TR_Min, int BL_Min, int BR_Min); // sensor minimum calibration
int average(int TOP, int BOTTOM, int LEFT, int RIGHT); // sensor averaging
void tracking_auto();
//~tracking();
};
#endif
Here is the tracking.cpp file
#include "tracking.h"
#include <Arduino.h>
int tracking::sensor_max(int TL_Max, int TR_Max, int BL_Max, int BR_Max)
{
TL_SV = analogRead(TopLeft);
TR_SV = analogRead(TopRight);
BL_SV = analogRead(BottomLeft);
BR_SV = analogRead(BottomRight);
// record the maximum sensor value
if (TL_SV > TL_Max) {
TL_Max = TL_SV;
}
if (TR_SV > TR_Max) {
TR_Max = TR_SV;
}
if (BL_SV > BL_Max) {
BL_Max = BL_SV;
}
if (BR_SV > BR_Max) {
BR_Max = BR_SV;
}
return TL_Max;
return TR_Max;
return BL_Max;
return BR_Max;
};
int tracking::sensor_min(int TL_Min, int TR_Min, int BL_Min, int BR_Min)
{
TL_SV = analogRead(TopLeft);
TR_SV = analogRead(TopRight);
BL_SV = analogRead(BottomLeft);
BR_SV = analogRead(BottomRight);
// record the minimum sensor value
if (TL_SV > TL_Min) {
TL_Min = TL_SV;
}
if (TR_SV > TR_Max) {
TR_Min = TR_SV;
}
if (BL_SV > BL_Min) {
BL_Min = BL_SV;
}
if (BR_SV > BR_Min) {
BR_Min = BR_SV;
}
return TL_Max;
return TR_Max;
return BL_Max;
return BR_Max;
};
int tracking::average(int TOP, int BOTTOM, int LEFT, int RIGHT)
{
// read the sensor:
TL_SV = analogRead(TopLeft);
TR_SV = analogRead(TopRight);
BL_SV = analogRead(BottomLeft);
BR_SV = analogRead(BottomRight);
// in case the sensor value is outside the range seen during calibration
TL_SV = constrain(TL_SV, TL_Min, TL_Max);
TR_SV = constrain(TR_SV, TR_Min, TR_Max);
BL_SV = constrain(BL_SV, BL_Min, BL_Max);
BR_SV = constrain(BR_SV, BR_Min, BR_Max);
// apply the calibration to the sensor reading
TL_SV = map(TL_SV, TL_Min, TL_Max, 0, 255);
TR_SV = map(TR_SV, TR_Min, TR_Max, 0, 255);
BL_SV = map(BL_SV, BL_Min, BL_Max, 0, 255);
BR_SV = map(BR_SV, BR_Min, BR_Max, 0, 255);
// read the sensor:
TL_SV = analogRead(TopLeft);
TR_SV = analogRead(TopRight);
TOP = (TL_SV + TR_SV) / 2;
BL_SV = analogRead(BottomLeft);
BR_SV = analogRead(BottomRight);
BOTTOM = (BL_SV + BR_SV) / 2;
TL_SV = analogRead(TopLeft);
BL_SV = analogRead(BottomLeft);
LEFT = (TL_SV + BL_SV) / 2;
TR_SV = analogRead(TopRight);
BR_SV = analogRead(BottomRight);
RIGHT = (TR_SV + BR_SV) / 2;
return TOP;
return BOTTOM;
return LEFT;
return RIGHT;
delay(1000);
};
void tracking::tracking_auto()
{
// X Axis Motor Setup //
pinMode(LPWM_X, OUTPUT);
pinMode(RPWM_X, OUTPUT);
pinMode(LEN_X, OUTPUT);
pinMode(REN_X, OUTPUT);
digitalWrite(LEN_X, HIGH);
digitalWrite(REN_X, HIGH);
// Y Axis Motor Setup //
pinMode(LPWM_Y, OUTPUT);
pinMode(RPWM_Y, OUTPUT);
pinMode(LEN_Y, OUTPUT);
pinMode(REN_Y, OUTPUT);
digitalWrite(LEN_Y, HIGH);
digitalWrite(REN_Y, HIGH);
// Makes Sure Motors Are Off //
digitalWrite(LPWM_X, LOW);
digitalWrite(RPWM_X, LOW);
digitalWrite(LPWM_Y, LOW);
digitalWrite(RPWM_Y, LOW);
if (TOP < BOTTOM) {
digitalWrite(LPWM_X, LOW);
digitalWrite(RPWM_X, HIGH);
delay(500);
digitalWrite(RPWM_X, LOW);
} else if (BOTTOM < TOP) {
digitalWrite(RPWM_X, LOW);
digitalWrite(LPWM_X, HIGH);
delay(500);
digitalWrite(LPWM_X, LOW);
}
if (LEFT > RIGHT) {
digitalWrite(LPWM_Y, LOW);
digitalWrite(RPWM_Y, HIGH);
delay(500);
digitalWrite(RPWM_Y, LOW);
} else if (RIGHT > LEFT) {
digitalWrite(RPWM_Y, LOW);
digitalWrite(LPWM_Y, HIGH);
delay(500);
digitalWrite(LPWM_Y, LOW);
}
};
The main INO file
// Include Libraries //
#include "tracking.h"
#include <Arduino.h>
#include <DHT.h>
#include <MPU6050_light.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <driver/adc.h>
#include <time.h>
// WiFi Connection //
int threshold = 200; // measurement sensitivity
tracking object;
int TL_SV = 0; // top left sensor value
int TL_Min = 0; // top left minimum sensor value
int TL_Max = 4000; // top left maximum sensor value
int TR_SV = 0; // top right sensor value
int TR_Min = 0; // top right minimum sensor value
int TR_Max = 4000; // top right maximum sensor value
int BL_SV = 0; // bottom left sensor value
int BL_Min = 0; // bottom left minimum sensor value
int BL_Max = 4000; // bottom right maximum sensor value
int BR_SV = 0; // bottom right sensor value
int BR_Min = 0; // bottom right minimum sensor value
int BR_Max = 4000; // bottom right maximum sensor value
//// -Setup- ////
void setup()
{
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
tracking();
Serial.println("CALIBRATING SENSOR MAX, MAKE SURE SENSORS IN DIRECT SUNLIGHT");
object.sensor_max();
Serial.println("PLEASE COVER SENSORS COMPLETELY");
delay(10000);
Serial.println("CALIBRATING SENSOR MIN");
};
void loop()
{
// sensors.average();
Serial.println("SENSOR VALUES");
delay(2000);
};
And finally the error message
c:\Users\mattm\OneDrive\Coding\Solar Tracker\arduino_firmware_v1.0\arduino_firmware_v1.0.ino: In function 'void setup()':
arduino_firmware_v1.0:66:23: error: no matching function for call to 'tracking::sensor_max()'
object.sensor_max();
^
In file included from c:\Users\mattm\OneDrive\Coding\Solar Tracker\arduino_firmware_v1.0\arduino_firmware_v1.0.ino:5:0:
c:\Users\mattm\OneDrive\Coding\Solar Tracker\arduino_firmware_v1.0\tracking.h:50:9: note: candidate: int tracking::sensor_max(int)
int sensor_max(int TL_Max); // sensor maximum calibration
^
c:\Users\mattm\OneDrive\Coding\Solar Tracker\arduino_firmware_v1.0\tracking.h:50:9: note: candidate expects 1 argument, 0 provided