• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 为什么运行这段代码控制上下的舵机无法正常运动



    • import sensor, image, time
      from pid import PID
      from servo1 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)
      red_threshold  = (13, 49, 18, 61, 6, 47)
      pan_pid = PID(p=0.07, i=0, imax=180)
      tilt_pid = PID(p=0.07, i=0, imax=180)
      pan_current = 0
      tilt_current = 0
      sensor.reset()
      sensor.set_contrast(1)
      sensor.set_gainceiling(16)
      sensor.set_pixformat(sensor.GRAYSCALE)
      sensor.set_vflip(True)
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(10)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      face_cascade = image.HaarCascade("frontalface", stages=25)
      def find_max(blobs):
      	max_size=0
      	for blob in blobs:
      		if blob[2]*blob[3] > max_size:
      			max_blob=blob
      			max_size = blob[2]*blob[3]
      	return max_blob
      while True:
      	clock.tick()
      	img = sensor.snapshot()
      	blobs =img.find_features(face_cascade, threshold=0.75, scale=1.35)
      	if blobs:
      		max_blob = find_max(blobs)
      		pan_error = max_blob[0]+max_blob[2]-img.width()/2
      		tilt_error =max_blob[1]+max_blob[3]-img.height()/2
      		print("pan_error: ", pan_error)
      		img.draw_rectangle(max_blob)
      		img.draw_cross(int(max_blob[0]+max_blob[2]), int(max_blob[1]+max_blob[3]))
      		pan_output=pan_pid.get_pid(pan_error,1)/2
      		tilt_output=tilt_pid.get_pid(tilt_error,1)
      		print("pan_output",pan_output)
      		print("tilt_output",pan_output)
      		servo.position(0, pan_current + pan_output)
      		pan_current = servo.get_angle()
      		servo.position(1, tilt_current - tilt_output)
      		tilt_current = servo.get_angle()
      


    • https://book.openmv.cc/example/15-Servo-Shield/main.html

      运行这个代码,舵机会不会动?