示例#1
0
def record():
    left = request.args.get('l')
    right = request.args.get('r')
    print(left, right)
    if cfg.camera_detected:
        """Video streaming route. Put this in the src attribute of an img tag."""
        #return Response(gen(cam.Camera()), mimetype='multipart/x-mixed-replace; boundary=frame')
        #frame = gen(cam.Camera())
        #frame = gen(cam.Camera())

        #while True:
        cfg.frame = gen(cam.Camera())
        if left:
            left = int(left)
            if left >= -100 and left <= 100:
                cfg.left_motor = left
                hw.motor_two_speed(cfg.left_motor)
        if right:
            right = int(right)
            if right >= -100 and right <= 100:
                cfg.right_motor = right
                hw.motor_one_speed(cfg.right_motor)

        return 'record_ok'
    else:
        return 'no video'
示例#2
0
def motor():
    left = request.args.get('l')
    right = request.args.get('r')
    cfg.joyX = request.args.get('joyX')
    recording = request.args.get('record')

    #print(recording)

    if cfg.camera_detected:
        cfg.frame = gen(cam.Camera())
        #cv2.imwrite(cfg.outputDir+cfg.currentDir+'/'+ 'test.jpg', cfg.frame)

    if recording == 'Y':
        #cfg.frame = gen(cam.Camera())
        #cv2.imwrite(cfg.outputDir+cfg.currentDir+'/'+ 'test.jpg', cfg.frame)

        cfg.recording = True
        #if cfg.cnt == 0:
        cfg.f = open(cfg.outputDir + cfg.currentDir + '/data.csv', 'a')
        cfg.fwriter = csv.writer(cfg.f)

        saveimage()

    if recording == 'N':
        cfg.recording = False
        cfg.cnt = 0
        if cfg.f != '':
            cfg.f.close()

    if left:
        left = int(left)
        if left >= -100 and left <= 100:
            cfg.left_motor = left
            hw.motor_two_speed(cfg.left_motor)
    if right:
        right = int(right)
        if right >= -100 and right <= 100:
            cfg.right_motor = right
            hw.motor_one_speed(cfg.right_motor)
    return 'ok'
示例#3
0
start_flag = False
while (True):
    k = cv2.waitKey(5)
    if k != -1:
        print(k)

    if k == ord('q'):
        break

    if k == ord('s'):
        if start_flag == False:
            start_flag = True
        else:
            start_flag = False
        print('start_flag: ', start_flag)

    if start_flag == True:
        if k == 82:  #forward
            hw.motor_one_speed(20)
            hw.motor_two_speed(20)

        if k == 83:  #rigth
            hw.motor_one_speed(15)
            hw.motor_two_speed(65)
    else:
        hw.motor_one_speed(0)
        hw.motor_two_speed(0)

hw.motor_clean()
cv2.destroyAllWindows()
示例#4
0
    if k == ord('q'):
        break

    if k == ord('s'):
        if start_flag == False:
            start_flag = True
        else:
            start_flag = False
        print('start_flag: ', start_flag)

    if start_flag == True:
        length = dc.get_distance()
        #print(length)
        if 5 < length and length < 15:
            hw.motor_one_speed(0)
            hw.motor_two_speed(0)
            print('Stop to avoid collision')
            time.sleep(0.2)
        else:
            if k == 82:  #forward
                hw.motor_one_speed(50)
                hw.motor_two_speed(50)

            if k == 81:  #left
                hw.motor_one_speed(50)
                hw.motor_two_speed(20)

            if k == 83:  #rigth
                hw.motor_one_speed(20)
                hw.motor_two_speed(50)
示例#5
0
            if cfg.recording:
               start_flag = True
            else:
               start_flag = False
               cfg.cnt = 0
            print('cfg.recording:',cfg.recording)

        #save image files and images list file   
        if cfg.recording:
            saveimage()
            print(cfg.cnt)
        
        if start_flag:
            # Left arrow: 81, Right arrow: 83, Up arrow: 82, Down arrow: 84
            if k == 81: 
                hw.motor_one_speed(cfg.maxturn_speed)
                hw.motor_two_speed(cfg.minturn_speed)
                #print('Straight')
                cfg.wheel = 1
            if k == 83: 
                hw.motor_one_speed(cfg.minturn_speed)
                hw.motor_two_speed(cfg.maxturn_speed)
                cfg.wheel = 3
            if k == 82: 
                hw.motor_one_speed(cfg.normal_speed_right)
                hw.motor_two_speed(cfg.normal_speed_left)
                cfg.wheel = 2
        
        else:
            hw.motor_one_speed(0)
            hw.motor_two_speed(0)
示例#6
0
            cfg.joyX = 100
        if cfg.joyX < -100:
            cfg.joyX = -100

        if cfg.joyX < 0:
            tempV = normal_speed - cfg.joyX
        else:
            tempV = normal_speed + cfg.joyX

        if tempV <= 100:
            overV = 0
        else:
            overV = tempV - 100
            tempV = 100

        if cfg.joyX < 0:
            hw.motor_two_speed(normal_speed - overV)
            hw.motor_one_speed(tempV)
        else:
            hw.motor_two_speed(tempV)
            hw.motor_one_speed(normal_speed - overV)
    else:
        hw.motor_one_speed(0)
        hw.motor_two_speed(0)
        cfg.joyX = 0

###c.release()
hw.motor_clean()
# close all windows
cv2.destroyAllWindows()
示例#7
0
            if cfg.recording:
                start_flag = True
            else:
                start_flag = False
                cfg.cnt = 0
            print('cfg.recording:', cfg.recording)

        #save image files and images list file
        if cfg.recording:
            saveimage()
            print(cfg.cnt)

        #avoid collision
        length = 30  #dc.get_distance()
        if 5 < length and length < 15 and start_flag:
            hw.motor_one_speed(0)
            hw.motor_two_speed(0)
            print('Stop to avoid collision')
            time.sleep(0.5)
            continue

        if start_flag:
            if cfg.joyX > 100:
                cfg.joyX = 100
            if cfg.joyX < -100:
                cfg.joyX = -100

            if cfg.joyX < 0:
                hw.motor_two_speed(normal_speed - int(normal_speed *
                                                      (-cfg.joyX) / 100))
                hw.motor_one_speed(normal_speed + int(normal_speed *