【openmv】水中机器人大赛输油管道组国一代码&讲解

一 总体设计

整体

使用2个openmv和1个stm32用于图像处理和控制
使用水下机器人平台以及平台自带的螺旋桨(好像我们用过之后就出规则不让用了)

程序设计思路

1个openmv用于巡线,1个openmv用于找点并使用蜂鸣器报点(也可以合在一起)
stm32用于控制电机和舵机(螺旋桨和尾巴)

本篇讲解

主要讲解openmv程序,openmv代码开源,欢迎一起讨论学习。

二 巡线部分功能设计

主要完成功能

1.使用openmv自带的线性回归函数get_regression()
2.返回角度和中点
3.将结果通过串口通信发送给stm32(如果没有找到线,发送0xff,0xfa

注意事项

1.这里寻找的是白色线,需要寻找黑色线请反转阈值
2.在你的环境使用的时候需要修改阈值THRESHOLD = (190, 255)(关于修改阈值的方法,详细请看星瞳科技的教程)
3.对一些干扰比较敏感

程序

# 快速线性回归(巡线)例程

#

# 这个例子展示了如何在OpenMV Cam上使用get_regression()方法来获得

# ROI的线性回归。 使用这种方法,你可以轻松地建立一个机器人,它可以

# 跟踪所有指向相同的总方向但实际上没有连接的线。 在线路上使用

# find_blobs(),以便更好地过滤选项和控制。

#

# 这被称为快速线性回归,因为我们使用最小二乘法来拟合线。然而,这种方法

# 对于任何具有很多(或者甚至是任何)异常点的图像都是不好的,

# 这会破坏线条拟合.

import sensor, image, time
from pyb import UART
from pyb import LED
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)

#       _____________________________________________________________________________
sensor.set_auto_gain(True)
#sensor.set_auto_gain(False)
#sensor.set_auto_whitebal(True)
sensor.set_auto_whitebal(False)
#a = -20#17
#sensor.set_auto_whitebal(False, rgb_gain_db = (0.52073+a,0.105657+a,2.038398+a))
#设置阈值,(200,255)检测黑色线


THRESHOLD = (190, 255) # Grayscale threshold for dark things...

#设置是否使用img.binary()函数进行图像分割


BINARY_VISIBLE = True # Does binary first so you can see what the linear regression


                      # is being run on... might lower FPS though.

#           _________________________________________________________________________________


sensor.skip_frames(time = 2000)


clock = time.clock()
uart = UART(3, 115200)
red_led   = LED(1)
green_led = LED(2)
blue_led  = LED(3)
ir_led    = LED(4)

while(True):


    clock.tick()
    img = sensor.snapshot().binary([THRESHOLD]) if BINARY_VISIBLE else sensor.snapshot()
    img.draw_rectangle(130, 85, 30, 35, color = (0, 0, 0), thickness = 2, fill = True)
    # Returns a line object similar to line objects returned by find_lines() and
    # find_line_segments(). You have x1(), y1(), x2(), y2(), length(),
    # theta() (rotation in degrees), rho(), and magnitude().
    #
    # magnitude() represents how well the linear regression worked. It goes from
    # (0, INF] where 0 is returned for a circle. The more linear the
    # scene is the higher the magnitude.
    #函数返回回归后的线段对象line,有x1(), y1(), x2(), y2(), length(), theta(), rho(), magnitude()参数。
    #x1 y1 x2 y2分别代表线段的两个顶点坐标,length是线段长度,theta是线段的角度。
    #magnitude表示线性回归的效果,它是(0,+∞)范围内的一个数字,其中0代表一个圆。如果场景线性回归的越好,这个值越大。
    line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD])
    if 
  • 11
    点赞
  • 77
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值