I’m trying to make a position control of dc motor using pid controller .Here im using a pot in the feedback .
// PID motor position control.
#include <PID_v1.h>
#define enb 5
#define M1 7 // PWM outputs to L298N H-Bridge motor driver module
#define M2 6
int DesiredValue;
int CurrentValue;
int pot;
//int Direction;
double kp = 5 , ki = 1 , kd = 0.01; // modify for optimal performance
double input = 0, output = 0, setpoint = 0;
PID myPID(&input, &output, &setpoint, kp, ki, kd, DIRECT);
void setup() {
pinMode(enb, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(M1, OUTPUT);
pinMode(pot,INPUT);
myPID.SetMode(AUTOMATIC);
myPID.SetSampleTime(1);
myPID.SetOutputLimits(-255, 255);
Serial.begin (9600);
}
void loop() {
setpoint =600;
DesiredValue=setpoint;
input =analogRead(A0);
CurrentValue= input;
// Serial.println(encoderPos);
myPID.Compute(); // calculate new output
Direction(output); // drive L298N H-Bridge module
}
void Direction(int DesiredValue,int CurrentValue)
{ // to H-Bridge board
if (DesiredValue>CurrentValue)
{
digitalWrite(M1, LOW);
digitalWrite(M2, HIGH);
}
if (DesiredValue< CurrentValue) //right
{
digitalWrite(M1,HIGH);
digitalWrite(M2, LOW);
}
}
error message:
too few arguments to function ‘void Direction(int, int)’