Exit status 1 Error Compiling

I am getting an error message when compiling.

This is everything that showed up in red in the debug window for 5 Sensor PID based Line follower

sketch\pid.ino.cpp.o: In function `loop’:

C:\Users\lenovo\Documents\Arduino\pid/pid.ino:39: undefined reference to `redline()’

C:\Users\lenovo\Documents\Arduino\pid/pid.ino:47: undefined reference to `select_turns(unsigned char, unsigned char, unsigned char)’

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.

the file is attached in case it can be like help. Thank you for the help.

pid.ino (3.32 KB)

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

Hi,
Your code:

int l1=2;
int l2=3;
int r1=4;
int r2=5;
int enl=A4;
int enr=A5;
int a[4];
int last_proportional=0;
int integral=0;

char select_turns(unsigned char found_left,unsigned char found_right,unsigned char found_st);
int mod(int v);
int set_motors(int a,int b);
void turn (char dir);
void PID();
int right=0;
int left=0;
int redline();
void setup()
{
pinMode(l1,OUTPUT);
pinMode(l2,OUTPUT);
pinMode(r1,OUTPUT);
pinMode(r2,OUTPUT);
pinMode(enl,OUTPUT);
pinMode(enr,OUTPUT);

Serial.begin(9600);
}

void loop()
{
PID();
set_motors(200,200);
delay(20);
unsigned char found_left=0;
unsigned char found_right=0;
unsigned char found_st=0;
redline();
if(a[0]==LOW)
found_left=1;
if(a[4]==LOW)
found_right=1;
if(a[2]==LOW)
found_st=1;
unsigned char dir;
dir=select_turns(found_left,found_right,found_st);
turn(dir);
}

 int set_motors(int l,int r)
{
Serial.println(r);
Serial.println(l);

if(l>0&&r>0)
{
analogWrite(enl,mod(l));
analogWrite(enr,mod(r));
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
}
else if(l<0&&r>0)
{
analogWrite(enl,mod(l));
analogWrite(enr,mod(r));
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
digitalWrite(r1,LOW);
 digitalWrite(r2,HIGH);
}
else if(l>0&&r<0)
{analogWrite(enl,mod(l));
analogWrite(enr,mod(r));
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
}
else if(l==0&&r==0)
{
analogWrite(enl,mod(l));
analogWrite(enr,mod(r));
digitalWrite(l1,HIGH);
digitalWrite(l2,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
}
}

  int readline()
 {
   for(int i =0;i<5;i++)
   {
    a[i]=digitalRead(3+i);
    }
    int v;
    v=(4000*a[0]+3000*a[1]+2000*a[2]+1000*a[3]+0*a[4])/(a[0]+a[1]+a[2]+a[3]+a[4]);
    Serial.println(a[4]);
    return v;
  }
  
  int stop()
  {
    analogWrite(enl,255);
    analogWrite(enr,255);
    digitalWrite(l1,HIGH);
    digitalWrite(l2,HIGH);
    digitalWrite(r1,HIGH);
    digitalWrite(r2,HIGH);
    }

  void turn(char dir)
{
  switch(dir)
    {
      case'L':
      set_motors(-200,200);
      delay(350);
      break;
      case 'R':
      set_motors(200,-200);
      delay(350);
      break;
      case'B':
      set_motors(200,-200);
      delay(650);
      break;
      case 'S':
      break;
      }
 }
 
    void PID()
{
 int i;
 int power_difference=0;
 float kp,ki,kd;
 unsigned int position;
 int derivative,proportional;
  while(1)
  {
    position=readline();
    Serial.println(position);
  proportional=((int)position-3500);
  derivative=proportional-last_proportional;
  integral=integral+proportional;
  last_proportional=proportional;
  kp=0.09;
  ki=0.0001;
  kd=1.0;
  power_difference=proportional*kp+integral*ki+derivative*kd;
  const int max=250;  
  if(power_difference >max)
  power_difference=max;
  if(power_difference<-max)
  power_difference=(-1*max);
  if(power_difference<0)
  {
    set_motors(max+power_difference,max);
    }
  else{
    set_motors(max,max-power_difference);
    }
  readline();
  if(a[0]==HIGH&&a[1]==HIGH&&a[2]==HIGH&&a[3]==HIGH&&a[4]==HIGH)
    return;
  else if(a[0]==LOW||a[4]==LOW)
  return;
  }
}


char select_turn(unsigned char found_left,unsigned char found_right,unsigned char found_st)
  {
     if(found_left==1)
  return 'L';
    else if(found_st==1)
  return 'S';
    else if(found_right==1)
  return 'R';
    else 
  return 'B';
    }
 
 int mod(int v)
{
 if(v<0)
 return -1*v;
 else if(v>0)
 return v;
}

First you need to select TOOLS then AUTO-FORMAT, to indent your code to make it easier to read.
What model Arduino are you using?
What version IDE?

Thanks… Tom… :slight_smile:

Hi I am using Arduino UNO and IDE 1.6.7

I notice that you have an error talking about redline and a function called readline. Spelling is important to the compiler

You declare and use a function called select_turns but only define one called select_turn, and something similar for redline / readline

The IDE handles forward declarations for you in the .ino file, by the way.

I recommend finding a good text editor for programming, one that does auto-complete on variable and function names and supports automatic indenting.

hi, thanks for help,and its just spelling mistake,now code is compiling