logo

电机和舵机是否能同时驱动?

2021-08-02 10:40
3
_3ksq
THRESHOLD = (40, 100, -128, 127, -128, 127) # Grayscale threshold for dark things...
import sensor, image, time
from pyb import LED, Servo
from tb6612 import Motor

servo3 = Servo(3)
servo3.angle(0)
m1 = Motor(1) # motor 1: A0 and A1
#m2 = Motor(2) # motor 2: B0 and B1

LED(1).on()
LED(2).on()
LED(3).on()

sensor.reset()
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
#sensor.set_windowing([0,20,80,40])
sensor.skip_frames(time = 2000)     # WARNING: If you use QQVGA it may take seconds
clock = time.clock()                # to process a frame sometimes.

while(True):
    clock.tick()
    m1.set_speed(10) # Forward
    #m2.set_speed(10) # Forward
    img = sensor.snapshot().binary([THRESHOLD])
    line = img.get_regression([(100,100)], robust = True)
    if (line):
        rho_err = abs(line.rho())-img.width()/2
        if line.theta()>90:
            theta_err = line.theta()-180
        else:
            theta_err = line.theta()
        img.draw_line(line.line(), color = 127)
        print(rho_err,line.magnitude(),theta_err)
        if line.magnitude()>8:
            servo3.angle(0+theta_err)
2021-08-02 14:11
I
网红小智智 星瞳科技

不能同时使用,引脚冲突。

2021-08-02 16:27
3
_3ksq

舵机用p9 电机用p7 p8也不行吗?

2021-08-02 16:33
I
网红小智智 星瞳科技

那可以,但是电机的pwm定时器要改,不能用4

2021-08-02 16:41
3
_3ksq
a0347dff-7ae6-45e3-ba1e-e768ca524b05.png
2021-08-02 18:15
I
网红小智智 星瞳科技

你用的什么OpenMV硬件?

2021-08-02 18:49
3
_3ksq

@kidswong999 openmv4 h7

2021-08-03 12:26
I
网红小智智 星瞳科技

https://github.com/openmv/openmv/blob/master/scripts/libraries/tb6612.py

得把这里面的time4都改成其他的,然后把tb6612.py放到sd卡里。