Hello,
I have not worked with Finch but I have little experience in programming. So I have refactored your code a little bit to make it readable and added few TODO comments. This may help you.
import edu.cmu.ri.createlab.terk.robot.finch.Finch;
public class FollowAnObjectSolution {
Finch myF = new Finch();
int Buzz = 300;
int BuzzDuration = 12;
int R = 250;
int G = 250;
int velocityRight = 150;
int velocityLeft = 150;
int turnLeft = -50;
int turnRight = -50;
public FollowAnObjectSolution() { }
public void StartObserving()
{
while (true) {
if (myF.isTapped() == true &&
myF.isObstacleLeftSide() == true &&
myF.isObstacleRightSide() == true &&
myF.isObstacle() == true) {
myF.setLED(R, 0, 0);
myF.setWheelVelocities(velocityLeft, velocityRight);
boolean RunAgain = true;
while (RunAgain) {
Move();
if (myF.isTapped() == true && myF.isTapped() == true) {
break;
}
}
}
}
}
public static void main(String[] args) {
new FollowAnObjectSolution().StartObserving();
}
private void Move() {
if (myF.isObstacleRightSide() == false &&
myF.isObstacleLeftSide() == false &&
myF.isObstacle() == true) {
MoveStraight();
} else if (myF.isObstacleRightSide() == false &&
myF.isObstacleLeftSide() == true) {
MoveLeft();
} else if (myF.isObstacleRightSide() == true &&
myF.isObstacleLeftSide() == false) {
MoveRight();
} else if (myF.isObstacleRightSide() == true &&
myF.isObstacleLeftSide() == true) {
StopMoving();
}
}
private void MoveStraight() {
myF.setLED(0, G, 0);
myF.setWheelVelocities(velocityLeft, velocityRight);
myF.buzz(Buzz, BuzzDuration);
}
private void MoveLeft() {
myF.setLED(0, G, 0);
myF.setWheelVelocities(turnLeft, velocityRight);
myF.buzz(Buzz, BuzzDuration);
}
private void MoveRight()
{
myF.setLED(0, G, 0);
myF.setWheelVelocities(velocityLeft, turnRight);
myF.buzz(Buzz, BuzzDuration);
}
private void StopMoving()
{
myF.setLED(R, 0, 0);
myF.stopWheels();
myF.buzz(Buzz, BuzzDuration);
}
}