Put the two things in functions, then implement a basic state machine. So you get something like this:
#define LINEFOLLOWER 0
#define OBSTACLEAVOIDANCE 1
byte mode = LINEFOLLOWER;
void loop() {
checkIR();
switch (mode) {
case LINEFOLLOWER:
linefollower();
break;
case OBSTACLEAVOIDANCE:
obstacleavoidance();
break;
}
}
void checkIR() {
// Read command over IR.
// set mode accordingly.
if (command == 'l') mode = LINEFOLLOWER;
if (command == 'o') mode = OBSTACLEAVOIDANCE;
}
void linefollower() {
// original linefollower loop()
}
void obstacleavoidance() {
// original obstacleavoidance loop()
}