我最近在学习nao机器人的naoqi框架。以下是如何在其文档中访问自定义模块的示例。 (https://community.aldebaran-robotics.com/doc/1-14/dev/cpp/examples/core/helloworld/example.html#cpp-examples-helloworld)
#include <iostream>
#include <alerror/alerror.h>
#include <alcommon/alproxy.h>
int main(int argc, char* argv[]) {
if(argc != 2)
{
std::cerr << "Wrong number of arguments!" << std::endl;
std::cerr << "Usage: testhelloworld NAO_IP" << std::endl;
exit(2);
}
const std::string robotIP = argv[1];
int port = 9559;
try {
boost::shared_ptr<AL::ALProxy> testProxy
= boost::shared_ptr<AL::ALProxy>(new AL::ALProxy("HelloWorld", robotIP, port));
/** Call the sayHello method from the module using its bound name.
* Since it returns nothing, use the callVoid method.
*/
testProxy->callVoid("sayHello");
testProxy->callVoid("sayText", std::string("This is a test."));
int sentenceLength = testProxy->call<int>("sayTextAndReturnLength",
std::string("This is another test"));
std::cout << "Sentence length is " << sentenceLength << std::endl;
}
catch (const AL::ALError& e) {
std::cerr << e.what() << std::endl;
}
}
此代码使用&#34;代理&#34;调用另一个模块中定义的某些函数。并且模块在不同的进程中加载。所以我认为它必须处理RPC问题。有谁知道底层机制(如CORBA或XML-RPC)?我试图在我自己的项目中实现类似的机制。任何线索都没问题。提前谢谢!