Distance Sensors -- Compute Distance (Matlab + Vrep)

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

Distance Sensors -- Compute Distance (Matlab + Vrep)

Post by karabill »

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

if (clientID>-1)
		disp('Connected to remote API server');
        [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
        [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
            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);
    disp('Not connected');

the detected point in matlab shows me that value

Code: Select all

detectedPoint =

   1.0e+25 *

         0         0    4.5524


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.

Thanks in advance,

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

Re: Distance Sensors -- Compute Distance (Matlab + Vrep)

Post by coppelia »


it is always very difficult and time consuming to read through code. Why your robot stops way before your obstacle can have many reasons, and you should try to narrow this down to a few possibilities. Then, when you know that your algorithm is correct and there must be another problem, try to reproduce your problem with a very simple test case that clearly and simply illustrates your problem, so that we can understand what might be going on. Otherwise it is a lot of effort spent for us.


Post Reply