gpt4 book ai didi

c - Mindstorms 的 Robotc **错误** :Undefined variable 'sonarSensor' . 假设为 'short'

转载 作者:行者123 更新时间:2023-11-30 18:10:03 25 4
gpt4 key购买 nike

理论上,这段代码应该永远循环,直到声纳传感器检测到高于 10 厘米的值,但是当我尝试编译此程序时,会出现消息

错误:

Undefined variable 'sonarSensor'. 'short' assumed. I'm not sure why it does not see that sonar has been initialized.

代码:

//Program: Bridge Layer
//Date: 12/14/19

#pragma config(Sensor, S4, sonar, sensorSONAR); //Enable sonar to sensor pin 4 on the NXT

task main()
{
int distance_in_cm = 10; //Initialize sensor value variable
while(SensorValue[sonar] < distance_in_cm){ //Creat a loop checking if the sonar sensor ever sees a value above 10 cm's
motor[motorB]= 50; //Start motor B forwards att 50% power
motor[motorC]= 50; //Start motor C forwards att 50% power
}
motor[motorB]= 50; //Stop motor B
motor[motorC]= 50; //Stop motor C
}

最佳答案

好吧,我现在很好,我发现您必须完成配置向导并设置声纳传感器的端口和类型。谢谢您的帮助。

关于c - Mindstorms 的 Robotc **错误** :Undefined variable 'sonarSensor' . 假设为 'short',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59366656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com