differentiating between red blob and green blob

Typically: "How do I... ", "How can I... " questions
mmhwmoh
Posts: 4
Joined: 21 Mar 2017, 00:01

differentiating between red blob and green blob

Postby mmhwmoh » 19 Apr 2017, 00:22

Hi there

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


which i use it after the checking shown below

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

Then i use the if loop to check whether if the blobs are green or red this is outside of the for loop

Code: Select all

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

After this however the simulation was still running the same navigation algorithm without taking into consideration of the red and green blobs

many thanks

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

Re: differentiating between red blob and green blob

Postby coppelia » 19 Apr 2017, 08:31

Hummm, difficult to say, your code probably has some logic problem. Did you try to print the color values to the console to check if detection is correct?

Cheers


Return to “General questions”

Who is online

Users browsing this forum: Bing [Bot] and 7 guests