#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <process.h>
#include <Windows.h>
#include <time.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
extern "C" {
#include "extApi.h"
}
using namespace std;
using namespace cv;
int main()
{
//开始连接
int clientID = simxStart("127.0.0.1", 3000, true, true, 2000, 5);
if (clientID != -1)
{
printf("V-rep connect success\r\n");
}
else
{
printf("connect error\r\n");
}
//开启仿真
simxStartSimulation(clientID, simx_opmode_oneshot);
printf("StartSimulation\r\n");
int IRB140;//机械臂句柄
simxInt camera;//视觉传感器句柄
float position[3] = { 0,0,0 };
float positionmove[3] = { 0,0,0 };
float orientation[3] = { 0,0,0 };
float orientationmove[3] = { 0,0,0 };
simxInt resolution[2];
simxUChar * image = 0;
simxGetObjectHandle(clientID, "Vision_sensor", &camera, simx_opmode_blocking);//第二个参数要与V-rep文件中的命名一直
printf("simxGetObjectHandle1\r\n");
simxGetObjectHandle(clientID, "IRB140_manipulationSphere", &IRB140, simx_opmode_blocking);//使用阻塞模式
printf("simxGetObjectHandle2\r\n");
simxGetVisionSensorImage(clientID, camera, resolution, &image, 0, simx_opmode_blocking);
for (int i = 0; i < 14; i++)
{
simxGetVisionSensorImage(clientID, camera, resolution, &image, 0, simx_opmode_blocking);
Mat channel(resolution[0], resolution[1], CV_8UC3, image);//chanel里存放了图片的数据
//读回来的图像数据是垂直翻转的,问题应该是在cvMat 和 v-rep 垂直坐标轴的方向相反,flip一下就正常了
flip(channel, channel, 0);
//读回来的图像数据时rgb通道分布的,而cvMat 默认bgr
cvtColor(channel, channel, COLOR_RGB2BGR);
imshow("opencv test", channel);
waitKey(10);
switch (i)
{
case 0:
imwrite("test1.jpg", channel);
break;
case 1:
imwrite("test2.jpg", channel);
break;
case 2:
imwrite("test3.jpg", channel);
break;
case 3:
imwrite("test4.jpg", channel);
break;
case 4:
imwrite("test5.jpg", channel);
break;
case 5:
imwrite("test6.jpg", channel);
break;
case 6:
imwrite("test7.jpg", channel);
break;
case 7:
imwrite("test8.jpg", channel);
break;
case 8:
imwrite("test9.jpg", channel);
break;
case 9:
imwrite("test10.jpg", channel);
break;
case 10:
imwrite("test11.jpg", channel);
break;
case 11:
imwrite("test12.jpg", channel);
break;
case 12:
imwrite("test13.jpg", channel);
break;
case 13:
imwrite("test14.jpg", channel);
break;
default:
break;
}
//simxGetObjectPosition(clientID, IRB140, -1, position, simx_opmode_blocking);
//printf("position (%f,%f,%f)\r\n", position[0], position[1], position[2]);
//positionmove[0] = position[0];
//positionmove[1] = position[1] ;
//positionmove[2] = position[2];
////printf("(%f,%f,%f)\r\n", positionmove[0], positionmove[1], positionmove[2]);
//simxSetObjectPosition(clientID, IRB140, -1, positionmove, simx_opmode_blocking);
simxGetObjectOrientation(clientID, IRB140, IRB140, orientation, simx_opmode_blocking);
printf("orientation(%f,%f,%f)\r\n", orientation[0], orientation[1], orientation[2]);
orientationmove[0] = orientation[0]+0.1;
orientationmove[1] = orientation[1];
orientationmove[2] = orientation[2];
//printf("(%f,%f,%f)\r\n", orientationmove[0], orientationmove[1], orientationmove[2]);
simxSetObjectOrientation(clientID, IRB140, IRB140, orientationmove, simx_opmode_blocking);
}
while (1)
{
int j;
}
simxStopSimulation(clientID, simx_opmode_oneshot);
simxFinish(clientID);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该资源是在VS2017上使用C++编写的可以通过remote API控制V-rep中的机械臂运动位置和姿态,并且可以将视觉传感器的数据读出来保存成图片,方便后期处理,VS2017与V-rep通信的配置大家可以看我的博客https://blog.csdn.net/qq_33374294/article/details/99305549
资源推荐
资源详情
资源评论
收起资源包目录
VS-Vrep-813Vrep.rar (36个子文件)
VS-Vrep-813Vrep
x64
Debug
VS-Vrep-813Vrep.ilk 1010KB
VS-Vrep-813Vrep.exe 110KB
VS-Vrep-813Vrep.pdb 940KB
.vs
VS-Vrep-813Vrep
v15
ipch
AutoPCH
2ee2101f4b63ac6a
源.ipch 112MB
.suo 36KB
Browse.VC.db 39.84MB
VS-Vrep-813Vrep
x64
Debug
源.obj 319KB
VS-Vrep-813Vrep.tlog
link.read.1.tlog 3KB
link.command.1.tlog 1KB
CL.command.1.tlog 1KB
VS-Vrep-813Vrep.lastbuildstate 224B
CL.write.1.tlog 544B
CL.read.1.tlog 44KB
link.write.1.tlog 536B
vc141.pdb 876KB
VS-Vrep-813Vrep.log 419B
vc141.idb 435KB
test11.jpg 343KB
test7.jpg 331KB
VS-Vrep-813Vrep.vcxproj 7KB
test1.jpg 266KB
VS-Vrep-813Vrep.vcxproj.filters 948B
test8.jpg 335KB
test14.jpg 336KB
test13.jpg 341KB
test4.jpg 312KB
test2.jpg 282KB
test6.jpg 324KB
test10.jpg 341KB
test3.jpg 299KB
test12.jpg 344KB
VS-Vrep-813Vrep.vcxproj.user 165B
test5.jpg 320KB
test9.jpg 337KB
源.cpp 4KB
VS-Vrep-813Vrep.sln 1KB
共 36 条
- 1
资源评论
乔慕宾
- 粉丝: 54
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功