예제 #1
0
def set_menu(ser, mSerial):
    mymenu = Menu_function(ser)
    while 1:
        menu_num = input(
            "请选择:1 设置CAN波特率 2 设置透传波特率 3 清空过滤器 4 初始化 5 测试CAN波特率 6 退出\r\n")
        menu_num = menu_num.replace('\r', '').replace('\n', '').strip()
        if menu_num == '1':
            print("    ", mymenu.set_baud())
        elif menu_num == '2':
            print("    ", mymenu.set_uart())
        elif menu_num == '3':
            print("    ", mymenu.clear_filter())
        elif menu_num == '4':
            print("    ", mymenu.init_sniffer())
        elif menu_num == '5':
            print("    ", mymenu.scan_can_baud(mSerial))
            getch = _Getch()

            while 1:
                ch = getch()
                if ord(ch) == ord('q'):
                    mSerial.stop_recv()
                    break
                elif ord(ch) == ord('a'):
                    mSerial.stop_recv()
                    print("    ", mymenu.auto_set_can_baud(0))
                    mSerial.start_recv()
                elif ord(ch) == ord('s'):
                    mSerial.stop_recv()
                    print("    ", mymenu.auto_set_can_baud(1))
                    mSerial.start_recv()
            del getch
        else:
            break
    opt_mus[:, t], opt_Sigmas[:, :, t] = ekf_update(
        arm.dynamics,
        lambda x: arm.observe(s, x=x),
        Q,
        R,
        opt_mus[:, t - 1],
        opt_Sigmas[:, :, t - 1],
        opt_ctrls[:, t - 1],
        None,
    )

arm.draw_trajectory(opt_X, opt_mus, opt_Sigmas, color=np.array((0.0, 1.0, 0.0, 0.2)))


drawRobot = opt_X
getch = _Getch._Getch()
t = 0
while True:
    c = getch()
    print c
    if c == "x":
        break
    elif ord(c) == 3 or ord(c) == 4:
        exit(0)
    elif c == "n":
        print "drawRobot = X"
        drawRobot = X
    elif c == "m":
        drawRobot = opt_states
    elif c == "," or c == "<":
        t = t - 1
예제 #3
0
	global direction, wasDisplayed
	if wasDisplayed:
		if newDirection != direction and (newDirection.x != -direction.x or newDirection.y != -direction.y):
			direction = newDirection
			wasDisplayed = False
	
	

if __name__ == "__main__":
	
	setTarget()
	move()

	# Use Keyboard Arrows
	from _Getch import _Getch
	getch = _Getch()
	print "To end the game press <q>"
	while running:
		try:
			key = ord(getch())
			if key == 27: #ESC
				key = ord(getch())
				if key == 91:
					key = ord(getch())
					if key == 65: #Up arrow
						changeDirection(DIR_U)
						#setPixel(0,1,True)
					if key == 66: #Down arrow
						changeDirection(DIR_D)
						#setPixel(0,1,False)
					elif key == 67: #right arrow
opt_ctrls = np.mat(opt_ctrls)

for t in xrange(1, T):
    opt_X[:, t] = localizer.dynamics(opt_X[:, t - 1], opt_ctrls[:, t - 1])
    opt_mus[:, t], opt_Sigmas[:, :, t] = ekf_update(
        localizer.dynamics, lambda x: localizer.observe(s, x=x), Q, R,
        opt_mus[:, t - 1], opt_Sigmas[:, :, t - 1], opt_ctrls[:, t - 1], None)

localizer.draw_trajectory(opt_X,
                          opt_mus,
                          opt_Sigmas,
                          color=np.array((0.0, 1.0, 0.0, 0.2)))

drawRobot = opt_X

getch = _Getch._Getch()
t = 0
while True:
    c = getch()
    print c
    if c == 'x':
        break
    elif ord(c) == 3 or ord(c) == 4:
        exit(0)
    elif c == 'n':
        print 'drawRobot = X'
        drawRobot = X
    elif c == 'm':
        drawRobot = opt_X
    elif c == ',' or c == '<':
        t = t - 1
예제 #5
0
    global direction, wasDisplayed
    if wasDisplayed:
        if newDirection != direction and (newDirection.x != -direction.x
                                          or newDirection.y != -direction.y):
            direction = newDirection
            wasDisplayed = False


if __name__ == "__main__":

    setTarget()
    move()

    # Use Keyboard Arrows
    from _Getch import _Getch
    getch = _Getch()
    print "To end the game press <q>"
    while running:
        try:
            key = ord(getch())
            if key == 27:  #ESC
                key = ord(getch())
                if key == 91:
                    key = ord(getch())
                    if key == 65:  #Up arrow
                        changeDirection(DIR_U)
                        #setPixel(0,1,True)
                    if key == 66:  #Down arrow
                        changeDirection(DIR_D)
                        #setPixel(0,1,False)
                    elif key == 67:  #right arrow
예제 #6
0
파일: my_cmd.py 프로젝트: hsp86/my_cmd
def get_cmd_input():
    '''本函数完成接收用户的输入并返回输入的字符,支持tab搜索已有命令,tab循环显示搜索结果,上下键浏览历史命令'''
    from _Getch import _Getch
    getch = _Getch()
    cmd = ""
    search_res = []  # 用于存储搜索结果
    search_res_num = 0  # 搜索到的项数
    display_num = 0  # 用于指示当前tab后显示的搜索结果的索引;当输入一个tab后清0
    sys.stdout.write(config.prompt_header)  # 显示提示头
    ch = getch()
    while ch != config.cmd_end:  # enter键完成命令输入结束符可在config中配置
        if ch == "\t":  # tab键
            if display_num == 0:  # 若没搜索过就重新搜索
                search_res_num, search_res = fuzzy_search(
                    config.cmd_name_list, cmd)  # 模糊搜索cmd的项
            # 显示搜索到的第search_res_num个,并设置到cmd
            if search_res_num > 0:  # 搜索到的结果大于0才重新显示,否则不修改cmd和显示
                if search_res_num <= display_num:
                    display_num = 0  # 若达到最后一个就回到0重新开始显示
                del_display(cmd)  # 删除原显示字符
                cmd = search_res[display_num]  # 更改cmd
                sys.stdout.write(cmd)
            display_num = display_num + 1  # 自增一,准备下次tab显示的位置,即使没搜索到也自增一,防止下次连续tab再次搜索
        else:
            search_res = []  # 输入非tab后清除之前的搜索结果
            search_res_num = 0
            display_num = 0  # 并且清除显示位置
            # print "\b" + ch, # 这样行末始终有一个空格,改用下面的sys.stdout.write
            if ch == "\b":  # 删除键
                if len(cmd) > 0:
                    sys.stdout.write("\b" + " " + "\b")  # 删除显示,用空格覆盖要删除的字符
                    cmd = cmd[0:-1]  # 从cmd中删除最后一个字符
            elif ord(ch) == 224:  # 上下左右键
                ch = getch()
                # print ord(ch)
                if ord(ch) == 72:  # 上键
                    # print u"上键"
                    if len(cmd_history) > 0:  # 有历史命令才能处理
                        cmd_history.insert(0, cmd)  # 把当前命令放入命令历史首
                        del_display(cmd)  # 清除显示
                        cmd = cmd_history.pop(-1)  # 从cmd_history末尾取出前一条历史命令
                        sys.stdout.write(cmd)  # 显示前一条历史命令
                elif ord(ch) == 80:  # 下键
                    # print u"下键"
                    if len(cmd_history) > 0:  # 有历史命令才能处理
                        cmd_history.append(cmd)  # 把当前命令放入命令历史尾
                        del_display(cmd)  # 清除显示
                        cmd = cmd_history.pop(0)  # 从cmd_history首取出相对最旧一条历史命令
                        sys.stdout.write(cmd)  # 显示最旧一条历史命令
                # elif ord(ch) == 75: # 左键。暂不处理
                # print u"左键"
                # sys.stdout.write("\b")
                # elif ord(ch) == 77: # 右键。暂不处理
                #     print u"右键"
                # sys.stdout.write(chr(0x27)) # 输入右移ASCII,39(0x27)有错
            else:  # 其它按键输出打印并存入cmd
                sys.stdout.write(ch)
                cmd = cmd + ch
        ch = getch()
        # print ord(ch)
    cmd_history.append(cmd)  # 存入命令历史尾
    # print search_res_num # 显示最后输入的tab键次数
    print "\n",  # 输出换行,方便之后输出其它信息
    return cmd