将串口得到的数据用JSON格式化有相关的资料吗
6gzn
@6gzn
6gzn 发布的帖子
-
PID控制舵机实现巡线小车问题
我将巡线小车例程和追小球云台代码合在一起,可以初步实现巡线,但是舵机转向并不灵敏,转向的角度要么多大要么太小,小车无法实现巡线,求如何调节参数实现小车巡线。
以下是main.py代码:
THRESHOLD = (59, 86, 15, 62, -15, 31) # Grayscale threshold for dark things...
import sensor, image, time
from pyb import LED
from pid import PID
from pyb import Servopan_servo=Servo(1) #p7
rho_pid = PID(p=0.4, i=0)
theta_pid = PID(p=0.001, i=0)LED(1).off()
LED(2).off()
LED(3).off()sensor.reset()
sensor.set_vflip(False)
sensor.set_hmirror(False)
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()
img = sensor.snapshot().binary([THRESHOLD])
line = img.get_regression([(100,100,0,0,0,0)], 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(),rho_err)
if line.magnitude()>8:
#if -40<b_err<40 and -30<t_err<30:
rho_output = rho_pid.get_pid(rho_err,1)
theta_output = theta_pid.get_pid(theta_err,1)
output = rho_output+theta_output
#car.run(50+output, 50-output)
pan_servo.angle(pan_servo.angle()+output)
else:
pan_servo.angle(pan_servo.angle())
else:
pan_servo.angle(pan_servo.angle())
pass
#print(clock.fps()) -
RE: 循迹小车PID相关
rho_pid = PID(p=0.4, i=0)
theta_pid = PID(p=0.001, i=0)
这两行代码的参数对转向有怎么的影响