EsqqRam
EsqqRam

Reputation: 1

Finch robot programming

I am writing a program where I have to make my finch robot follow an object. I have written it so that the finch will begin by sensing objects around it once it has been tapped on the top. As soon as I tap the top and cover the sensors, a red light is supposed to turn on and it will follow the object in the direction of the covered sensor. While it is moving, it should be making a buzzing sound and have the light change from red to green. When I stop moving the object, the finch is supposed to turn it's nose back to red and wait until it is either tapped twice to end the program or until the object is moved for it to continue following. However, when I tap it, nothing happens.

Here is my code:

import edu.cmu.ri.createlab.terk.robot.finch.Finch;

public class FollowingAnObject 
{
static Finch myF = new Finch();

public static void main(String[] args) 
{
    myF = new Finch();
}
    public FollowingAnObject() 
{

while (true)
{    

//This begins the movement of the finch  

if (myF.isTapped() == true  && myF.isObstacleLeftSide() == true && myF.isObstacleRightSide() == true && myF.isObstacle() == true)
    {     
//LED colours are red, green and blue
myF.setLED(R,0,0);
myF.setWheelVelocities(velocityLeft, velocityRight);

//Triggers the RunAgain function to true so that the program does not stop in one run so that the Finch will continue to move

boolean RunAgain = true;




while(RunAgain)
        {

//Calling the Move method for the Finch movements

Move();

//Inside the while, RunAgain loop , there is a conditional statement that makes the program terminate if the Finch has been tapped twice

if (myF.isTapped()==true && myF.isTapped()==true)
            {
                break;
            }
        }
      }
    }
  }

// Method for all of the Finch movements
public static 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();

   }

}


//All of the variables have been declared

static int Buzz = 300;
static int BuzzDuration = 12;


static int R = 250;
static int G = 250;

static int velocityLeft = 150;
static int velocityRight = 150;

static int turnLeft = -50;
static int turnRight = -50;;




//If the finch is moving straight, the light will be green and both of the wheels will move at 150
public static void MoveStraight()

  {
      myF.setLED(0, G, 0);

      myF.setWheelVelocities(velocityLeft, velocityRight);

      myF.buzz(Buzz, BuzzDuration);
  }

public static void MoveLeft()

  {
//If the finch is moving left, the light will be green, the left wheel will move at -50 and the right wheel will move at 150
      myF.setLED(0, G, 0);

      myF.setWheelVelocities(turnLeft, velocityRight);

      myF.buzz(Buzz, BuzzDuration);

  }

public static void MoveRight()

//If the finch is moving right, the light will be green the left wheel will move at 150 and the right wheel will move at -50
  {
      myF.setLED(0, G, 0);

      myF.setWheelVelocities(velocityLeft, turnRight);

      myF.buzz(Buzz, BuzzDuration);

  }

public static void StopMoving()

//if the Finch is not moving, the colour of the light will be red and the buzzing will stop
  {
      myF.setLED(R, 0 , 0);

      myF.stopWheels();

      myF.buzz(Buzz, BuzzDuration);

  }


}

Upvotes: 0

Views: 2651

Answers (1)

Lucas
Lucas

Reputation: 5069

Your main method is empty. Java starts at main, so you need to start your new Finch in main.

Upvotes: 1

Related Questions