使用pca9685代替云台的绿色的板子,按上WiFi模块,可以传输图流,但是云台抽动,程序无报错
-
import sensor, image, time, network, usocket, sys from servo import Servos from machine import I2C, Pin i2c = I2C(sda=Pin('P5'), scl=Pin('P4')) servo = Servos(i2c, address=0x40, freq=50, min_us=500, max_us=2500, degrees=180) SSID ='OPENMV_AP' # Network SSID KEY ='1234567890' # Network key (must be 10 chars) HOST = '' # Use first available interface PORT = 8080 # Arbitrary non-privileged port # Reset sensor sensor.reset() # Set sensor settings sensor.set_contrast(1) sensor.set_brightness(1) sensor.set_saturation(1) sensor.set_gainceiling(16) sensor.set_framesize(sensor.QQVGA) sensor.set_pixformat(sensor.RGB565) # 在AP模式下启动wlan模块。 wlan = network.WINC(mode=network.WINC.MODE_AP) wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2) #您可以阻止等待客户端连接 #print(wlan.wait_for_sta(10000)) def start_streaming(s): print ('Waiting for connections..') client, addr = s.accept() # 将客户端套接字超时设置为2秒 client.settimeout(2.0) print ('Connected to ' + addr[0] + ':' + str(addr[1])) # 从客户端读取请求 data = client.recv(1024) # 应该在这里解析客户端请求 # 发送多部分head client.send("HTTP/1.1 200 OK\r\n" \ "Server: OpenMV\r\n" \ "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \ "Cache-Control: no-cache\r\n" \ "Pragma: no-cache\r\n\r\n") # FPS clock clock = time.clock() # 开始流媒体图像 #注:禁用IDE预览以增加流式FPS。 while (True): clock.tick() # Track elapsed milliseconds between snapshots(). frame = sensor.snapshot() cframe = frame.compressed(quality=35) header = "\r\n--openmv\r\n" \ "Content-Type: image/jpeg\r\n"\ "Content-Length:"+str(cframe.size())+"\r\n\r\n" client.send(header) client.send(cframe) print(clock.fps()) while (True): # 创建服务器套接字 s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) try: # Bind and listen s.bind([HOST, PORT]) s.listen(5) # 设置服务器套接字超时 # 注意:由于WINC FW bug,如果客户端断开连接,服务器套接字必须 # 关闭并重新打开。在这里使用超时关闭并重新创建套接字。 s.settimeout(3) start_streaming(s) except OSError as e: s.close() print("socket error: ", e) #sys.print_exception(e) servo.position(2, 0) time.sleep(1500) servo.position(1, 20) time.sleep(1500) servo.position(1, 80) time.sleep(1500) servo.position(2, 150) time.sleep(1500) servo.position(1, 20) time.sleep(1500) servo.position(1, 80) time.sleep(1500)
-
你的程序有问题啊,前面一个死循环,后面的代码都执行不到。
-
就是把后面的程序放到前面的死循环里,它也不动,请问为啥?我这个只是在WIFI图流的程序上改的
-
你可以试试在start_streaming函数里面加入控制舵机的代码。
-
@kidswong999 只可以循环一次,然后舵机就再也不动了,如果连上WiFi的话,就彻底不动了
-
@kidswong999 您好,我看您淘宝店铺视屏里实现了这个功能,可以分享一下吗?
-
哪个功能?并没有Wi-Fi图传同时云台啊?
-
@kidswong999 那这个程序怎么能让他正常运行呢?我那样试了不行