Skip to content

Instantly share code, notes, and snippets.

@cagodoy
Created June 23, 2018 04:39
Show Gist options
  • Select an option

  • Save cagodoy/378d025c109cc36c01b5a36dde4a232a to your computer and use it in GitHub Desktop.

Select an option

Save cagodoy/378d025c109cc36c01b5a36dde4a232a to your computer and use it in GitHub Desktop.
// #include <PID_v1.h>
// include motor
//general status
const String IDLE_STATUS = "idle";
//irrigation status
const String IRRIGATION_STATUS = "irrigation";
const String IRRIGATION_ERROR_STATUS = "irrigation_error";
const String IRRIGATED_STATUS = "irrigated";
//calibration status
const String CALIBRATION_STATUS = "calibration";
const String CALIBRATION_ERROR_STATUS = "calibration_error";
const String CALIBRATED_STATUS = "calibrated";
//test status
const String TEST_STATUS = "test";
const String TEST_ERROR_STATUS = "test_error";
const String TESTED_STATUS = "tested";
// PID constants
// const float ki = 1;
// const float kp = 1;
// const float kd = 1;
class WaterPump {
private:
string id;
string status;
int pin;
bool onError; //inUse
AFMOTOR motor;
// PID myPID;
// double pid_input;
// double pid_output;
// double pid_setpoint;
public:
WaterPump (string id, int pin) {
this->id = id;
this->pin = pin;
this->pin = IDLE_STATUS;
this->onError = false;
this->motor(this->pin);
// this->myPID(&this->pid_input, &this->pid_output, &this->pid_setpoint, kp, ki, kd, DIRECT);
}
int calculateDelayTime (ml) {
//freq
//speed
//time
return //f(time, ml, freq, speed) =
}
void irrigation (float ml) {
// validate if exist an error
if (this->onError) {
Serial.println("la bomba esta con error ->", this->status);
return;
}
// validate if status equal to "irrigation"
if (this->status == IRRIGATION_STATUS) {
Serial.println("la bomba está regando ->", this->status);
return;
}
// validate if status equal to "calibration"
if (this->status == CALIBRATION_STATUS) {
Serial.println("la bomba se está calibrando ->", this->status);
return;
}
//change to irrigation status
Serial.println("water pump changed status: ", IRRIGATION_STATUS);
this->status = IRRIGATION_STATUS;
//calculate and get magic time number for use inside delay method
int delayTime = this->calculateDelayTime(ml)
//turn on this motor to start irrigation
Serial.println("la bomba se ha encendido");
this->motor(FORWARD);
//wait magic delay number
Serial.println("esperando X segundos", delayTime);
delay(delayTime);
//turn off water pump irrigation
Serial.println("la bomba se ha detenido");
this->motor(RELEASE);
//chage to irrigated status
Serial.println("water pump changed status: ", IRRIGATED_STATUS);
this->status = IRRIGATED_STATUS
}
void calibration (float ml) {}
void test (float ml, float time) {
// validate if water pump is in use
//change to test status
Serial.println("water pump changed status: ", TEST_STATUS);
this->status = TEST_STATUS;
irrigation (float ml)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment