Page 1 of 1

Obstacle avoidance using Remote API C++

Posted: 25 Feb 2017, 08:30
by Msalmanch
Hello,

I am using C++ remote API to control Khepera III robot. The remote connection was successful. I have made a code for the robot to move and its working fine. How to code the Infrared sensor for obstacle avoidance???

Regards

Re: Obstacle avoidance using Remote API C++

Posted: 26 Feb 2017, 14:18
by coppelia
Hello,

if the remote API connection is working fine, then you can stream the data from the infrared sensors to the remote API, process the signals there, then act on the wheels. Please be more specific for a more precise answer to your question.

Cheers

Re: Obstacle avoidance using Remote API C++

Posted: 26 Feb 2017, 15:09
by Msalmanch
Sorry for the inconvenience. What i meant was which command will be used for the detection of obstacles using infrared sensor. I have tried the "simxReadProximitySensor" command but it always returns a true value even if there is nothing in front of the sensor. The code is give below:

Code: Select all

#include <iostream>
#include <conio.h>
using namespace std;
extern "C" {
#include "extApi.h"
}
int main(int argc, char** argv)
{
	int a;
	int b;
	int *leftHandMotor  = &a;
	int *rightHandMotor = &b;
        int clientID;
	

	//simxFinish(-1);
	

	clientID=simxStart("127.0.0.1",19999,true,true,2000,5);
	cout << clientID << endl;
    if (clientID!=-1)
    {
      cout << "Connected" << endl;
	  
	simxAddStatusbarMessage(clientID,"Connection Sucessful",simx_opmode_oneshot);
    
	simxGetObjectHandle(clientID,"K3_leftWheelMotor",leftHandMotor,simx_opmode_blocking);
	
	simxGetObjectHandle(clientID,"K3_rightWheelMotor",rightHandMotor,simx_opmode_blocking);
    
	simxSetJointTargetVelocity(clientID,a,1,simx_opmode_streaming);
	
	simxSetJointTargetVelocity(clientID,b,1,simx_opmode_streaming);
	}
	

	int c;
	
	int *sensor  = &c;
	
	int mysensor= simxGetObjectHandle(clientID,"K3_infraredSensor4",sensor,simx_opmode_blocking); 

	simxUChar detectionState;
   
	simxInt errorCode=simxReadProximitySensor(clientID,mysensor,&detectionState,NULL,NULL,NULL,simx_opmode_streaming);

	if (detectionState!=0)
{
    simxAddStatusbarMessage(clientID,"obstacle detected",simx_opmode_oneshot);

	}

	  
		  
		  getch();
	}

Regards.

Re: Obstacle avoidance using Remote API C++

Posted: 28 Feb 2017, 08:13
by coppelia
For instance, this line of code is wrong:

Code: Select all

int mysensor= simxGetObjectHandle(clientID,"K3_infraredSensor4",sensor,simx_opmode_blocking);
you are using the remote API wrongly, mysensor is not the sensor handle, but the returnValue. Make sure to carefully read this page too.

Cheers