CoppeliaSim Remote API 实操

QT5 端

1.lib文件

打开路径 C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu\programming\remoteApiBindings\lib
在这里插入图片描述
打开QT工程文件 remoteApiSharedLib.pro, release 编译后,将release文件中的以下文件拷贝出来
在这里插入图片描述
放在remoteAPI文件夹中(也可以是其它文件夹):
在这里插入图片描述

2.QT工程准备

QT5 新建工程, 在pro文件中添加:

win32: LIBS += -L'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/remoteApi/' -lremoteApi
INCLUDEPATH += 'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/common'
DEPENDPATH += 'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/common'

INCLUDEPATH += 'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/include'
DEPENDPATH += 'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/include'

INCLUDEPATH += 'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/remoteApi'
DEPENDPATH += 'C:/Program Files/CoppeliaRobotics/CoppeliaSimEdu/programming/remoteApi'

DEFINES += NON_MATLAB_PARSING
DEFINES += MAX_EXT_API_CONNECTIONS=255

3.CoppeliaSim准备

打开CoppeliaSim,从模型库中拖入ABB IRB140模型,在sysCall_init() 中添加

simExtRemoteApiStart(3000)

simRemoteApi.start(3000, 1300, false, false)

老版本的Vrep里有个函数是simExtRemoteApiStart(3000),代表打开19999这个端口。现在在CoppeliaSim的帮助文档中已经找不到了,但是仍可以使用。
新的启用服务器的函数为:
Lua synopsis
simRemoteApi.start(number portNumber,number maxPacketSize=1300,Boolean debug=false,Boolean preEnableTrigger=false)
Lua parameters
portNumber: port where to install the server service. Ports above 20000 are preferred. Negative port numbers can be specified in order to use shared memory, instead of socket communication.
maxPacketSize: the maximum size of a socket send-packet. Make sure to keep the value at 1300, unless the client side has a different setting.
debug: if true, a window will display the data traffic on that port.
preEnableTrigger: if true, the server service will be pre-enabled for synchronous trigger signals from the client.

4.测试通信

QT main 函数中添加

#include "mainwindow.h"
#include <QApplication>

#include <QtDebug>

extern "C" {
#include "extApi.h"
#include "extApiPlatform.h"
}

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  MainWindow w;
  w.show();

  int clientID = simxStart("127.0.0.1", 3000, true, true, 5000, 5);
  if (clientID != -1)
  {
     qDebug() << "success";
  }
  else
  {
      qDebug() << "error";
  }
  simxStartSimulation(clientID, simx_opmode_oneshot);
  simxFinish(clientID);

  return a.exec();
}

运行CoppeliaSim仿真,运行QT,若连接成功,则打印success。

QT端运行可能出现

[LspTrace]ReadAccConfig returns false!

解决办法:

  1. 以管理员身份运行命令符窗口。
  2. 输入netsh winsock reset,然后按下回车键。
  3. 出现提示,重启电脑即可。

VS2017端

1.lib文件

打开路径 C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu\programming\remoteApiBindings\lib
在这里插入图片描述
使用VS2017打开remoteApiSharedLib-64.vcxproj工程, release编译,提示错误:

无法解析的外部符号

解决办法:
在工程属性 中:C/C++ >> 输出文件 >>对象文件名 把 $(IntDir) 修改为: $(IntDir)%(RelativeDir)
编译成功后会生成remoteApi.dll和remoteApiSharedLib-64.lib。
将dll文件路径添加到系统变量中,重启电脑。
在这里插入图片描述

2. VS2017配置

  1. 新建工程

  2. 进入属性管理器,菜单栏->视图->其他窗口->属性管理器,右击Debug|x64,新建属性表,这是为了以后新建工程直接复制属性表,无需再重新一步步操作了。

  3. 打开属性表,在VC++目录的库目录中添加remoteApiSharedLib-64.lib文件所在的目录

  4. 在C/C++ 常规 附加包含目录中添加三个目录
    在这里插入图片描述

  5. 在预处理器的预处理器定义中添加以下内容

    NON_MATLAB_PARSING
    MAX_EXT_API_CONNECTIONS=255
    

    在这里插入图片描述

3.CoppeliaSim

配置同QT

4.测试通讯

VS main 文件如下

#include "pch.h"
#include <stdio.h>
#include <stdlib.h>

using namespace std;
extern "C" {
#include "extApi.h"
#include "extApiPlatform.h"
}

int main() {
  int clientID = simxStart("127.0.0.1", 3000, true, true, 5000, 5);

  if (clientID != -1) {
    printf("success");
  } else {
    printf("error");
  }
  simxStartSimulation(clientID, simx_opmode_oneshot);
  simxStopSimulation(clientID, simx_opmode_oneshot);
  simxFinish(clientID);
  return 0;
}

启动CoppeliaSim仿真,运行VS,窗口print出success则连接成功
感谢以下博文对我的帮助

V-rep与VS2017 C++通信环境配置,远程操控机械臂 http://www.luyixian.cn/news_show_187594.aspx
V-REP运动学仿真笔记(一)QT通过REMOTEAPI的交互 http://www.freesion.com/article/6532188633/
Qt 出现ReadAccConfig returns false!解决方法 https://blog.csdn.net/zxl_1996/article/details/86333945
V-REP通过C++程序控制仿真 https://blog.csdn.net/iamqianrenzhan/article/details/88777469

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值