Esempio n. 1
0
def runAction(actNum):
    '''
    运行动作组,无法发送stop停止信号
    :param actNum: 动作组名字 , 字符串类型
    :param times:  运行次数
    :return:
    '''
    global runningAction
    global stopRunning
    global online_action_times
    if actNum is None:
        return
    hwaxNum = "/home/pi/human_code/ActionGroups/" + actNum + ".hwax"
    actNum = "/home/pi/human_code/ActionGroups/" + actNum + ".d6a"

    if os.path.exists(hwaxNum) is True:
        if runningAction is False:
            runningAction = True
            ssc.portWrite()
            hwax = HWAX(hwaxNum, ssc.serialHandle)
            hwax.reset()
            while True:
                if stopRunning is True:
                    stopRunning = False
                    print('stop')
                    break
                ret = hwax.next()
                if ret is None:
                    hwax.reset()
                    break
            hwax.close()
            runningAction = False

    elif os.path.exists(actNum) is True:
        if runningAction is False:

            runningAction = True
            ag = sql.connect(actNum)
            cu = ag.cursor()
            cu.execute("select * from ActionGroup")
            while True:

                act = cu.fetchone()
                if stopRunning is True:
                    stopRunning = False
                    print('stop')
                    break
                if act is not None:
                    for i in range(0, len(act) - 2, 1):
                        serial_setServo(i + 1, act[2 + i], act[1])
                    time.sleep(float(act[1]) / 1000.0)
                else:  # 运行完才退出
                    break
            runningAction = False

            cu.close()
            ag.close()
    else:
        runningAction = False
        print("未能找到动作组文件")
Esempio n. 2
0
def run_ActionGroup(actNum, times):
    '''
    运行动作组
    :param actNum:动作组文件名
    :param times:运行次数,次数为0时表示无限循环,无法停止
    :return:无
    '''
    global runningAction
    global stopRunning
    global action_group_finish

    d6aNum = "/home/pi/human_code/ActionGroups/" + actNum + ".d6a"
    hwaxNum = "/home/pi/human_code/ActionGroups/" + actNum + ".hwax"

    stopRunning = False
    if action_group_finish:
        if times == 0:  #对传入次数进行分类处理
            times = 1
            state = False
        else:
            times = abs(times)
            state = True
        if os.path.exists(hwaxNum) is True:
            ssc.portWrite()
            hwax = HWAX(hwaxNum, ssc.serialHandle)
            hwax.reset()
            while times:
                if state:
                    times -= 1
                if runningAction is False:
                    runningAction = True
                    while True:
                        if stopRunning is True:
                            runningAction = False
                            break
                        ret = hwax.next()
                        if ret is None:
                            runningAction = False
                            hwax.reset()
                            break
                else:
                    break

        elif os.path.exists(d6aNum) is True:  # 如果存在该动作组
            while times:
                if state:
                    times -= 1
                ag = sql.connect(d6aNum)  # 打开数据库actNum
                cu = ag.cursor()  # 定义了一个游标
                cu.execute("select * from ActionGroup")  # 查询
                if runningAction is False:  # 没有动作组在运行
                    runningAction = True
                    while True:
                        if stopRunning is True:
                            runningAction = False
                            cu.close()  # 关闭一个数据库链接
                            ag.close()  # 游标关闭
                            break
                        act = cu.fetchone()  # 返回列表中的第一项,再次使用,则返回第二项,依次下去
                        if act is not None:
                            for i in range(0, len(act) - 2, 1):
                                serial_setServo(i + 1, act[2 + i], act[1])
                            time.sleep(float(act[1]) / 1000.0)
                        else:
                            runningAction = False
                            cu.close()
                            ag.close()
                            break
                else:
                    break
        else:
            runningAction = False
            print("未能找到动作组文件")
Esempio n. 3
0
def run_ActionGroup(actNum, times):
    '''
    Run the action group
    :param actNum:Action group filename
    :param times:The times of running. when the number of times is 0, it means infinite loop, which cannot be stopped
    :return:无
    '''
    global runningAction
    global stopRunning
    global stop

    if not stopRunning:
        stop = False
        write_data(stop)
        d6aNum = "/home/pi/human_code/ActionGroups/" + actNum + ".d6a"
        hwaxNum = "/home/pi/human_code/ActionGroups/" + actNum + ".hwax"

        if times == 0:  #Classify the times of imcoming
            times = 1
            state = False
        else:
            times = abs(times)
            state = True
        if os.path.exists(hwaxNum) is True:
            ssc.portWrite()
            hwax = HWAX(hwaxNum, ssc.serialHandle)
            hwax.reset()
            while times:
                if state:
                    times -= 1
                if stop is False:  #Action group stop flag bit is not
                    if runningAction is False:
                        runningAction = True
                        while True:
                            if stopRunning is True:
                                stop = True
                                write_data(stop)
                                runningAction = False
                                break
                            ret = hwax.next()
                            if ret is None:
                                runningAction = False
                                hwax.reset()
                                break
                    else:
                        break
                else:
                    stopRunning = False
                    break

        elif os.path.exists(d6aNum) is True:  # If the action group exists
            while times:
                if state:
                    times -= 1
                if stop is False:  #Action group stop flag bit is not
                    ag = sql.connect(d6aNum)  # Open the database actNum
                    cu = ag.cursor()  # Defines a cursor
                    cu.execute("select * from ActionGroup")  # Inquire
                    if runningAction is False:  # None of action groups are running
                        runningAction = True
                        while True:
                            if stopRunning is True:
                                stop = True
                                write_data(stop)
                                runningAction = False
                                cu.close()  # Close a database link
                                ag.close()  # Close the cursor
                                break
                            act = cu.fetchone(
                            )  # Return to the first item in the list, do it again, it will return to the second item
                            if act is not None:
                                for i in range(0, len(act) - 2, 1):
                                    serial_setServo(i + 1, act[2 + i], act[1])
                                time.sleep(float(act[1]) / 1000.0)
                            else:
                                runningAction = False
                                cu.close()
                                ag.close()
                                break
                    else:
                        stopRunning = False
                        break
                else:
                    stopRunning = False
                    break
        else:
            runningAction = False
            print("The action group file could not be found")
    stop = True
    write_data(stop)
    stopRunning = False