代理
Aldebaran的模块是模组化的,不包含其它模块文件,而是要求代理(Proxy)去寻找相应的模块。如果模块不存在,就会引发一个异常。mainBroker(本地调用)和myBroker(远程调用)句法相同:
//C++ sample #include "alproxy.h" try { getProxy("ALMotion")->callVoid("walk",1) } catch(...) { //motion library is not loaded or walk function doesn't exist //or 1 is not a motion compatible parameter }
#python sample #some proxy are created by default try: motion = ALProxy("ALMotion") motion.walk(1) except RuntimeError,e: # motion library is not loaded or walk function doesn't exist # or 1 is not a motion compatible parameter
现在,假设mainBroker和myBroker可执行档没有连接在一起,但是我们想调用远程命令:
//C++ sample try { // we have to explicitly write IP and port because brokers are not connected ALPtr<ALProxy> motion(new ALProxy("ALMotion",IP,port); // pointer automatically destroyed after try block // or ALProxy *motion = new ALProxy("ALMotion",IP,port); // don't forget to delete proxy manually motion.call("walk",1); }
ALProxy(std::string moduleName) | 获得对一个模块的访问。如果是本地模块,使用本地过程调用(LPC);如果是远程模块,使用远程过程调用(RPC)。要远程访问时,代理可执行档应连接至moduleName可执行档。 |
ALProxy(std::string moduleName, std::string IP, int port) | 获得对一个模块的访问。如果是本地模块,使用LPC;如果是远程模块,使用RPC。要远程访问时,代理可执行档无需连接至“moduleName”可执行档。 |
callvoid(std::string methodName, parameter1, parameter2....) | 调用methodName。无返回值。 |
type variable = call<type>(std::string method name, parameter1, parameter2....) | 调用methodName。类型返回值。 |
int ID = pCall(std::string method name, parameter1, parameter2....) | 并行或Post方式调用methodName。非阻塞函数。返回函数ID,用来对其进行监控。 |