I am new to arduino programming, specially with PID controllers. Can someone tell me the exact location to save PID_v1.h header file, since I am getting error
C:\Users\Lenovo\Downloads\Wheelchair_Encoder\Wheelchair_Encoder.ino:1:20: fatal error: PID_v1.h: No such file or directory
#include <PID_v1.h>
This is my code
#include <PID_v1.h>
#define SIGNAL_PIN 4
#define WAIT_NEXT_CMD 8000
#define WAIT_NEXT_BIT 21
#define MAX_CMD_IDX 72
#define LEFT_INPUT 2
#define RIGHT_INPUT 3
#define NUM_OF_INT_PER_ROTATE 71
#define TIMER_HERTZ 1
// initialise array as containing 72 elements
int frontL[72] = {0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1};
int stopCmd2[72] = {0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1};
int full_left[72] = {0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
int waitNextCmd = 1;
unsigned long previousMillis1;
unsigned long previousMillis2;
unsigned long previousMillis3;
unsigned int cmdIdx = 0;
unsigned int numCmd = 0;
unsigned int leftCount = 0;
unsigned int rightCount = 0;
int* currentCmd;
double Input, Output;
double errSum, lastErr;
double kp = 0.015, ki = 0, kd = 0;
int SampleTime = 1000; // 1 seconds
unsigned long currentMillis = micros();
int Setpoint = 70; // Target point for the PID Controller
int IdleTime; // Number of times the stop command will be repeated, initial value assigned
int OnTime; // Number of times the front command will be repeated, initial value assigned
int period = 50;
float dutyRatio; // OnTime / Period
double leftRPM = 0;
double wheelCircumference = 27.81;
double leftVelocity = 0;
double rightVelocity = 0;
int left=0;
int right=0;
void setup()
{
pinMode(SIGNAL_PIN, OUTPUT); // sets the digital pin as output
digitalWrite(SIGNAL_PIN, HIGH); // use the internal pullup resistor
pinMode(LEFT_INPUT, INPUT);
pinMode(RIGHT_INPUT, INPUT);
waitNextCmd = 1;
cmdIdx = 0;
currentCmd = stopCmd2;
previousMillis1 = micros();
previousMillis2 = micros();
leftCount = 0;
rightCount = 0;
//Digital Pin 2 as a left interrupt
attachInterrupt(digitalPinToInterrupt(LEFT_INPUT), leftEncoder, FALLING);
// Digital Pin 3 as a right interrupt
attachInterrupt(digitalPinToInterrupt(RIGHT_INPUT), rightEncoder, FALLING);
Serial.begin(115200);
Serial.print("Left Count");
Serial.print("\t");
Serial.print("Left Speed");
Serial.print("\t");
Serial.print("Right Count");
Serial.print("\t");
Serial.print("Right Velocity");
Serial.print("\t");
Serial.print("OnTime");
Serial.print("\t");
Serial.print("IdleTime");
Serial.print("\n");
}
void loop() {
unsigned long currentMillis = micros(); // check to see if it's time to change the state
// unsigned int rightRPM = 0;
if (waitNextCmd == 1)
{
if (currentMillis - previousMillis1 > WAIT_NEXT_CMD)
{
pinMode(SIGNAL_PIN, OUTPUT);
// state change
if (currentCmd == stopCmd2)
{
if (numCmd > IdleTime)
{
currentCmd = frontL;
numCmd = 0;
} // if (numCmd > IdleTime)
else
{
numCmd++;
}
} // if (currentCmd == stopCmd2)
else if (currentCmd == frontL)
{
if (numCmd > OnTime)
{
currentCmd = stopCmd2;
numCmd = 0;
} // if (numCmd > OnTime)
else
{
numCmd++;
}
} // else if (currentCmd == frontL)
// end state change
digitalWrite(SIGNAL_PIN, currentCmd[cmdIdx++]);
waitNextCmd = 0;
previousMillis1 = currentMillis;
} // if (currentMillis - previousMillis1 > WAIT_NEXT_CMD)
} // if (waitNextCmd == 1)
else
{
if (currentMillis - previousMillis1 > WAIT_NEXT_BIT)
{
if (cmdIdx == MAX_CMD_IDX)
{
pinMode(SIGNAL_PIN, INPUT_PULLUP);
cmdIdx = 0;
waitNextCmd = 1;
if (currentMillis - previousMillis2 > 1000000 )
{
leftRPM = (double)leftCount / NUM_OF_INT_PER_ROTATE * TIMER_HERTZ;
leftVelocity = ((double)wheelCircumference / (double)leftCount) / TIMER_HERTZ;
// rightRPM = rightCount / NUM_OF_INT_PER_ROTATE * TIMER_HERTZ;
rightVelocity = ((double)wheelCircumference / (double)rightCount) / TIMER_HERTZ;
//float dutyRatio = Compute();
dutyRatio = 0.85;
OnTime = (int)(period * dutyRatio);
IdleTime = period - OnTime;
Serial.print("\t");
Serial.print(leftCount);
Serial.print("\t");
Serial.print("\t");
Serial.print(leftVelocity);
Serial.print("\t");
Serial.print("\t");
Serial.print(rightCount);
Serial.print("\t");
Serial.print("\t");
Serial.print(rightVelocity);
Serial.print("\t");
Serial.print(OnTime);
Serial.print("\t");
Serial.print(IdleTime);
Serial.print("\n");
leftCount = 0;
rightCount = 0;
previousMillis2 = currentMillis;
} // if (currentMillis - previousMillis2 > 1000000 )
} // if (cmdIdx == MAX_CMD_IDX)
else
{
digitalWrite(SIGNAL_PIN, currentCmd[cmdIdx++]);
}
previousMillis1 = currentMillis;
} // if (currentMillis - previousMillis1 > WAIT_NEXT_BIT)
}
} // void loop()
void leftEncoder()
{
leftCount++;
}
void rightEncoder()
{
rightCount++;
}