API C++ in V-REP PLayer

Report crashes, strange behaviour, or apparent bugs
Post Reply
jarelias
Posts: 6
Joined: 20 Aug 2014, 05:12

API C++ in V-REP PLayer

Post by jarelias »

Hi

I'm using a remote API in C++ to control the behavior of some objects. When I run the simulation in V-REP PRO, it works fine, but in V-REP PLAYER there is a problem with the sensor reading.

It seams that function simxReadProximitySensor does not work in V-REP PLAYER. I´m using it like this (same way bubbleRobotClient):

if (simxReadProximitySensor(clientID, sensorHandle, &sensorTrigger, NULL, NULL, NULL, simx_opmode_continuous) == simx_error_noerror)

Could you tell me if there are things i need to do different in order to make it work in V-REP Player?

Thanks

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: API C++ in V-REP PLayer

Post by coppelia »

Hello,

could you tell me what V-REP version your are using? If you are not using the last one (V3.1.2), then make sure to download the last one.
Then, you should always remember that the streaming mode simx_opmode_continuous might return a value different from zero the first few times is was called. This is because it takes time for the first streaming data to reach the remote API client. This might be the difference between the player and the Pro version, since one might run a tiny little bit faster or has a different configuration.

Make sure you have understood how data streaming works with the remote API.

Cheers

jarelias
Posts: 6
Joined: 20 Aug 2014, 05:12

Re: API C++ in V-REP PLayer

Post by jarelias »

Hi again

I had the previous version before, now I have (V3.1.2) for both Pro and player. The problem remains.

In the new version i noticed some difference in the error codes and the operation modes of simxReadProximitySensor().
Now it is called:
if (simxReadProximitySensor(clientID, sensorHandle, &sensorTrigger, NULL, NULL, NULL, simx_opmode_streaming) == simx_return_ok)
{}

same way as bubbleRobClient

Now it does not work with the Pro. It returns the following error code:
simx_return_novalue_flag

Any advice to deal with this?
I don´t know if there is a VREP issue or I have to deal with it by C++ code.

Thanks

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: API C++ in V-REP PLayer

Post by coppelia »

It seems the way you use the remote API functionality is wrong.
Please show use the full code how you initialize streaming and where you read the data. If what you showed is is all, then it is wrong, and you really have to learn how the remote API works (see my link above)

Cheers

jarelias
Posts: 6
Joined: 20 Aug 2014, 05:12

Re: API C++ in V-REP PLayer

Post by jarelias »

This is the code. I deleted not relevant code. I remaind you that it was working fine in VREP Pro V3.0.5.
It was not working with Player 3.1.2, and now is not working with Pro V3.1.2.

I noticed some things changed from previous version. Maybe I´m missing something.

Meanwhile, I will give a deeper look to remote API documentation.

Thanks for your help.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include "windows.h"

extern "C" {
#include "extApi.h"
//#include "extApiCustom.h" //if you wanna use custom remote API functions! 
}


int main(int argc, char* argv[])
{
	int portNb = 0;
	int sensorHandle;
	int cylinderHandle;
	int dummyjointHandle;
	int result(0);
	float cylinder_speed;
	cylinder_speed = 5.0;

	if (argc >= 4)
	{
		portNb = atoi(argv[1]);
		sensorHandle = atoi(argv[2]);
		cylinderHandle = atoi(argv[3]);
		dummyjointHandle = atoi(argv[4]);
	}
	else
	{
		printf("Indicate all arguments'!\n");
		extApi_sleepMs(5000);
		return 0;
	}



	int clientID = simxStart((simxChar*)"127.0.0.1", portNb, true, true, 2000, 5);
	if (clientID != -1)
	{
		float motorSpeeds[2];
		while (simxGetConnectionId(clientID) != -1)
		{
			simxUChar sensorTrigger = 0;

			if (simxReadProximitySensor(clientID, sensorHandle, &sensorTrigger, NULL, NULL, NULL, simx_opmode_streaming) == simx_return_ok)
			{ // We succeeded at reading the proximity sensor

				if (sensorTrigger)
				{
					//...Do something
				}
				else
				{
					//...Do something
				}
			}


			extApi_sleepMs(5);
		}
		simxFinish(clientID);
	}

	return(0);
}

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: API C++ in V-REP PLayer

Post by coppelia »

Hi again,

can you try following:

in V-REP PRO, load the scene controlTypeExamples.ttt and run the simulation. The purple robot is controlled via the remote API in the exact same way as you try to interact with a remote API client. That works here.

in V-REP PLAYER, load the scene controlTypeExamples.ttt, but previously do not forget to copy the file bubbleRobClient.exe from the PRO version and run the simulation. That works here too.

If that doesn't work for you, then there is really something fishy.

Cheers

jarelias
Posts: 6
Joined: 20 Aug 2014, 05:12

Re: API C++ in V-REP PLayer

Post by jarelias »

Ok is working now!

However, i´m not comfortable because i don´t know what was the problem.

I just copied all my code and pasted it in the bubbleRobClient main function.

Thank you.

Post Reply