我使用 AlColorBlobDetection 来检测绿灯(我有一个可以切换颜色的玩具交通灯),但是,看起来我的机器人跟踪的是光或白色,但绝对不是绿色。我附上了代码。我用的是编舞。我希望你有机会研究一下。非常感谢!
MyClass 类(生成的类):
def init(自我):
生成的类。init(自身)
def onLoad(self):
通过
def onUnload(self):
通过
def onInput_onStart(self):
运动 = ALProxy(“ALMotion”)
姿势 = ALProxy("ALRobotPosture")
tracker = ALProxy("ALTracker")
运动.wakeUp()
分数最大速度 = 0.8
posture.goToPosture("StandInit",fractionMaxSpeed)
motionProxy = ALProxy("ALColorBlobDetection")
motionProxy.setColor(0,250,0,200)
事件名称 =“ALTracker/ColorBlobDetected”
模式=“头部”
tracker.setMode(模式)
tracker.trackEvent(事件名称)
打印“ALTracker成功启动,现在向机器人显示绿色!”
打印“使用 Ctrl+c 停止此脚本。”
尝试:
而真实:
时间.睡眠(1)
键盘中断除外:
打印
打印“被用户中断”
打印“正在停止...”
tracker.stopTracker()
tracker.unregisterAllTargets()
posture.goToPosture("坐",fractionMaxSpeed)
运动.rest()
打印“ALTracker 已停止。”
def onInput_onStop(self):
self.onUnload() # 建议在盒子停止时重复使用清理工作
self.onStopped() # 激活盒子的输出