我是编程的初学者并试图制作一个清洁机器人 NXT 我连接(超声波传感器)和(声音传感器)机器人的工作是当我拍手时它必须开始向前移动并且当超声波传感器在它必须转身并继续前进。问题是当它转动时它不会继续前进,直到我再次鼓掌!!!!!!
这是我写的代码:
public static void main(String[] args) {
// TODO Auto-generated method stub
TouchSensor touch = new TouchSensor(SensorPort.S2);
SoundSensor sound = new SoundSensor( SensorPort.S4 );
UltrasonicSensor sonic = new UltrasonicSensor( SensorPort.S3);
Motor.A.setSpeed( 400 );
Motor.C.setSpeed( 400 );
Button.waitForAnyPress();
int SoundValue;
SoundValue = sound.readValue();
System.out.print(SoundValue);
do {
if ( sound.readValue() > 50 ) {
// PROBLEM:
while ( sonic.getDistance() > 30 ){
Motor.B.backward();
Motor.A.backward();
Motor.C.backward();
}
{
Motor.A.rotate( -185, true );
Motor.C.rotate( 185, true );
}
};
}
while( Button.readButtons() != Button.ID_ESCAPE );
}
有人可以帮忙解决这个问题吗??????
thnx 无论如何。