detectionState Proximity sensor C++

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 6
Joined: 19 May 2013, 00:06

detectionState Proximity sensor C++

Post by jegovila » 20 Jul 2013, 22:00


When I use a proximity sensor with Matlab, I use this API function:

Code: Select all

[number errorCode,boolean detectionState,array detectedPoint,number detectedObjectHandle,array detectedSurfaceNormalVector]=simxReadProximitySensor(number clientID,number sensorHandle,number operationMode)
So the "detectionState" is a return value and I can use it directly as an argument for a conditional. This works great.

The problem is when I want to do the same with C++. In C++ the API functon is:

Code: Select all

simxInt simxReadProximitySensor(simxInt clientID,simxInt sensorHandle,simxChar* detectionState,simxFloat* detectedPoint,simxInt* detectedObjectHandle,simxFloat* detectedSurfaceNormalVector,simxInt operationMode)
And the return value is a remote API function error code.

How can I get the detectionState of my sensor in C++?

Can I do this?

Code: Select all

And I will get "true" when no detection?


Site Admin
Posts: 7255
Joined: 14 Dec 2012, 00:25

Re: detectionState Proximity sensor C++

Post by coppelia » 22 Jul 2013, 00:01


From C/C++, use the simxReadProximitySensor from the remote API like this:

Code: Select all

simxChar detectionState;
simxFloat detectedPoint[3];
simxInt detectedObjectHandle;
simxFloat detectedSurfaceNormalVector[3];
simxInt errorCode=simxReadProximitySensor(clientID,sensorHandle,&detectionState,detectedPoint,&detectedObjectHandle,detectedSurfaceNormalVector,operationMode);
if (detectionState!=0)
    // something was detected
If you just need the detection state, then you can set the 4th, 5th and 6th arguments to NULL.
Make sure you read this section on how the remote API works.


Post Reply