import sensor, image, time
from pyb import Servo
yellow_threshold = (100, 56, -13, -58, 3, 61)
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.
K=350#the value should be measured
length=0
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
blobs = img.find_blobs([yellow_threshold])
if len(blobs) == 1:
# Draw a rect around the blob.
b = blobs[0]
img.draw_rectangle(b[0:4]) # rect
img.draw_cross(b[5], b[6]) # cx, cy
Lm = (b[2]+b[3])/2
length = K/Lm
print(length)
#print(Lm)
if length<10:
s1 = Servo(1)
s2 = Servo(2)
while(True):
for i in range(1000):
s1.pulse_width(1600 - i)
s2.pulse_width(1600 - i)
time.sleep_ms(600)
for i in range(1000):
s1.pulse_width(1600 - i)
s2.pulse_width(1600 - i)
time.sleep_ms(600)
else:
s1 = Servo(1)
s2 = Servo(2)
while(True):
for i in range(1000):
s1.pulse_width(2999 - i)
s2.pulse_width(2999 - i)
time.sleep_ms(600)
for i in range(1000):
s1.pulse_width(2999 - i)
s2.pulse_width(2999 - i)
time.sleep_ms(600)会出现上电的瞬间可以识别出来距离并且控制电机转动,之后画面就定住了也没有数据从串口端出现。可以烧录进去并脱机使用但是脱机的时候和用ide编译的时候一样只能刚上电的时候识别一次
你第30行,和42行,都是死循环,永远不会跳出的。
@kidswong999 大佬有没有什么办法可以让他不卡死啊求赐教呀,初学不太懂(需求就是控制两个舵机在识别到一个颜色且距离小于一定范围时可以同时旋转)谢谢大佬
https://book.openmv.cc/project/pan-tilt.html
参考一下这个。
@kidswong999 谢谢大佬非常感谢我去好好学习一下