我一直致力于让一个机器人跟随声音的程序,但我不断得到奇怪的编译器错误。我猜我犯了一些错误,把编译器扔掉了。
#define TICKS_TO_SAMPLE 6
#define MS_TO_SAMPLE 100
#define TIME_TO_QUIET 250
#define ONE_THIRD 480
#define SAMPLE_DEPTH 20
#define NUM_OF_MOVEMENTS 6
#define TIME_MOVING 1000
#define MIC SENSOR_1
int gauge()
{
int soundMax = 0;
for(int tick = 0; tick < TICKS_TO_SAMPLE; tick++){
if(MIC > soundMax){
soundMax = MIC;
}
Wait(MS_TO_SAMPLE);
}
return soundMax;
}
int soundFind(int width)
{
int firstMax = 0;
firstMax = gauge();
OnFwd(OUT_A, 75);
Wait(width);
Off(OUT_AC);
Wait(TIME_TO_QUIET);
int secondMax = 0;
secondMax = gauge();
OnRev(OUT_A, 75);
Wait(width*2);
Off(OUT_AC, 75);
Wait(TIME_TO_QUIET);
int thirdMax = 0;
thirdMax = gauge();
if(firstMax >= secondMax && firstMax >= thirdMax)
{
OnRev(OUT_A, 75);
Wait(width);
Off(OUT_AC);
Wait(TIME_TO_QUIET);
}
else
{
if(secondMax >= firstMax && secondMax >= thirdMax)
{
OnRev(OUT_A, 75);
Wait(width*2);
Off(OUT_AC);
Wait(TIME_TO_QUIET);
}
}
if(width > SAMPLE_DEPTH)
{
return width/3;
}
else{
return 0;
}
}
task main()
{
int startingAngle = ONE_THIRD;
SetSensorSound(IN_1);
for(int movements = 0; movements < NUM_OF_MOVEMENTS; movements++){
startingAngle = soundFind(ONE_THIRD);
while(startingAngle > SAMPLE_DEPTH)
{
startingAngle = soundFind(ONE_THIRD);
}
OnRev(OUT_AC, 75);
Wait(TIME_MOVING);
Off(OUT_AC);
}
}
吐出
line 32 Error: ')' expected
line 32 Error: ';' expected
和
Error: Unmatched close parenthesis
第32,33,35-39,40,45-48,51,58,60-64,66-68行
答案 0 :(得分:1)
Off()
功能只接受一个参数,即电机端口。您正尝试将功率值作为第二个参数传递。