【Coppeliasim】利用remoteApi实现Coppeliasim与C++程序的数据通讯

在看完 https://blog.csdn.net/cxyhjl/article/details/125592295【Coppeliasim4.3】基于remoteApi的C++ 示教器操作仿真器中的UR10后,我尝试使用simxCallScriptFunction函数实现Coppeliasim与C++程序进行通讯,目前能够顺利实现C++程序向Coppeliasim脚本发送数据,但从Coppeliaisim脚本向C++程序发送数据的功能无法实现。

C++程序:

              int cnt;
             float* jointData;
             int result = simxCallScriptFunction(
               clientID,
               "LaserScanner_2D",            // the name of the associated obejct script
               sim_scripttype_childscript,      // the handle of the script
               "remoteTestPara",    // Function name
               0, 0,              // inIntCnt, inInt
               0, 0,              // inFloatCnt, inFloat
               0, 0,              // inStringCnt, inString
               0, 0,              // inBufferSize, inBuffer
               0, 0,            // outIntCnt, outInt
               &cnt, &jointData,          // outFloatCnt, outFloat  数量,关节数据
               0, 0,              // outStringCnt, outString
               0, 0,              // outBufferSize, outBuffer
               simx_opmode_buffer);

             cout<1]<

Lua脚本程序:

function remoteTestPara()

    outDataInt = {51,23}
    outDataFloat = {6.7,8.9}
    return {},outDataFloat,{},''
end

运行结果:

img

结果显示C++程序未能成功接收数据,希望各位网友能够指出代码中的错误或是提供可行方案,最终目标是C++程序能够通过调用simxCallScriptFunction函数接收Lua脚本发送的数据。
谢谢!

在代码中,您仅接收了浮点数,而没有接收整数或字符串。在remoteTestPara函数中返回的结果中包含了整数和字符串,所以在C++代码中,您需要定义变量来接收这些数据。下面是示例代码:

img