我无法让我的机器人使用 RobotC 控制我的 Mindstorms NXT 机器人。我希望我的机器人能够在桌子上向前移动,当到达末端时,朝下的超声波传感器将通过查看地面的距离来确定它是否在边缘。当超声波传感器发现它在边缘时,机器人会从边缘向后移动,掉头,然后走另一条路。
这是我的代码:
#pragma config(Sensor, S1, , sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
int Ultrasonic;
Ultrasonic = SensorValue[S1];
while (true)
{
if (Ultrasonic >10)
{
motor[motorB] = -100;
motor[motorC] = -100;
wait1Msec(2000);
motor[motorB] = 100;
wait1Msec(2000);
}
if (Ultrasonic <= 10)
{
motor[motorB] = 50;
motor[motorC] = 50;
wait1Msec(5000);
}
}
}