Beispiel #1
0
#颜色识别内容
import sensor, image, time, math, pyb
from pyb import UART
from pyb import Servo

s1 = Servo(1) #P7 舵机1
s1.pulse_width(1900) #舵机1初始化到中间位置

#设置颜色识别阈值
green_threshold = (8, 20, -22, -9, -4, 19)#(22, 46, -49, -20, -33, 24)(11, 83, -43, -25, -2, 26)
white_threshold = (38, 47, -7, 7, -5, 5)
GRAYSCALE_THRESHOLD = [(13, 69)]


#发送的数据种类选择·
X_Size = 200
H_Size = 210

#找到最大的那块
def find_max(blobs):
    max_size=0
    for blob in blobs:
        if blob[2]*blob[3]>max_size:
            max_blob = blob
            max_size = blob[2]*blob[3]
    return max_blob

#限幅函数
def XianFu(Data1,Data2):
    biggest = 1500
    if(Data1>biggest):
Beispiel #2
0
laser_disable=0
laser_enable=1
uart = UART(3, 921600, timeout=50) #串口初始化定义 p4 p5
# red_threshold  =(0, 100, 17, 127, -128, 127)  # 以前
red_threshold  = (20, 68, 41, 127, -13, 54)
yellow_threshold  = red_threshold
#白天 室外 (0, 100, 24, 127, -128, 127) 曝光值 0.6
#室内 灯光 (0, 100, 17, 127, -128, 127) 曝光值 1.5
up_servo=Servo(1)  #p7 p8
down_servo=Servo(2)
up_servo_zero_position = 1500
down_servo_zero_position = 1440
#up_servo_zero_position = 1800       #向下正
#down_servo_zero_position = 1100     #向左正
up_servo.pulse_width(up_servo_zero_position)
down_servo.pulse_width(down_servo_zero_position)

kp_up = -2.6
ki_up = -0.42
kd_up = -0.43

kp_down = 3.19
ki_down = 0.46
kd_down = 0.43

#kp_down = 2.5
#ki_down = 0
#kd_down = 0

bias_down = 0.0
Beispiel #3
0
# Servo Control Example
#
# This example shows how to use your OpenMV Cam to control servos.

import time
from pyb import Servo

s1 = Servo(1)  # P7
s2 = Servo(2)  # P8

while (True):
    for i in range(1000):
        s1.pulse_width(1000 + i)
        s2.pulse_width(1999 - i)
        time.sleep(10)
    for i in range(1000):
        s1.pulse_width(1999 - i)
        s2.pulse_width(1000 + i)
        time.sleep(10)
Beispiel #4
0
s2 = Servo(2)  # P8

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=2000)
sensor.set_brightness(0)
sensor.set_contrast(0)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
clock = time.clock()

tag_families = 0
tag_families |= image.TAG16H5

s1.pulse_width(1450)

s2.pulse_width(1200)


def family_name(tag):
    if (tag.family() == image.TAG16H5):
        return "TAG16H5"


def moveservo(servo, deg):
    if servo == 1:

        s1.pulse_width(deg)

    else:
Beispiel #5
0
import gc
import sensor
import network
import usocket
import ure
import utime
import uos
import ubinascii
import uhashlib
from pyb import LED
from pyb import Servo

GREEN_LED = LED(2)
BLUE_LED = LED(3)
servo = Servo(3)  # P9
servo.pulse_width(500)

SSID = 'YOUR_SSID'
KEY =  'YOUR_KEY'
LOG_FILE = 'time.log'
AUTH_FILE = '.htpasswd'
DAY_ABBR = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
STATUS = {200:"200 OK", 404:"404 Not Found", 401:"401 Unauthorized", 501:"501 Server Error"}
TURNS = 1

# Set sensor settings
sensor.reset()
sensor.set_framesize(sensor.QQVGA)  # 160x120 resolution
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames()
Beispiel #6
0
from pyb import Servo

servo = Servo(1)
print(servo)

servo.angle(0)
servo.angle(10, 100)

servo.speed(-10)
servo.speed(10, 100)

servo.pulse_width(1500)
print(servo.pulse_width())

servo.calibration(630, 2410, 1490, 2460, 2190)
print(servo.calibration())
Beispiel #7
0
#s1.pulse_width(1000) # return motor controller to low/off throttle
while (True):
    led_control(2)
    s1.speed(120)
    pyb.delay(10)
    clock.tick()  # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot()  # Take a picture and return the image.
    img.find_edges(image.EDGE_CANNY, threshold=(40, 174))  # Find edges
    lines = img.find_lines(threshold=40)  # Find lines.
    counter = 0
    totalslope = 0
    for l in lines:
        img.draw_line(l, color=(127))  # Draw lines
    if lines:
        if (l[2] - l[0]) != 0:  # don't allow vertical lines (infinite slope)
            slope = 0
            slope = (l[3] - l[1]) / (l[2] - l[0])
            #            print ('slope')
            #            print (slope)
            if slope <= -0.5 or slope >= 0.5:  # ignore lines that are mostly horizontal (slope between -0.5 and 0.5)
                totalslope = totalslope + slope
                counter = counter + 1
        if counter != 0:
            steer_angle = 1 / (
                totalslope / counter
            )  # 1/(average slope), to compensate for the inverse slope curve
            print(steer_angle)
            #           s1.pulse_width(cruise_speed) # move forward at cruise speed
            s2.pulse_width(1500 - int(steer_angle * steering_gain))  # steer
            pyb.delay(10)
Beispiel #8
0
from pyb import Servo

servo = Servo(1)
print(servo)

servo.angle(0)
servo.angle(10, 100)

servo.speed(-10)
servo.speed(10, 100)

servo.pulse_width(1500)
print(servo.pulse_width())

servo.calibration(630, 2410, 1490, 2460, 2190)
print(servo.calibration())
# Servo Control Example
#
# This example shows how to use your OpenMV Cam to control servos.

import time
from pyb import Servo

s1 = Servo(1) # P7
s2 = Servo(2) # P8

while(True):
    for i in range(1000):
        s1.pulse_width(1000 + i)
        s2.pulse_width(1999 - i)
        time.sleep(10)
    for i in range(1000):
        s1.pulse_width(1999 - i)
        s2.pulse_width(1000 + i)
        time.sleep(10)
Beispiel #10
0
    if (x & 8) == 0: ir_led.off()
    elif (x & 8) == 8: ir_led.on()


s1 = Servo(1)  # P7 Motor
s2 = Servo(2)  # P8 Steering
print(s1.calibration())  # show throttle servo calibration
cruise_speed = 1500  # how fast should the car drive, range from 1000 to 2000
steering_gain = 800
sensor.reset()  # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE)  # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA)  # or sensor.QVGA (or others)
clock = time.clock()  # Tracks FPS.
while (True):
    led_control(2)
    s1.pulse_width(cruise_speed)  # move forward at cruise speed
    #    s1.speed(120)  # alternative way to control speed
    pyb.delay(10)
    clock.tick()  # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot()  # Take a picture and return the image.
    img.find_edges(image.EDGE_CANNY, threshold=(40, 174))  # Find edges
    lines = img.find_lines(threshold=40)  # Find lines.
    counter = 0
    totalslope = 0
    if lines:
        for l in lines:
            img.draw_line(l, color=(127))  # Draw lines
            if (l[2] -
                    l[0]) != 0:  # don't allow vertical lines (infinite slope)
                slope = 0  # reset slope
                slope = (l[3] - l[1]) / (l[2] - l[0])
Beispiel #11
0
#
# This example shows how to use your OpenMV Cam to control servos.

import micropython, time
from pyb import Servo
micropython.alloc_emergency_exception_buf(100)

s1 = Servo(1)  # P7

#s1.calibration(1000, 1500, 1100)
s1.calibration(640, 2420, 1500)
s1.speed(-100)

time.sleep(2000)

print(s1.pulse_width())
print(s1.calibration())

s1.speed(-14)
time.sleep(5000)
s1.speed(-13)
time.sleep(5000)

i = -20
while (i < 100):
    print(i)
    s1.speed(i)
    print(s1.pulse_width())
    time.sleep(1000)
    i += 1