장애물에 도달 할 때까지이 로봇을 임의의 방향으로 이동하려고합니다. 그런 다음 장애물 (장애물 = 1,2,3 등)을 기록하고 방향을 전환해야합니다. 이것은 타이머가 만료 될 때까지 계속되어야합니다.로봇 장애물 기록/회피
public static void main(String args[]) throws Exception{
Robot therobot = new Robot();
int x = 10000;
int obstacles = 0;
Random rand = new Random();
int r1 = rand.nextInt(255) + 1;
int r2 = rand.nextInt(255) + 1;
therobot.setWheelVelocities(100,100);
long before = System.currentTimeMillis();
while (System.currentTimeMillis() - before < x){
Thread.sleep(x);
if(therobot.isObstacle() ==true || therobot.isTapped() == true)
{
r1 = rand.nextInt(255) - 255;
r2 = rand.nextInt(255) - 255;
obstacles = obstacles++;
therobot.setWheelVelocities(r1, r2);
}
}
System.out.println(obstacles);
therobot.stopWheels();
therobot.quit();
}
하지만 이것은 작동하지 않습니다. 타이머가 만료 될 때까지 진행되지만 아무 것도 멈추지 않거나 기록하지 않습니다.
무엇이 누락 되었습니까?
테스트 할 때 각 반복에 대해 10 초를 사용하지 말 것을 제안합니다. 우리가 isObstacle 및 isTapped에 대한 동작을 모르는 경우에도 우리는 당신을 도울 수 없습니다. while 루프의 끝에 therobot.quit()을 호출하는 이유는 무엇입니까? 당신이 while 회 돌이에서 벗어 났을 때 그걸 부르면 안되니? –
이름을 기반으로 추측하면 왼쪽 또는 오른쪽 장애물 센서가 장애물을 감지하면 isObstacle은 true를 반환합니다. isTapped의 경우와 똑같습니다. 뭔가 닿는다면 움직이지 말아야합니다. 또한, 그들은 부울입니다. – George
therobot.quit() 및 stopWheels()은 무엇입니까? –