如何检查一个值是否没有变化?我的Pi2GO Lite正在计算它在开车时做了多少步。有时候轮子卡在什么东西上,不再动了。遗憾的是,由于缺乏传感器,它没有注意到这一点。它有很多盲点。
这是我代码中的计数部分:
countL = 0
countR = 0
runL = True
runR = True
running = True
speed = 60
try:
lastValidL = 2
lastValidR = 2
lastL = pi2go.irLeftLine()
lastR = pi2go.irRightLine()
while True:
if pi2go.getDistance() >=8:
while pi2go.getDistance() >=8:
if countR > countL:
pi2go.turnForward(90,85)
if countR < countL:
pi2go.turnForward(85,90)
if countR == countL:
pi2go.turnForward(85,90)
val = pi2go.irLeftLine()
if val == lastL and val != lastValidL:
countL +=1
lastValidL = val
lastL = val
print "L:", countL
val = pi2go.irRightLine()
if val == lastR and val != lastValidR:
countR += 1
lastValidR = val
lastR = val
print "R:", countR
#heres the function I want.
oldL = countL +
print oldL
if True:
if oldL == countL:
time.sleep(5)
#if oldL has still the same value as count L
if oldL == countL
pi2go.stepReverse(80,20)现在我的问题是:"time.sleep(5)“计数器也停止了。所以countL和oldL绝对是一样的。
如何在不随每个计数更改变量的情况下创建具有当前计数值的变量?如果你知道我的意思,我需要一个“静态”数字。
发布于 2018-07-13 06:36:33
在python中,静态功能可以通过全局变量来实现。
你的问题不够清楚,无法理解。
https://stackoverflow.com/questions/51302374
复制相似问题