打开vrep,在上方操作栏找到help选项打开,选择help topics。此时浏览器打开了vrep的操作手册user manual。

在user manual左侧目录中找到writing code in and around V-REP,子目录选择V-REP API framework,子目录选择Remote API,从Enabling the Remote API - client side开始学习。

To use the remote API functionality in your C/C++ application, just include following C-language files in your project:
extApi.h
extApi.c
extApiPlatform.h (contains platform specific code)
extApiPlatform.c (contains platform specific code)
Above files are located in V-REP's installation directory, under programming/remoteApi.
把vrep安装目录内的programming/remoteApi里面所有头文件和源文件复制到C++工程里。

Make sure you have defined NON_MATLAB_PARSING and MAX_EXT_API_CONNECTIONS=255 (and optionally DO_NOT_USE_SHARED_MEMORY) as a preprocessor definition.
预处理器定义NON_MATLAB_PARSING和MAX_EXT_API_CONNECTIONS=255。如果编译器有报错关于shared memory,那么还要定义DO_NOT_USE_SHARED_MEMORY,然后在工程中写一个空的main测试error,根据编译器的错误提示修改。

To enable the remote API on the client side (i.e. your application), call simxStart. See the bubbleRobClient project in the programming directory for an example. This page lists and describes all supported C/C++ remote API functions. V-REP remote API functions can easily be recognized from their "simx"-prefix.
调用函数simxStart以启动远程API。但目前做不到,点击这个函数可以查看其使用方法。vrep函数的特点就是都带有simx前缀。

simxStart:
Description
Starts a communication thread with the server (i.e. V-REP). A same client may start several communication threads (but only one communication thread for a given IP and port). This should be the very first remote API function called on the client side. Make sure to start an appropriate remote API server service on the server side, that will wait for a connection. See also simxFinish. This is a remote API helper function.
启动与服务器的通信线程(即V-REP)。 同一客户端可以启动多个通信线程(但只有一个通信线程用于给定的IP和端口)。 这应该是客户端调用的第一个远程API函数。 确保在服务器端启动适当的远程API服务器服务,该服务将等待连接。 另见simxFinish。 这是一个远程API辅助函数。
C synopsis
simxInt simxStart(const simxChar* connectionAddress, simxInt connectionPort, simxUChar waitUntilConnected, simxUChar doNotReconnectOnceDisconnected, simxInt timeOutInMs,simxInt commThreadCycleInMs)
调用方式,基本上只需要关注connectionPort,这个是自定义的参数(端口号)。
C parameters
connectionAddress: the ip address where the server is located (i.e. V-REP)
直接使用字符串“127.0.0.1”即可
connectionPort: the port number where to connect. Specify a negative port number in order to use shared memory, instead of socket communication.
端口号在哪里连接。 指定负端口号以使用共享内存,而不是套接字通信。端口号是自定义的。
waitUntilConnected: if different from zero, then the function blocks until connected (or timed out).
若非零,则功能将阻塞直到连接建立或超时。设置为true或1。
doNotReconnectOnceDisconnected: if different from zero, then the communication thread will not attempt a second connection if a connection was lost.
若非零,那么如果连接丢失,通信线程将不会尝试第二次连接。设置为true或1。
timeOutInMs:
if positive: the connection time-out in milliseconds for the first connection attempt. In that case, the time-out for blocking function calls is 5000 milliseconds.
if negative: its positive value is the time-out for blocking function calls. In that case, the connection time-out for the first connection attempt is 5000 milliseconds.
若为正值:第一次连接尝试的连接超时(以毫秒为单位)。 在这种情况下,阻塞函数调用的超时为5000毫秒。
若为负值:它的绝对值是阻塞函数调用的超时时间。 在这种情况下,第一次连接尝试的连接超时为5000毫秒。
设置为-5000到5000内任意值。
commThreadCycleInMs: indicates how often data packets are sent back and forth. Reducing this number improves responsiveness, and a default value of 5 is recommended.
表示数据包来回发送的频率。 减少此数字可提高响应速度,建议默认值为5。
C return value
the client ID, or -1 if the connection to the server was not possible (i.e. a timeout was reached). A call to simxStart should always be followed at the end with a call to simxFinish if simxStart didn't return -1.
客户端ID,如果无法连接到服务器,则返回-1(即达到超时)。 如果simxStart没有返回-1,则应始终在调用simxFinish时调用simxStart。

返回,继续学习Enabling the Remote API - server side。只需关注一个内置函数simRemoteApi.start。调用方式也很简单,直接调用,并且只要一个参数,就是自定义的端口号。使用vrep自带场景就可以测试,这里使用tutorials\BubbleRob里面的bubbleRob.ttt,建议建立一个副本。打开这个场景,在左侧模块目录中双击bubbleRob右侧第一个小图标,在空白行调用这个函数simRemoteApi.start(20172)。(20172是自定义的,建议端口号设为20000以上的值以免与其它进程冲突)

编写测试程序,直接写在主函数所在源文件:

#include<iostream>
#include"extApi.h"
void main()
{   using namespace std;   int Port = 20172;   int clientID = simxStart("127.0.0.1", Port, 1, 1, 1000, 5);   if (clientID != -1)
  {
    cout << "V-rep connected.";
    simxFinish(clientID);
  }
  else
  {
    cout << "V-rep can't be connected.";
  }   cin.get();
  return;
}

测试开始时,先在vrep界面运行仿真,然后再运行c++工程。命令窗口显示V-rep connected表示测试成功。

V-REP与C++初步通信测试的更多相关文章

  1. XIII Open Cup named after E.V. Pankratiev. GP of Ukraine

    A. Automaton 后缀自动机可以得到$O(2n+1)$个状态,但是后缀自动机会拒绝接收所有不是$S$的子串的串,所以在建立后缀自动机的时候不复制节点即可得到$n+1$个状态的DFA. #inc ...

  2. 51nod算法马拉松15

    智力彻底没有了...看来再也拿不到奖金了QAQ... A B君的游戏 因为数据是9B1L,所以我们可以hash试一下数据... #include<cstdio> #include<c ...

  3. BZOJ2506: calc

    Description            给一个长度为n的非负整数序列A1,A2,…,An.现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且Ai mod p = k的值 ...

  4. BZOJ3069: [Pa2011]Hard Choice 艰难的选择

    Description Byteasar是一个很纠结的人.每次他经过Bytetown的时候都知道有至少2条不同的路径可以选择,这导致他必须花很长时间来决定走哪条路.Byteasar最近听说了Bytet ...

  5. hdu Dylans loves tree [LCA] (树链剖分)

    Dylans loves tree view code#pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...

  6. Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA/(树链剖分+数据结构) + MST

    E. Minimum spanning tree for each edge   Connected undirected weighted graph without self-loops and ...

  7. BZOJ4500: 矩阵

    Description 有一个n*m的矩阵,初始每个格子的权值都为0,可以对矩阵执行两种操作: 1. 选择一行, 该行每个格子的权值加1或减1. 2. 选择一列, 该列每个格子的权值加1或减1. 现在 ...

  8. BZOJ1391: [Ceoi2008]order

    Description 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成. 现在给出这些参数,求最大利润 Inpu ...

  9. uva 10622

    http://vjudge.net/contest/140673#problem/H 求某个数字(最大到10^9,可为负值)写成完全p次方数的指数p是多少 分析: 先进行唯一分解,之后p整除各个素因子 ...

随机推荐

  1. 矩形覆盖(JAVA)

    矩形覆盖 题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 思路:最初看到这题,只能通过画图归纳来寻找规律. ...

  2. Actifio OnVault 8.0

  3. Unity 3D中不得不说的yield协程与消息传递

    1. 协程 在Unity 3D中,我们刚开始写脚本的时候肯定会遇到类似下面这样的需求:每隔3秒发射一个烟花.怪物死亡后20秒再复活之类的.刚开始的时候喜欢把这些东西都塞到Update里面去,就像下面这 ...

  4. 2、冒泡排序法(C语言)

    一.冒泡算法实现分析 1.假设有5个元素分别为8,6,15,9,3对其进行冒泡排序,我们需要关注的有三点如下: (1)元素个数 n: (2)需要比较的趟数 i: (3)每趟比较的次数 j: 2.它们之 ...

  5. Verilog手绘FVH信号

    Verilog手绘FVH信号 `timescale 1ns / 1ps //////////////////////////////////////////////////////////////// ...

  6. 阿里云CentOS7服务器利用LVM分区挂载磁盘全记录

    1.进入服务器后,首先利用fdisk -l来观察磁盘信息,可以看出红线标注处,有两块硬盘信息,分别是40G和300G 2.同时你也可以观察到分区信息,40G的硬盘已经分了一个区vda1,大小(Bloc ...

  7. Linux下mysql的root密码修改方法(ERROR 1054)

    #1.停止mysql数据库 /etc/init.d/mysqld stop #2.执行如下命令 mysqld_safe --user=mysql --skip-grant-tables --skip- ...

  8. JavaScript 集合对象

    1. 集合对象 1.1 Object 关于Object类型的创建和底层存储原理我在另一篇文章有说明: JavaScript 对象属性底层原理 我们知道了大多数情况下Object底层都是Hash结构,我 ...

  9. AngularJS 1.x 思维索引

    我们在这里不讨论Angular2和Angular4,因为其完全重写,其实已经不叫AngularJS了. AngularJS的缺陷: 性能问题:通过检查脏值进行数据更新,当数据不断增加时,检查的效率就不 ...

  10. LeetCode——162. Find Peak Element

    一.题目链接: https://leetcode.com/problems/find-peak-element/ 二.题目大意: 给定一个长度为N的一维数组,数组是无序的,要求找到数组中的极大值(或局 ...