从现在开始, 将使用到传感器, 涉及到对传感器的操作.
任务简介
本文为 virtual world challenge pack 中的传感器(SENSORS) 中的
“move untill touch”, 如图 1 所示. 要求从起点 A 出发一直前进,
直到碰到障碍物就停止前进.
图 1 move untill touch 界面图
此挑战使用的 robot 为 “Clawbot IQ-arm up”, 基本配置如图 2 所示.
图 2 robot 基本配置
程序
#pragma config(StandardModel, "Clawbot IQ With Sensors")
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
// loop untill touches a block
while(getBumperValue(bumpSwitch) != 1){
setMotorSpeed(leftMotor, 50);
setMotorSpeed(rightMotor, 50);
}
//
stopAllMotors();
}
图 3 robot 运行中间截图.
图 3 运行中间截图
运行结果如图 4 所示.
图 4 运行结果