## Distance Sensors -- Compute Distance (Matlab + Vrep)

Typically: "How do I... ", "How can I... " questions
karabill
Posts: 6
Joined: 14 Jun 2017, 11:20

### Distance Sensors -- Compute Distance (Matlab + Vrep)

Im new in vrep. Currently im doing my bachelor thesis and as i havent use before vrep i have many questions. I managed to connect vrep and matlab and the pioneer p3dx robot when a cuboid is on its way to stop. But my problem is that the robot stops very far from the cuboid and i cant do it stop closer. my matlab code is this.

Code: Select all


vrep=remApi('remoteApi');
vrep.simxFinish(-1);
clientID=vrep.simxStart('127.0.0.1',19999,true,true,5000,5);
if (clientID>-1)
disp('Connected to remote API server');

%motors
[returnCode, left_Motor] = vrep.simxGetObjectHandle(clientID,'Pioneer_p3dx_leftMotor', vrep.simx_opmode_oneshot_wait);%left motor
[returnCode, right_Motor] = vrep.simxGetObjectHandle(clientID,'Pioneer_p3dx_rightMotor', vrep.simx_opmode_oneshot_wait);%right motor

%sensors
[returnCode, front_sensor] = vrep.simxGetObjectHandle(clientID,'Pioneer_p3dx_ultrasonicSensor5', vrep.simx_opmode_oneshot_wait);%fron sensor (5)
[returnCode,detectionState, detectedPoint,~,~] = vrep.simxReadProximitySensor(clientID, front_sensor, vrep.simx_opmode_streaming); %start measuring

[returnCode] = vrep.simxSetJointTargetVelocity(clientID, left_Motor, 0.1,  vrep.simx_opmode_oneshot_wait);% left motor velocity
[returnCode] = vrep.simxSetJointTargetVelocity(clientID, right_Motor, 0.1,  vrep.simx_opmode_oneshot_wait);% right motor velocity

while 1
[returnCode, detectionState, detectedPoint,~,~] = vrep.simxReadProximitySensor(clientID, front_sensor, vrep.simx_opmode_buffer)% measurement refresh
disp(norm(detectedPoint))

if (detectionState == 1)

[returnCode] = vrep.simxSetJointTargetVelocity(clientID, left_Motor, 0,  vrep.simx_opmode_oneshot_wait);
[returnCode] = vrep.simxSetJointTargetVelocity(clientID, right_Motor, 0,  vrep.simx_opmode_oneshot_wait);
end

end

vrep.simxFinish(-1);
else
disp('Not connected');
end
vrep.delete()


the detected point in matlab shows me that value

Code: Select all

detectedPoint =

1.0e+25 *

0         0    4.5524

4.5524e+25


Also im trying to do the bug1 algorithm. so when the robot follows the perimeter of the obstacle i want to measure the distance from robot position to the end(for example a dummy as destination) and when the robot make 1 circle around the obstacle i want to go to the minimum distance between obstacle and dummy. how can i measure that distance and the coordinates of that position? so that the robot go to this position and continue the path to the destination.

Karabill

coppelia