2020-08-22

在这里插入图片描述
广西●河池学院
广西高校重点实验室培训基地
系统控制与信息处理重点实验室
本篇博客来自河池学院: 无人机智控小组
写作时间: 2020年8月22日

基于openmv小车循迹的调试

import sensor, image, time

from pyb import LED

import car

from pid import PID

import sensor, image, time, math

from pyb import UART

import json

import ustruct

rho_pid = PID(p=0.4, i=0)

theta_pid = PID(p=0.001, i=0)

#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.
i=0

#初始化串口
uart = UART(3, 115200)
uart.init(115200, bits=8, parity=None, stop=1)

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
        print(theta_err)


    else:


        theta_err = line.theta()
        print(theta_err)




    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(52+output, 42-output)
        uart.write(52+output,42-output\r\n)


    else:


        car.run(-45,-45)
        # car.run(0,0)


else:


    car.run(50,-50)


    pass


#print(clock.fps())

在这里首先要调试PID和PWM,先确定好PWM的值,再调节P,先把P从小到大调试,找到一个适合的值,然后在调节I,D,慢慢去寻找其中规律,一边调试一边运行小车。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
可以使用 Java 中的 LocalDateTime 类来处理时间。 首先,我们需要将给定的时间段转换为 LocalDateTime 对象: ```java LocalDateTime start = LocalDateTime.of(2020, 11, 20, 0, 0, 0); LocalDateTime end = LocalDateTime.of(2021, 10, 9, 23, 59, 59); ``` 这里将结束时间设置为 23:59:59 是因为我们想要包含该日期的所有时间。 接下来,我们可以使用一个循环来遍历时间段中的每一天,并获取该天的开始时间和结束时间: ```java LocalDateTime current = start; while (!current.isAfter(end)) { LocalDateTime dayStart = current.withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime dayEnd = current.withHour(23).withMinute(59).withSecond(59).withNano(999999999); System.out.println("Day " + current.toLocalDate() + " starts at " + dayStart + " and ends at " + dayEnd); current = current.plusDays(1); } ``` 这里,我们使用 `withHour`、`withMinute`、`withSecond` 和 `withNano` 方法来设置每天的开始时间和结束时间。然后,我们可以使用 `plusDays` 方法来增加 `current` 对象的日期,以便遍历整个时间段。 完整代码如下: ```java import java.time.LocalDateTime; public class Main { public static void main(String[] args) { LocalDateTime start = LocalDateTime.of(2020, 11, 20, 0, 0, 0); LocalDateTime end = LocalDateTime.of(2021, 10, 9, 23, 59, 59); LocalDateTime current = start; while (!current.isAfter(end)) { LocalDateTime dayStart = current.withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime dayEnd = current.withHour(23).withMinute(59).withSecond(59).withNano(999999999); System.out.println("Day " + current.toLocalDate() + " starts at " + dayStart + " and ends at " + dayEnd); current = current.plusDays(1); } } } ``` 输出结果如下: ``` Day 2020-11-20 starts at 2020-11-20T00:00 and ends at 2020-11-20T23:59:59.999999999 Day 2020-11-21 starts at 2020-11-21T00:00 and ends at 2020-11-21T23:59:59.999999999 Day 2020-11-22 starts at 2020-11-22T00:00 and ends at 2020-11-22T23:59:59.999999999 ... Day 2021-10-07 starts at 2021-10-07T00:00 and ends at 2021-10-07T23:59:59.999999999 Day 2021-10-08 starts at 2021-10-08T00:00 and ends at 2021-10-08T23:59:59.999999999 Day 2021-10-09 starts at 2021-10-09T00:00 and ends at 2021-10-09T23:59:59.999999999 ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值