代码
通过调用dg函数驱动舵机,且会从原始位置开始运动,可以自定义时间
mog={0:90,1:90,2:90,3:90,4:90,5:90}
# 5,90-15
def dg(ed,n=0,t=0.02):
st=mog[n]
x=1
if st>ed:
x=-1
for i in range(st,ed,x):
s.position(n,i)
mog[n]=i
time.sleep(t)
def init_top():
s.position(0,90)
s.position(1,90)
s.position(2,90)
s.position(3,90)
s.position(4,90)
s.position(5,90)
mog={0:90,1:90,2:90,3:90,4:90,5:90}
def bite(f=True):
if f:
s.position(5,155)
else:
s.position(5,90)
dg(90,1)
#设置·舵机转到90度
dg(120,4)
#设置4舵机转到120度
from machine import I2C,Pin
import time
from servo import Servos
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=10000)
s=Servos(i2c,address=0x40,min_us=500, max_us=2500)
mog={0:90,1:90,2:90,3:90,4:90,5:90}
# 5,90-15
def dg(ed,n=0,t=0.02):
st=mog[n]
x=1
if st>ed:
x=-1
for i in range(st,ed,x):
s.position(n,i)
mog[n]=i
time.sleep(t)
def init_top():
s.position(0,90)
s.position(1,90)
s.position(2,90)
s.position(3,90)
s.position(4,90)
s.position(5,90)
mog={0:90,1:90,2:90,3:90,4:90,5:90}
def zero():
dg(0,0)
dg(0,1)
dg(0,2)
dg(0,3)
dg(0,4)
dg(90,5)
mog={0:0,1:0,2:0,3:0,4:0,5:90}
def top():
dg(90,0)
dg(90,1)
dg(90,2)
dg(90,3)
dg(90,4)
dg(90,5)
mog={0:90,1:90,2:90,3:90,4:90,5:90}
def bite(f=True):
if f:
s.position(5,155)
else:
s.position(5,90)
def hello(t=0.02):
top()
dg(135,2,t)
dg(45,2,t)
dg(90,2,t)
init_top()