#define ROLL 7
#define THROTTLE 3
#define MOTOR1 2
#define MOTOR2 4
#define MOTOR3 6
#define MOTOR4 8
#define TMAX 1700
#define TMIN 910
#define RMAX 1890
#define RMIN 1085
#define RCENTRE 1476
int throttle1,roll1;
float dt,setpoint,pro_var,pterm,Kp,Kd,dterm,error[2],input;
int gyro_iroll[4]={0,0,0,0},diff=0;
float roll_raw=0,gyro_froll[4];
unsigned long last=0,now=0;
int q,i,j;
float gyro_roll()
{
last=now;
now=micros();
diff=now-last;
roll_raw = (roll_raw + (((gyro_froll[3] + 2*gyro_froll[2] + 2*gyro_froll[1] + gyro_froll[0])*roll_diff)/6000000));
for(q=2;q>=0;q--)
gyro_froll[q+1]=gyro_froll[q];
gyro_iroll[0]=analogRead(0);
gyro_froll[0]=gyro_iroll[0]-361;
// Serial.println(val);
return roll_raw;
}
int roll_pid(roll1,roll_raw)
{
setpoint =roll1;
input =roll_raw;
dt=0;
Kp=1.25,Kd=-0.5;
error[0]=setpoint-input;
pterm=Kp*error[0];
dt=(millis()-dt)*1000;
dterm=Kd*(error[0]-error[1])/dt;
dt=dt/1000;
error[1]=error[0];
pro_var=pterm+dterm;
return pro_var;
}
void setup()
{
Serial.begin(4800);
for(q=0;q<=3;q++)
{
gyro_iroll[q]=analogRead(0);
gyro_froll[q]=gyro_iroll[q]-361;
}
pinMode(MOTOR1, OUTPUT);
pinMode(MOTOR2, OUTPUT);
pinMode(MOTOR3, OUTPUT);
pinMode(MOTOR4, OUTPUT);
pinMode(THROTTLE,INPUT);
pinMode(ROLL,INPUT);
pinMode(0,INPUT);
}
void loop()
{
int val1,val2,val3,val4;
throttle1=pulseIn(THROTTLE,HIGH);
roll1=pulseIn(ROLL,HIGH);
if((roll1<RMAX) && (roll1>RMIN))
{
if((roll1>RCENTRE-14) && (roll1<RCENTRE+14))
{
roll1=0;
}
else if((throttle1-TMIN)>(TMAX-throttle1))
{
roll1=map(roll1,RMIN,RMAX,-(TMAX-throttle1),(TMAX-throttle1));
}
else
{
roll1=map(roll1,RMIN,RMAX,-(throttle1-TMIN),(throttle1-TMIN));
}
}
do
{
gyro_roll_raw=gyro_roll();
roll_pd_value=roll_pid(roll1,gyro_roll_raw);
val1=throttle1;
val2=throttle1+roll_pd_value;
val3=throttle1;
val4=throttle1-roll_pd_value;
digitalWrite(MOTOR1,HIGH);
delayMicroseconds(val1);
digitalWrite(MOTOR1,LOW);
digitalWrite(MOTOR2,HIGH);
delayMicroseconds(val2);
digitalWrite(MOTOR2,LOW);
digitalWrite(MOTOR3,HIGH);
delayMicroseconds(val3);
digitalWrite(MOTOR3,LOW);
digitalWrite(MOTOR4,HIGH);
delayMicroseconds(val4);
digitalWrite(MOTOR4,LOW);
}while(roll_pd_value!=throttle)
}
I know there are many many other errors but this one is not justified.
I'm not even using the variable roll1 in that function..
When i compile it shows this error and highlights the 10th row.
I'm using arduino 17 if that counts...
PLZ Help Out ..
Thanks in advance