Issue with ObjectHandle returned by simReadProximitySensor

Typically: "How do I... ", "How can I... " questions
Post Reply
DavideIng
Posts: 39
Joined: 21 Sep 2017, 17:27

Issue with ObjectHandle returned by simReadProximitySensor

Post by DavideIng » 30 Nov 2017, 16:40

Hello,
My purpose is get the Image (Rgb_table) from the vision sensor of ePuck1 or ePuck2 or ePuck3 or ePuck4 if detected by one of the ePuck proximity sensor.
To do that I am using the statements below:

Code: Select all

res1,dist1,dP1,detectedObjectHandle1=simReadProximitySensor(ProxSensor1)
res2,dist2,dP2,detectedObjectHandle2=simReadProximitySensor(ProxSensor2)
res3,dist3,dP3,detectedObjectHandle3=simReadProximitySensor(ProxSensor3)
res4,dist4,dP4,detectedObjectHandle4=simReadProximitySensor(ProxSensor4)
res5,dist5,dP5,detectedObjectHandle5=simReadProximitySensor(ProxSensor5)
res6,dist6,dP6,detectedObjectHandle6=simReadProximitySensor(ProxSensor6)
res7,dist7,dP7,detectedObjectHandle7=simReadProximitySensor(ProxSensor7)
res8,dist8,dP8,detectedObjectHandle8=simReadProximitySensor(ProxSensor8)

if (res1>0) then
p1=simGetObjectPosition(detectedObjectHandle1,-1)
end
if (res2>0) then
p2=simGetObjectPosition(detectedObjectHandle2,-1)
end
if (res3>0) then
p3=simGetObjectPosition(detectedObjectHandle3,-1)
end
if (res4>0) then
p4=simGetObjectPosition(detectedObjectHandle4,-1)
end
if (res5>0) then
p5=simGetObjectPosition(detectedObjectHandle5,-1)
end
if (res6>0) then
p6=simGetObjectPosition(detectedObjectHandle6,-1)
end
if (res7>0) then
p7=simGetObjectPosition(detectedObjectHandle7,-1)
end
if (res8>0) then
p8=simGetObjectPosition(detectedObjectHandle8,-1)
end
color1=0
color2=0
color3=0
color4=0
if (detectedObjectHandle1==ePuck1) or (detectedObjectHandle2==ePuck1) or (detectedObjectHandle3==ePuck1) or (detectedObjectHandle4==ePuck1) or (detectedObjectHandle5==ePuck1) or (detectedObjectHandle6==ePuck1) or (detectedObjectHandle7==ePuck1) or (detectedObjectHandle8==ePuck1) then
Rgb_Table1=simGetVisionSensorImage(Camera1,0,0,0)
color1=Rgb_Table1[1]
end

if (detectedObjectHandle1==ePuck2) or (detectedObjectHandle2==ePuck2) or (detectedObjectHandle3==ePuck2) or (detectedObjectHandle4==ePuck2) or (detectedObjectHandle5==ePuck2) or (detectedObjectHandle6==ePuck2) or (detectedObjectHandle7==ePuck2) or (detectedObjectHandle8==ePuck2) then
Rgb_Table2=simGetVisionSensorImage(Camera2,0,0,0)
color2=Rgb_Table2[1]
end

if (detectedObjectHandle1==ePuck3) or (detectedObjectHandle2==ePuck3) or (detectedObjectHandle3==ePuck3) or (detectedObjectHandle4==ePuck3) or (detectedObjectHandle5==ePuck3) or (detectedObjectHandle6==ePuck3) or (detectedObjectHandle7==ePuck3) or (detectedObjectHandle8==ePuck3) then
Rgb_Table3=simGetVisionSensorImage(Camera3,0,0,0)
color3=Rgb_Table3[1]
end

if (detectedObjectHandle1==ePuck4) or (detectedObjectHandle2==ePuck4) or (detectedObjectHandle3==ePuck4) or (detectedObjectHandle4==ePuck4) or (detectedObjectHandle5==ePuck4) or (detectedObjectHandle6==ePuck4) or (detectedObjectHandle7==ePuck4) or (detectedObjectHandle8==ePuck4) then
Rgb_Table4=simGetVisionSensorImage(Camera4,0,0,0)
color4=Rgb_Table4[1]
end
The fact is that the proximity sensor 7 (ProxSensor7) detects the ePuck4 because res7 is > 0 and from the scene I can see that the object detected is the ePuck4 but the instruction:

Code: Select all

Rgb_Table4=simGetVisionSensorImage(Camera4,0,0,0)
color4=Rgb_Table4[1]
Is not executed because the condition:

Code: Select all

if (detectedObjectHandle7==ePuck4) then
Rgb_Table4=simGetVisionSensorImage(Camera4,0,0,0)
color4=Rgb_Table4[1]
end
Don't became true and I don't understand why.
Anyone might help me to figure it out?

Many thanks in advance

Davide

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

Re: Issue with ObjectHandle returned by simReadProximitySensor

Post by coppelia » 01 Dec 2017, 14:54

Hello,

it is very difficult and time-intensive to read code written by another person, and in addition, without the scene it comes with. Try to identify your problem more closely, by for instance preparing a minimalistic scene that illustrates your problem. Also, remove from your code everything that is not part of the problem.

Cheers

Post Reply