示例#1
0
def imageprocessor(event, serial_obj):
    global g_imagedata
    global g_graph
    global g_lock
    global g_steerstats

    with g_graph.as_default():
        time.sleep(1)
        while not event.is_set():
            g_lock.acquire()
            tmpimg = np.copy(g_imageData)
            g_lock.release()
            immean = tmpimg.mean()
            imvar = tmpimg.std()
            start = time.time()

            pred = model.predict(np.expand_dims(tmpimg, axis=0))
            steer_command = pred[0][0] * g_steerstats[1] + g_steerstats[0]

            if steer_command > 2000:
                steer_command = 2000
            elif steer_command < 1000:
                steer_command = 1000

            end = time.time()
            print(end - start)
            dataline = '{0}, {1}, {2}, {3}\n'.format(
                commandEnum.RUN_AUTONOMOUSLY, int(steer_command), THR_MAX, 0)
            print(dataline)
            try:
                serial_obj.write(dataline.encode('ascii'))
                serial_obj.flush()
            except:
                print("some serial problem")
示例#2
0
def imageprocessor(event):
    global g_image_data
    global g_lock
    global g_graph
    global g_steerstats
    global g_ip_thread
    global g_debug_steer_command
    global g_debug_steer_change

    with g_graph.as_default():
        time.sleep(1)
        while not event.is_set():
            g_lock.acquire()
            tmpimg = np.copy(g_image_data)
            g_lock.release()
            immean = tmpimg.mean()
            imvar = tmpimg.std()
            print('immean, imvar: {0}, {1}'.format(immean, imvar))
            start = time.time()
            pred = model.predict(np.expand_dims(tmpimg, axis=0))
            end = time.time()
            if (end - start) < .2:
                time.sleep(.2 - (end - start))
            end2 = time.time()
            steer_command = pred[0][0] * g_steerstats[1] + g_steerstats[0]
            #    !!! must have one space after comma !!!

            #            if( g_debug_steer_command > 1700 ):
            #                g_debug_steer_change = -20
            #            elif( g_debug_steer_command < 1300 ):
            #                g_debug_steer_change = 20

            #            g_debug_steer_command = g_debug_steer_command + g_debug_steer_change
            #            steer_command = g_debug_steer_command

            dataline = '{0}, {1}, {2}, {3}\n'.format(
                int(commandEnum.RUN_AUTONOMOUSLY), int(steer_command),
                int(DEFAULT_AUTONOMOUS_THROTTLE), int(0))

            #  This test is made because this thread may not know autonomous is turned off yet
            if (g_Mode_Autonomous):
                try:
                    ser.write(dataline.encode('ascii'))
                    print(dataline)
                    logging.debug('autonomous command: ' + str(dataline))

                except Exception as the_bad_news:
                    handle_exception(the_bad_news)