proximity sensors problem

Typically: "How do I... ", "How can I... " questions
Post Reply
luberdis
Posts: 27
Joined: 14 Dec 2018, 16:06

proximity sensors problem

Post by luberdis » 06 Jun 2019, 13:45

Hi Coppelia

I am facing 2 problems with ultrasonic sensors.
1)there is a small noise most of the times in the measurement even though the area is clear it seems that it sees something at a distance of 0.02 as a noise
2) I have 3 sensors that they cover 180 degrees , the strange is that when one senros sees something then the other also sensors see the same even though it should be clear.
For example.
https://ibb.co/RvRGFHs

As you see only one detector sees the obstacle but also the other receive it. Why???

I run in sychronous mode and i use commands e.g. for sensor 1

[returnCode,sensor1]=vrep.simxGetObjectHandle(clientID,'Proximity_sensor1',vrep.simx_opmode_blocking);

[returnCode,detectionState3,detectedPoint3,~,~]=vrep.simxReadProximitySensor(clientID,sensor1,vrep.simx_opmode_streaming)

Code: Select all

function simpleSynchronousTest()
    disp('Program started');
    % vrep=remApi('remoteApi','extApi.h'); % using the header (requires a compiler)
    vrep=remApi('remoteApi'); % using the prototype file (remoteApiProto.m)
    vrep.simxFinish(-1); % just in case, close all opened connections
    clientID=vrep.simxStart('127.0.0.1',19997,true,true,5000,5);

    if (clientID>-1)
        disp('Connected to remote API server');

        % enable the synchronous mode on the client:
        vrep.simxSynchronous(clientID,true);

        % start the simulation:
        vrep.simxStartSimulation(clientID,vrep.simx_opmode_blocking);

        [returnCode,sensor1]=vrep.simxGetObjectHandle(clientID,'Proximity_sensor1',vrep.simx_opmode_blocking);
        [returnCode,sensor2]=vrep.simxGetObjectHandle(clientID,'Proximity_sensor2',vrep.simx_opmode_blocking);
        [returnCode,sensor3]=vrep.simxGetObjectHandle(clientID,'Proximity_sensor3',vrep.simx_opmode_blocking);

        [returnCode,LeftM]=vrep.simxGetObjectHandle(clientID,'LeftMotor',vrep.simx_opmode_blocking);
        [returnCode,RightM]=vrep.simxGetObjectHandle(clientID,'RightMotor',vrep.simx_opmode_blocking);
        
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID,LeftM,2,vrep.simx_opmode_blocking);
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID,RightM,2,vrep.simx_opmode_blocking);
        % Now step a few times:
        for i=0:1000
            [returnCode,detectionState1,detectedPoint1,~,~]=vrep.simxReadProximitySensor(clientID,sensor1,vrep.simx_opmode_blocking);
            disp('s1')
            disp(norm(detectedPoint1))
            [returnCode,detectionState2,detectedPoint2,~,~]=vrep.simxReadProximitySensor(clientID,sensor2,vrep.simx_opmode_blocking);
            disp('s2')
            disp(norm(detectedPoint2))
            [returnCode,detectionState3,detectedPoint3,~,~]=vrep.simxReadProximitySensor(clientID,sensor3,vrep.simx_opmode_blocking);
%             [returnCode,detectionState3,detectedPoint3,~,~]=vrep.simxReadProximitySensor(clientID,sensor3,vrep.simx_opmode_streaming);
            disp('s3')
            disp(norm(detectedPoint3))
            disp('Press a key to step the simulation!');
            pause;
            vrep.simxSynchronousTrigger(clientID);
        end
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID,LeftM,0,vrep.simx_opmode_blocking);
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID,RightM,0,vrep.simx_opmode_blocking);
        % stop the simulation:
        vrep.simxStopSimulation(clientID,vrep.simx_opmode_blocking);

        % Now close the connection to V-REP:    
        vrep.simxFinish(clientID);
    else
        disp('Failed connecting to remote API server');
    end
    vrep.delete(); % call the destructor!
    
    disp('Program ended');
end

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

Re: proximity sensors problem

Post by coppelia » 14 Jun 2019, 12:17

Hello,

you really need to be able to locate where the problem is. The problem does not appear to be in V-REP, but more because of the way you interact with V-REP via the remote API. So first thing would be to make sure that in V-REP everything is ok. Next is to find the problem in your client application.

Very probably you are not correctly using the remote API streaming mode. An easy way to check is to use the blocking mode (much slower) first. Then to switch to the streaming mode for values that continuously need to be read. Make sure to carefully read and understand how data streaming works with the remote API.

Cheers

luberdis
Posts: 27
Joined: 14 Dec 2018, 16:06

Re: proximity sensors problem

Post by luberdis » 18 Jun 2019, 10:05

Ok! Let us go from beginning, we have a robot that has multiple proximity sensors. At the example is 3 I want in the SAME simulation step each proximity sensor read its current value and then the robot decide what to do. Th problem is that the sensors get the same value of the others. Now I have tested the different streaming options and the only difference I saw is that when I use op_mode_blocking all the sensors take the value of one no matter where it is and when I use op_mode_streaming the sensors who are placed on the left of the detecting sensor get the same value but on the right. I use synchronous mode with Matlab. The documentation focus on how to avoid reading form other steps.

In my case DOESN'T happen this because I step by pressing key. I want the logical thing the sensor give the value of what it detects by itself and not from the neighbouring

I have seen already the other options of remote API. So how would you implement this?

P.S. the only way I avoid this is to use the trigger for the next simulation step, but then the algorithm is wrong they should work in parallel. So the problem is that multiple proximity sensors get the SAME VALUE, it is correct for the one but for the rest is wrong as there is not any obstacle.

Chreers!

luberdis
Posts: 27
Joined: 14 Dec 2018, 16:06

Re: proximity sensors problem

Post by luberdis » 18 Jun 2019, 10:43

I just saw this post for simReadProximitySensor:

Reads the state of a proximity sensor. This function doesn't perform detection, it merely reads the result from a previous call to sim.handleProximitySensor (sim.handleProximitySensor is called in the default main script). See also sim.checkProximitySensor, sim.checkProximitySensorEx and sim.resetProximitySensor.

To make it clear I want to read the distance from the object.

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

Re: proximity sensors problem

Post by coppelia » 21 Jun 2019, 13:26

Please write a small script that reads and prints the data from those proximity sensors, directly in V-REP. Make sure that those values are correct. Only then, look at the remote API side.
Also, if you are in synchronous mode and haven't yet stepped the simulation, then you won't get any valid data from those proximity sensors, since they haven't yet computed their first values.

Cheers

Post Reply