监控
所有pCall(并行/Post调用)都会返回一个函数ID。
函数可以被监控(Monitoring):
ALModule ALProxy监控:
int ALProxy::pCall("method",...); | pCall返回一个方法ID |
int ALProxy::post.method(...) | 同pCall |
ALModule::wait(ID, timeout) | 等待,直至方法ID停止超时 |
ALModule::stop(const std::string& pModuleName, int ID); | 如果您想在方法停止时有一个特定的行为,就需要在用户模块中予以运用。 |
ALModule::isRunning(int ID); | 如果方法ID在运行,为“True” |
ALModule::isRunning(functionName); | 函数名在运行时为“True”(如果若干函数共享一个名称时会很危险) |
int getMethodID(void) | 使一个方法知道自己的ID |
bool ALTaskMonitor::isRequireStop(int ID) | 如果有人要求方法ID停止时为“True” |
// C++ sample // walk and play mp3 in the same time. Stop mp3 when walk stop #include "almotionproxy.h" int IDWalk = motionProxy.post.walk(1); // walk int IDMP3 = audioout.playFile("longMusicForWalk.mp3"); // play music motionProxy.wait(ID); // wait end of walk audioout.stop(IDMP3); // stop music after walk
//C++ sample //bound method that want to know if someone wants to stop it void myModule::myMethod(void) // the method must be bound { myID = getMethodID(); while (!isRequireStop(myID)) { ... } } // if someone call mymodule.stop(myID), isRequireStop() will return true.
#python sample import os import sys import time path = `os.environ.get("AL_DIR")` home = `os.environ.get("HOME")` # import NAOqi lib if path == "None": print "the environment variable AL_DIR is not set, aborting..." sys.exit(1) else: alPath = path + "/extern/python/aldebaran" alPath = alPath.replace("~", home) alPath = alPath.replace("'", "") sys.path.append(alPath) import naoqi from naoqi import ALBroker from naoqi import ALModule from naoqi import ALProxy try: broker = ALBroker("pythonBroker","127.0.0.1",9999,"127.0.0.1",9559) time.sleep(2) IDWalk = ALMotion.post.walk(1) IDMP3 = audioout.post.playFile("longMusicForWalk.mp3"); ALMotion.wait(IDWalk,0) # 0 mean no timeout audioout.stop(IDMP3) except RuntimeError,e: exit(1)