首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Finch机器人编程

Finch机器人编程
EN

Stack Overflow用户
提问于 2015-08-22 00:42:25
回答 1查看 2.6K关注 0票数 0

我正在写一个程序,我必须让我的finch机器人跟随一个物体。我已经写了它,以便一旦它被轻击在顶部,它将通过感知周围的物体开始。只要我点击顶部并覆盖传感器,红灯就会亮起,它会跟随物体朝着覆盖的传感器的方向移动。当它移动时,它应该发出嗡嗡的声音,并使灯光从红色变为绿色。当我停止移动对象时,finch应该将它的鼻子转回红色,并等待它被轻击两次以结束程序,或者直到对象被移动以使其继续跟随。然而,当我点击它时,什么也没有发生。

下面是我的代码:

代码语言:javascript
复制
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);

  }


}
EN

回答 1

Stack Overflow用户

发布于 2015-08-22 00:47:44

你的main方法是空的。Java从main开始,所以你需要在main中开始你的新Finch。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32145429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档