Simulink and CoppeliaSim. Retrieve Ultrasonic Sensors Distance

17 visualizaciones (últimos 30 días)
I am using Simulink to retrieve the distance of the first 8 Ultrasonic sensors from the Pioneer 3DX model that CoppeliaSim provides.
I am using a Level-2 Matlab S-function to communicate CoppeliaSim-Matlab-Simulink.
I am using the following code to retrieve the state and the distance of each sensor:
To get UltrasonicSensor Handles:
for i= 1:1:8
num=num2str(i);
[retunrCode,sensor(i)]=vrep.simxGetObjectHandle(clientID,strcat('Pioneer_p3dx_ultrasonicSensor',num),vrep.simx_opmode_blocking);
end
To get values from each Sensor:
for i=1:1:8
[returnCode,detect(i), aux(i,:),~,~]=vrep.simxReadProximitySensor(clientID, sensor(i),vrep.simx_opmode_blocking);
end
block.OutputPort(6).Data = double(aux);
block.OutputPort(7).Data = double(detect);
I have no problem displaying the state of each sensor, all work well, as in the image shown below, when the box is sensed by the Ultrasonicsensor 8, that state goes to 1 and the rest remain in 0, same way when only the UltrasonicSensor 1 detects the box, only that value changes to 1 and the rest remains in 0.
For the image below, the Matrix Outport shows the x,z,y distance from the Pioneer P3DX to the box.
The output with 8 values shows the state of each sensor, in the image below only the Ultrasonic sensor 8 is detecting as shown in the Pioneer with the box in the right.
I am interested in the values of the 3rd column of the Matrix Output, as you can see in the image below, only the distance from Ultrasonic Sensor 8 has a significant value of 0.3116.
Now, the problem is that when I move the box to be detected by the Ultrasonic Sensor 1, as shown in the second image (Shown below), the UltrasonicSensor State works well, givin only a 1 in the UltrasonicSensor 1 and 2 which are the ones detecting the box, but as you can see, all the distances get the same value as the distance from Ultrasonic Sensor 1, when all Ultrasonic Sensors from 3 to 8 should be 0 or a really low value as the distance shown in the image above. I dont know why is that happening and i would like to know how to get wach distance individually without all values getting the distance of UltrasonicSensor 1.
As i said before I am interested in the 3rd column of the Matrix, and because all values are the same, I cant make my program work well.
Also, I would like to know how to retrieve each value individually of the 3rd column of the Matrix, I am using this code
for i=1:1:8
[returnCode,detect(i), aux(i,:),~,~]=vrep.simxReadProximitySensor(clientID, sensor(i),vrep.simx_opmode_blocking);
end
but it retrieves the entire Matrix, so that would help me a lot too.

Respuesta aceptada

RICARDO ANDRES ROMERO PAREDES
RICARDO ANDRES ROMERO PAREDES el 6 de Mayo de 2021
Hello Gabriel.
First of all, I think that probably the reason why the matrix outputs the same value for the rest of the sensors is an internal issue with Coppelia Sim and maybe there is not much that can be done about that.
But with the information that you show in the pictures is more than enough. Because you can multiply the third coulmn of the matrix aux times the matrix detect. Like this:
aux(:,3).*detect
Let me know if that works :)
PS.: make sure to use the code editor for the code parts next time :v

Más respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by