导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. h4rl
    H
    • 举报资料
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    h4rl

    @h4rl

    0
    声望
    17
    楼层
    496
    资料浏览
    0
    粉丝
    0
    关注
    注册时间 最后登录

    h4rl 关注

    h4rl 发布的帖子

    • 为什么不能在List数组尾部增加数字1

      代码是这样的

      # Select an area in the Framebuffer to copy the color settings.
      #from machine import I2C
      #from vl53l1x import VL53L1X
      import time
      
      from pid import PID
      from pyb import UART
      import math
      import json
      clock = time.clock() # Tracks FPS.
      
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      
      
      #i2c = I2C(2)
      #distance = VL53L1X(i2c)
      x_pid = PID(p=0.05, i=0.05, imax=100)
      d_pid = PID(p=0.05, i=0.1, imax=50)
      
      #uart1 = UART(3, 9600,timeout=1000)
      uart1=UART(3, 9600)
      uart1.init(9600, bits=8, parity=None, stop=1)
      uart2=UART(1, 9600)
      uart2.init(9600, bits=8, parity=None, stop=1)
      
      List=list()
      while(True):
      #    clock.tick() # Track elapsed milliseconds between snapshots().
          List=[1]
          if uart1.any():
      #        x_error =uart1.readline().decode()
              x_error = int(uart1.read().decode())
              print(x_error)
              SET=600
      
      
      #        x_output=x_pid.get_pid(x_error,1)
      #        print(x_output)
              if(x_error>=9999):
                  a=len(List)
                  D_24=0
                  D_13=0
                  List.append=("1")
                  a=len(List)
                  if(a>=3):
                      FH = bytearray([57,168])
                      uart2.write(FH)
      
                      data = bytearray([27,27,27,27,60,5,60,5])   ###
                      uart2.write(data)
                      print(int(D_13),int(D_24))
              else:
                  List=[0,]
                  if(abs(x_error)>SET):
      
                      x_output=d_pid.get_pid(x_error,1)
      
      
                      D_24=-x_output   ###
                      D_13=x_output  ###
                      if((D_13)>=0):
                          a=5
                      else:
                          a=60
                      if((D_24)>=0):
                          b=5
                      else:
                              b=60
      
      #               FH = bytearray([168,168])
      #               uart2.write(FH)
                      D_13=abs(D_13)
                      D_24=abs(D_24)
                      if((D_13)>35):
                          D_13=35
                      if((D_24)>35):
                          D_24=35
      
                      FH = bytearray([57,168])
                      uart2.write(FH)
                      data = bytearray([int(D_13),int(D_24),int(D_13),int(D_24),a,b,a,b])   ###
                      uart2.write(data)
      
      
      #                print(int(D_13),int(D_24),a,b,a,b)
      
      
                  else:
      #               x_output=x_pid.get_pid(x_error,1)
      #               print(x_output)
                      theta_default=0.5*math.pi            #  0.5*3.14
      #               l_threshold=100                     #####
                      delta_theta_max=0.785
                      a=delta_theta_max/SET
      #               print(a)
      #               x_output=x_pid.get_pid(x_error,1)
                      delta_theta=a*x_error
      #               d = distance.read()
      #               print(d)
      
                      k=30   ####
                      D_14=k*(math.cos(theta_default+delta_theta)+math.sin(theta_default+delta_theta))
                      D_23=k*(math.sin(theta_default+delta_theta)-math.cos(theta_default+delta_theta))
      #                print(D_14,D_23)
                      FH = bytearray([57,168])
                      uart2.write(FH)
                      data = bytearray([int(D_14),int(D_23),int(D_23),int(D_14),5,5,5,5])
                      uart2.write(data)
                      print(int(D_14),int(D_23),int(D_23),int(D_14),5,5,5,5)
      
      
      会报错:AttributeError: 'NoneType' object has no attribute 'append'
      发布在 OpenMV Cam
      H
      h4rl
    • RE: 追球小车中的pid为什么是增量式pid的

      @kidswong999 啊不是,不是这个意思,我是说咱们程序中pid代码返回的是占空比还是占空比的增量啊

      发布在 OpenMV Cam
      H
      h4rl
    • 增量式pid的代码是不是有问题

      小车pid代码是不是用问题

      output += error * self._kp
      

      既然用的是增量式pid,为什么是kp乘以error呢,根据增量式 PID 公式:
      Pwm += Kp[e(k)-e(k-1)]+Ki*e(k)+Kd[e(k)-2e(k-1)+e(k-2)]
      难道不应该是kp乘以error-self._last_error吗

      发布在 OpenMV Cam
      H
      h4rl
    • 为什么追小球的小车pid没有用微分控制

      为什么追小球的小车没有用微分控制,只用了p和i呢

      发布在 OpenMV Cam
      H
      h4rl
    • RE: 追球小车中的pid为什么是增量式pid的

      那咱们的pid代码返回的是增量吗还是占空比啊

      发布在 OpenMV Cam
      H
      h4rl
    • 串口调试助手连续发送多次,接收到的数据会打印在一行,该怎么解决呢

      0_1601301310146_0.PNG

      代码如下:

          if uart1.any():
              x_error = int(uart1.readline().decode())
              print(x_error)
      
      发布在 OpenMV Cam
      H
      h4rl
    • OpenMV接收gbk字符串怎么接收不到呢

      我用下面这两种代码都接收不到,应该怎么办呢

          if uart1.any():
              x_error = uart1.read()
              print(x_error)
      
          if uart1.any():
              x_error = int(uart1.readline().decode())
              print(x_error)
      
      发布在 OpenMV Cam
      H
      h4rl
    • 追球小车中的pid为什么是增量式pid的

      增量式pid不是应该返回增量吗,为什么这个返回的是当前的占空比的

      发布在 OpenMV Cam
      H
      h4rl
    • 追球小车里,是怎么让小车到达一定距离就停下的
      car.run(-h_output-x_output,-h_output+x_output)
      

      当小车到达合适的距离而且左右也没有偏差的时候,h_error和x_error都为0,但由于是增量式pid,h_output和x_output都不为0,而且如果是从远处走向近处的话,h_output应该是小于0的啊,加上负号之后就成正值了,当到达设定的距离之后,h_outpu不为零,小车怎么会停下来呢

      发布在 OpenMV Cam
      H
      h4rl