I have attempted to write my code in a way to try and differentiate which blob is red and green using an epuck where if the blob is green then it will be new xPos1 variable used for the navigation planning which is written this way

Code: Select all

```
if (proxSensDist[2]+proxSensDist[3]+proxSensDist[4]+proxSensDist[5] ==noDetectionDistance*4)
and xPos1 >= 0.3 and xPos1 <= 0.7 then
velLeft=9
velRight=9
elseif (proxSensDist[2]+proxSensDist[3]+proxSensDist[4]+proxSensDist[5] ==noDetectionDistance*4)
and xPos1 < 0.3 then
velLeft=1
velRight=5
elseif (proxSensDist[2]+proxSensDist[3]+proxSensDist[4]+proxSensDist[5] ==noDetectionDistance*4)
and xPos1 > 0.7 then
velLeft=5
velRight=1
else
velLeft=9
velRight=-9
end
```

i had a condition where i check to see if the epuck is red for example

i define colorCode and xPos1 as within a for loop

Code: Select all

```
xPos1=t1[2+(1-1)*dataSizePerBlob+3]
yPos1=t1[2+(1-1)*dataSizePerBlob+4]
xPos2=t1[2+(2-1)*dataSizePerBlob+3]
yPos2=t1[2+(2-1)*dataSizePerBlob+4]
blobSize2=t1[2+(2-1)*dataSizePerBlob+1]
blobSize3=t1[2+(3-1)*dataSizePerBlob+1]
blobSize4=t1[2+(4-1)*dataSizePerBlob+1]
blobSize5=t1[2+(5-1)*dataSizePerBlob+1]
if (blobBoxDimensions[1]>blobBoxDimensions[2]) then
tmp=blobBoxDimensions[1]
blobBoxDimensions[1]=blobBoxDimensions[2]
blobBoxDimensions[2]=tmp
blobOrientation=blobOrientation+math.pi/2
end
if (blobSize>0.01) and (xPos1>=0.3) and (xPos1<=0.7) then
blobCol1=simGetVisionSensorImage(ePuckCam,resolution[1]*xPos1,resolution[2]*yPos1,1,1)
if (blobCol1[1]>blobCol1[2])and(blobCol1[1]>blobCol1[3]) then
colorCode1=1
end
if (blobCol1[2]>blobCol1[1])and(blobCol1[2]>blobCol1[3]) then
colorCode1=2
end
if (blobCol1[3]>blobCol1[1])and(blobCol1[3]>blobCol1[2]) then
colorCode1=3
end
elseif (blolbCount == 2) and (blobSize2>0.01) and (xPos2>=0.1) and (xPos2<=0.9) then
blobCol2=simGetVisionSensorImage(ePuckCam,resolution[1]*xPos2,resolution[2]*yPos2,1,1)
if (blobCol2[1]>blobCol2[2])and(blobCol2[1]>blobCol2[3]) then
colorCode2=1
end
if (blobCol2[2]>blobCol2[1])and(blobCol2[2]>blobCol2[3]) then
colorCode2=2
end
if (blobCol2[3]>blobCol2[1])and(blobCol2[3]>blobCol2[2]) then
colorCode2=3
end
```

Code: Select all

```
if blobCount == 2 and if colorCode == 1 and colorCode ==2 then
xPos1 = xPos2
```

many thanks