Example explanation-02-servo_control servo control

# 舵机控制例子
#
# 这个例子展示了如何使用OpenMV来控制舵机

import time
from pyb import Servo

s1 = Servo(1) # P7
s2 = Servo(2) # P8
s3 = Servo(3) # P9

while(True):
    for i in range(1000):
        s1.pulse_width(1000 + i)
        s2.pulse_width(1999 - i)
        s3.pulse_width(1000 + i)
        time.sleep_ms(10)
    for i in range(1000):
        s1.pulse_width(1999 - i)
        s2.pulse_width(1000 + i)
        s3.pulse_width(1999 - i)
        time.sleep_ms(10)

Singtown Technology OpenMV official Chinese document function explanation:

OpenMV4 H7 has three PWM pins: P7, P8, and P9. OpenMV4 H7 Plus has two PWM pins: P7, P8. OpenMV RT1062 has four PWM pins: P7, P8, P9, and P10.

The pyb module cannot be used on OpenMV RT, only the following machine module can be used:

# 舵机控制例子
#
# 这个例子展示了如何使用OpenMV来控制舵机
#
# 伺服系统需要 50 Hz PWM,脉冲宽度为 1000us 至 2000us。

import time
from machine import PWM

# P7 和 P8 可以共享相同的 PWM  module,它们需要具有相同的频率。
p7 = PWM("P7", freq=50, duty_ns=(2000 * 1000))
p8 = PWM("P8", freq=50, duty_ns=(2000 * 1000))

# P9 和 P10 可以共享相同的 PWM  module,它们需要具有相同的频率。
p9 = PWM("P9", freq=50, duty_ns=(2000 * 1000))
p10 = PWM("P10", freq=50, duty_ns=(2000 * 1000))


while True:
    for i in range(1000, 2000, 100):
        p7.duty_ns(i * 1000)
        p8.duty_ns(i * 1000)
        p9.duty_ns(i * 1000)
        p10.duty_ns(i * 1000)
        time.sleep_ms(1000)

    for i in range(2000, 1000, -100):
        p7.duty_ns(i * 1000)
        p8.duty_ns(i * 1000)
        p9.duty_ns(i * 1000)
        p10.duty_ns(i * 1000)
        time.sleep_ms(1000)

results matching ""

    No results matching ""