V-rep与VS2017 C++通信环境配置,远程操控机械臂

在环境配置的过程中参考了以下博主的博客,在此表示感谢

1、V-REP通过C++程序控制仿真 :https://blog.csdn.net/iamqianrenzhan/article/details/88777469

2、v-rep 入门-VS2015 c++ 控制小车:https://blog.csdn.net/qq_25379821/article/details/81698529

为了方便大家学习,我把建立的工程也上传了,工程里可以控制机械臂的位姿,并且将视觉传感器的数据保存成图片,方便后期处理,链接:https://download.csdn.net/download/qq_33374294/11547643

首先介绍VS2017的环境配置

一、运行C:\Program Files\V-REP3\V-REP_PRO_EDU\programming\remoteApiBindings\lib目录下的remoteApiSharedLib-64.vcxproj

编译之后生成文件夹X64,在里面有文件remoteApi.dll和remoteApiSharedLib-64.lib,之后会用到

二、将remoteApi.dll所在目录添加环境变量Path

在系统属性里点击环境变量

然后在系统变量中找到Path

双击Path后,点击新建,将remoteAPI.dll文件的目录粘贴就行

三、VS2017环境配置

新建一个工程,然后打开属性页,在VC++目录的库目录中添加remoteApiSharedLib-64.lib文件所在的目录

然后在C/C++ 常规 附加包含目录中添加三个目录

之后在预处理器的预处理器定义中添加以下内容

再将输出文件的对象文件名改为$(IntDir)%(RelativeDir)

之后在链接器里的输入 附加依赖项中添加remoteApiSharedLib-64.lib

完成以上操作后,VS2017的环境便配置好了

三、VS2017 C++控制 V-REP机械臂

C++代码

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
extern "C" {
#include "extApi.h"
}

int main()
{
	int Port = 3000;
	int PositionControlHandle;
	//simxChar* Adresse = "127.0.0.1";
	float position[3];
	float positionmove[3];
	//智能制造单元控制系统 Intelligent manufacturing unit control system
	//imucs
	int clientID = simxStart("127.0.0.1", Port, true, true, 2000, 5);

	if (clientID != -1)
	{
		printf("V-rep connected.");
		int count = 0;
		//extApi_sleepMs(300);
		while (simxGetConnectionId(clientID) != -1)
		{
			count++;
			simxGetObjectHandle(clientID, "IRB140_manipulationSphere", &PositionControlHandle, simx_opmode_oneshot);
			simxGetObjectPosition(clientID, PositionControlHandle, -1, position, simx_opmode_oneshot);
			positionmove[0] = position[0];
			positionmove[1] = position[1] + 0.01* sin(count / 10.0);
			positionmove[2] = position[2];
			simxSetObjectPosition(clientID, PositionControlHandle, -1, positionmove, simx_opmode_oneshot);
			printf("(%f,%f,%f)\r\n", position[0], position[1], position[2]);
		}

		simxFinish(clientID);
	}
	else {
		printf("V-rep can't be connected.");
		//extApi_sleepMs(300);
	}

	return 0;
}

在V-rep的scene里添加ABB的IRB140机械臂,然后双击它的脚本,打开后在第一行添加simExtRemoteApiStart(3000)

然后先运行V-rep仿真,再编译VS2017,即可看到VREP里的机械臂运动

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章