Line following general question

My robot is following a line but is going incredibly slow. I realize that since I am using stepper motors this will be the case most of the time but in autonomous mode my bot can go pretty fast. I believe the problem with line following mode is my algorithm. Does anyone see anything in my function that I could possibly change to make it better? I am using interrupts on my line sensor. Also my motor functions being called are just stepping through the motor...

video of how slow its going;

void lineSensor(){
  
  //012345
  //XX00XX
  //XXXX00
  //00XXXX
  
  
  while(linerun == true){
  
  batteryAction.check(); 
  unsigned int position = qtrrc.readLine(sensorValues);
  
  unsigned char i;
  for (i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(sensorValues[i] * 10 / 1001);
    Serial.print(' ');
  }
  Serial.print("    ");
  Serial.println(position);
  
  if((((sensorValues[2] * 10 / 1001) <= 2 )||((sensorValues[3] * 10 / 1001) <= 2))){
  for(int a = 0; a < 5; a++){
  motorsf();
  }
  }
  if((((sensorValues[4] * 10 / 1001) <= 2 )||((sensorValues[5] * 10 / 1001) <= 2))){
    
  motorsr();
    
  }
  if((((sensorValues[0] * 10 / 1001) <= 2 )||((sensorValues[1] * 10 / 1001) <= 2))){
  
  motorsl();
  
  }
  
  }
}

Not much to go on with there. How about posting all the code?

Also try commenting out the Serial prints. They take time. (Or put something like #if DEBUG around them).

You need to post ALL the code.

I would say you have it the wrong way round. Step the motors from the interrupts and look at the line from the loop.

The code is too big to post here but I have it on pastebin...The stepper motors are not using the interrupts.

The stepper motors are not using the interrupts.

I know I said it would be better if they were.

I understand I was just making it clear to everyone. I tried using interrupts on them and cant seem to get the timing right because I loose half of the torque.

Then you are not doing it right. Why should the torque be halved?
What are you using as a driver?
Can you post a schematic?

Just looked at your code. My god you should learn how to program if you want to make anything half decent. It is one of the worst examples of copy and past coading I have ever seen.
Sorry to be brutal but this is more than half your problem.

I actually built the motor drivers myself but I don't have the schematic on this computer, I will post them later. I am an engineering student not a computer scientist. I am trying my best. My torque is not halfed.

void motorsl(){
 
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(4);
  digitalWrite(motorPin5, HIGH);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
  delay(4);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(4);
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, HIGH);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, LOW);
  delay(4);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(4);
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, HIGH);
  digitalWrite(motorPin8, LOW);
  delay(4);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(4);
  digitalWrite(motorPin5, LOW);
  digitalWrite(motorPin6, LOW);
  digitalWrite(motorPin7, LOW);
  digitalWrite(motorPin8, HIGH);
  delay(4);
  //digitalWrite(motorPin8, LOW);
 
}

Thats 8 X 4 mS delays each time you call this. Total: 32 mS.

 for(int a = 0; a < 5; a++){
  motorsf();
  }

Multiply that by 5. 160 mS.

I'm surprised it isn't slower. Redesign to get rid of the delays.

Thanks Nick,
What do you think the best way to do this is? My past only consists of programming in languages like Assembly mostly. I have played around with a lot of Java but never for anything like this. I wrote the motor code like I would have in Assembly. I am not sure how I could do this without a delay. If I took out the delay I would blow a fuse because 12 V would be fed in directly. Any ideas?

Blow a fuse? Huh? Well try making the delays 2 rather than 4 (make a variable, don't put literal numbers everywhere). See what that does.

If I took out the delay I would blow a fuse because 12 V would be fed in directly.

How does your program code change whether or not 12V is fed in directly?

I might have misunderstood what you were saying. I cannot have all of the motor coils active at the same time. Do you have an example of how I might do the motor code without the delays?

OK, well I'm not an expert on stepper motors. But how about finding a stepper library rather than doing it yourself?

I tried the library and I had some trouble with it. There must be a way to do it without using the library. And yes, if I energized all of the coils of the motors too fast or at the same time I would blow my 2 amp fuse. That is why there are delays as well as why I am setting the motor wires low when they must be low. If the delays are below 4 mS, the motors have no torque and the bot will not move. Anything above 4 will move the bot though. I am experimenting with other methods of doing it right now, let me know if any of you find a way.

I tried the library and I had some trouble with it

What kind of trouble?

I don't know - Mr Wentworth just told me to come in here and say that there was trouble at the mill, that's all - I didn't expect a kind of Spanish Inquisition.