V-REP通过C++程序控制仿真

v-rep介绍

v-rep是一个机器人仿真平台,具有大量的模块和良好的架构,适合做原型验证,算法开发等工作。最重要的是,它的教育版本是完全开源的。具体的中文介绍
https://blog.csdn.net/weixin_39901416/article/details/78898266
官网主页:
http://www.coppeliarobotics.com/

前置工作

windows版下载地址:
http://www.coppeliarobotics.com/downloads.html
下载速度较慢,可以下载我上传的版本
https://download.csdn.net/download/iamqianrenzhan/11055344

如何在c++中和仿真环境通信

1.remoteApi库编译

在安装目录 V-REP3\V-REP_PRO_EDU\programming\remoteApiBindings\lib下用 vs2015 打开remoteApiSharedLib-64工程,进行编译,编译过程中报错

warning LNK4042: 对象被多次指定;已忽略多余的指定

无法解析的外部符号

这时按照 https://blog.csdn.net/gupar/article/details/52860794
中做法,在工程属性 :C/C++ >> 输出文件 >>对象文件名 把 $(IntDir) 修改为: $(IntDir)%(RelativeDir)
编译成功后会生成remoteApi.dll和remoteApiSharedLib-64.lib,这两个文件在接下来会用到。
dll文件所在路径加入环境变量PATH。

2.仿真开启

打开v-rep软件,把ABB IRB 140.ttm拖到仿真界面
在这里插入图片描述
双击脚本图标,弹出脚本编辑框,在function sysCall_init() 下第一行添加
在这里插入图片描述

simExtRemoteApiStart(3000)

3000代表端口号

然后开启仿真(一定要先开启仿真再启动c++控制程序)。

3.C++代码控制仿真

新建空白工程,设置包含文件路径和刚才生成的库文件路径

添加预处理

WIN32
NDEBUG
_CONSOLE
NON_MATLAB_PARSING
MAX_EXT_API_CONNECTIONS=255zasda

在代码文件中添加如下代码:

#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(Adresse, 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;
}

运行程序,可以看到仿真界面中的机械臂安装发送的指令运动

  • 7
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

仟人斩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值