This is my pid program for robot
got 5 sensors 2 pins each to drive motor from driver and 1 each for pwm
getting
error: a function-definition is not allowed here before '{' token
at compile
// ————————————————————————— Motors
int motor_left[] = {8, 9 };
int motor_right[] = {10, 11};
int motor_right0 = 10 ;
int motor_right1 = 11 ;
int left2 = 12;
int left1 = 13;
int center = 0;
int right1 = 1;
int right2 = 2;
int pwml = 3;
int pwmr = 4;
int Myint;
int Mpos;
long Diff;
long Difflast;
int rate;
int prop;
int Deriv;
int Intergral;
int Control;
int temp1;
int Lfast = 255;
int Rfast = 255;
int Tpos = 0;
int Highlimit = 255;
int Lowlimit = -255;
float Kp = 0;
float Kd = 0;
float Ki = 0;
float Interval = 0.01;
// ————————————————————————— Setup
void setup() {
// Setup motors
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left*, OUTPUT);*
pinMode(motor_right*, OUTPUT);
pinMode(left2, INPUT);
pinMode(left1, INPUT);
pinMode(center, INPUT);
pinMode(right1, INPUT);
pinMode(right2, INPUT);
_}_
void loop()
_{_
_ void drive();_
_ void decide();_
_ void cal();_
_ void apply();_
_}_
void drive()
{digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
*analogWrite (pwml ,Lfast); *
analogWrite (pwmr ,Rfast);
_}_
void decide()
_{_
_ if (left2 == LOW && left1 == HIGH && center == HIGH && right1 == HIGH && right2 == HIGH)_
_{_
_ Mpos = -40;_
_}_
if (left2 == LOW && left1 == LOW && center == HIGH && right1 == HIGH && right2 == HIGH)
_{_
_ Mpos = -30;_
_}if (left2 == HIGH && left1 == LOW && center == HIGH && right1 == HIGH && right2 == HIGH)_
_{_
_ Mpos = -20;_
_}if (left2 == HIGH && left1 == LOW && center == LOW && right1 == HIGH && right2 == HIGH)_
_{_
_ Mpos = -10;_
_}if (left2 == HIGH && left1 == HIGH && center == LOW && right1 == HIGH && right2 == HIGH)_
_{_
_ Mpos = 0;_
_ Integral = 0;_
_}if (left2 == HIGH && left1 == HIGH && center == LOW && right1 == LOW && right2 == HIGH)_
_{_
_ Mpos = 10;_
_}if (left2 == HIGH && left1 == HIGH && center == HIGH && right1 == LOW && right2 == HIGH)_
_{_
_ Mpos = 20;_
_}if (left2 == HIGH && left1 == HIGH && center == HIGH && right1 == LOW && right2 == LOW)_
_{_
_ Mpos = 30;_
_}if (left2 == HIGH && left1 == HIGH && center == HIGH && right1 == HIGH && right2 == LOW)_
_{_
_ Mpos = 40;_
_}if (left2 == HIGH && left1 == HIGH && center == HIGH && right1 == HIGH && right2 == HIGH)_
_{_
if (Mpos < 0)
_{Mpos = -30};_
else
_{Mpos = 30};_
_}_
_}_
void cal(){
_ Diff = Tpos - Mpos;_
Prop = Diff * Kp;
Integral = Integral + Diff;
Integral = Integral * Ki;
Integral = Integral * Interval;
If (Integral > Highlimit)
_{Integral = Highlimit};_
If (Integral < Lowlimit)
_{Integral = Lowlimit};_
Rate = Diff - Difflast;
Deriv = Rate * Kd;
Difflast = Diff;
Control = Prop + Deriv;
Control = Control + Integral;
If (Control > Highlimit)
_{Control = Highlimit};_
If (Control < Lowlimit)
_{Control = Lowlimit};_
_}_
void apply()
_{_
If (Control <= 0)
_ {Temp1 = Lfast + Control;_
_ Myint = Temp1;_
_ analogWrite (pwml,Myint);_
_ Rightmotor = Rfast;_
_ }_
_ If*_
* If (Control > 0)*
* {Temp1 = Rfast - Control;*
* Myint = Temp1;*
* analogWrite (pwmr,Myint);*
* Leftmotor = Lfast;*
* }*
* delay (10)*
}