i am using pixy2 for identifying color of objects that i should move.
i want to use pixy.ccc.blocks[i].m_signature function and detect only color block which size is more than 100 * 100.
what i mean is i don’t want to detect color block or signature of it like this image
here is my code
#include <Pixy2SPI_SS.h>
#include <AIROARM.h>
Pixy2SPI_SS pixy;
AiroArm arm;
unsigned long previousMillis = 0;
const long interval = 2000;
int t=0;
int mode = 1;
int colorArr[6];
int8_t i;
char buf[128];
void setup()
{
pixy.init(); //픽시캠 초기화
pixy.changeProg("ccc"); //픽시캠 모드 ccc로 변경 (color connected components)
pixy.setLED(255,255,255);
pixy.setLamp(0,0);
arm.offset.m1_deg = 4;
arm.offset.m2_deg = 3;
Serial.begin(9600);
Serial1.begin(1000000);
arm.pSerial = &Serial1;
arm._init();
}
void loop()
{
//int8_t i;
//char buf[128];
pixy.ccc.getBlocks();
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
t++;
}
if(mode==1)
{
switch(t)
{
case 1 :
arm.movel(60.3788, 190.201,0);
delay(1000);
colorArr[0] = ScanColor();
break;
case 2 :
arm.movel(15.2149, 191.3841,0);
delay(1000);
colorArr[1] = ScanColor();
break;
case 3 :
arm.movel(-20.0207, 181.6863,0);
delay(1000);
colorArr[2] = ScanColor();
break;
case 4 :
arm.movel(-54.8372, 175.0377,0);
delay(1000);
colorArr[3] = ScanColor();
break;
case 5 :
arm.movel(-90.7539, 168.0381,0);
delay(1000);
colorArr[4] = ScanColor();
break;
case 6 :
arm.movel(-119.8989, 162.8829,0);
delay(1000);
colorArr[5] = ScanColor();
Serial.print("colorArr[0] = ");
Serial.println(colorArr[0]);
Serial.print("colorArr[1] = ");
Serial.println(colorArr[1]);
Serial.print("colorArr[2] = ");
Serial.println(colorArr[2]);
Serial.print("colorArr[3] = ");
Serial.println(colorArr[3]);
Serial.print("colorArr[4] = ");
Serial.println(colorArr[4]);
Serial.print("colorArr[5] = ");
Serial.println(colorArr[5]);
//t=0;
mode++;
break;
}
}
}
int ScanColor()
{
pixy.ccc.getBlocks();
if(pixy.ccc.numBlocks)
{
if(pixy.ccc.blocks[i].m_width >= 100)
{
if(pixy.ccc.blocks[i].m_height >= 100)
{
if(pixy.ccc.blocks[i].m_signature > 4)
{
return -1;
}
else
{
return pixy.ccc.blocks[i].m_signature;
}
}
}
}
else
return -1;
}
airoarm.h and arm.movel are the function about moving robot arm to the point
i want the result
if there’s red, blue, yellow, green color, each matches 1, 2, 3, 4 signature number
and if there’s no object, restore -1 to array
when i run this code, the result was colorArr[] = {1, 2, 44, 4, 3, -1}
is there anything wrong to my code?
i just don’t want to return the result like 44…