软件版本:v-rep 3.5 EDU;vs 2013
1. VS新建C/C++工程,右键工程-属性-配置属性-C/C++ - 预处理器 - 预处理器定义
编辑如下:
WIN32
NDEBUG
_CONSOLE
NON_MATLAB_PARSING
MAX_EXT_API_CONNECTIONS=255zasda
DO_NOT_USE_SHARED_MEMORY
_CRT_SECURE_NO_WARNINGS
备注:如果报shared memory错误的话就添加DO_NOT_USE_SHARED_MEMORY,如果报fopen错误的话就添加_CRT_SECURE_NO_WARNINGS,否则无需添加。
2.
将C:\Program Files\V-REP3\V-REP_PRO_EDU\programming路径下的include,remoteApi,common三个文件夹下的所有头文件和源文件复制到vs安装文件夹的VC-include文件中,我的是D:\visual studio2013\VC\include。
3.在V-REP child script中添加simExtRemoteApiStart(2000),2000即为端口号,需与VS源码中对应。
4.vs中输入附录测试源码
5.先运行v-rep,然后运行vs,打印success,即通信成功,如果只运行VS,则打印error。
备注:因为配环境会出现各种问题,报各种错,需要一个一个解决,因人而异,以上教程仅供参考。而且v-rep学习资料比较少,所以还是建议潜心研读官网给的user manual。
特别鸣谢:黏基看屁屁大神的支持。
附录:
测试源码
//#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include<extApi.h>
#include<extApiPlatform.h>
#include<extApi.c>
#include<extApiPlatform.c>
//extern "C" {
//#include "extApi.h"
//}
int main()
{
int clientID = simxStart("127.0.0.1", 2000, 1, 1, 2000, 5);
//printf("clientID is %d", clientID);
//getchar();
int simRes = simxStartSimulation(clientID, simx_opmode_oneshot); //start simulation
printf("simRes is %d", simxStartSimulation);
if (clientID != -1)
{
printf("success");
getchar();
}
else
{
printf("error");
getchar();
}
return 0;
}