<< return to Pixycam.com

ANGLE DETECTION USING COLOR CODE HAVE ILLOGICAL VALUES (65000++)

Hi all,
I’m currently using Pixy for autonomous guided vehicle (AGV) navigation (line following). I am using 2 tapes, yellow & red color code as marker.Through PixyMon I get acceptable angle value for each angle tested on the screen, however when I used Arduino MEGA ADK controller and display the result in serial monitor, it is a bit lagging and displaying illogical values which are above 65000. The programming code and the serial monitor result as follows:

#include   
#include 

// This is the main Pixy object 
Pixy pixy;

void setup()
{
  Serial.begin(9600);
  Serial.print("Starting...\n");

  pixy.init();
}

void loop()
{ 
  static int i=0;
  if (pixy.getBlocks())
  {
    i++;  
  // If there are detect blocks, print them!
  if (i%50*pixy.blocks[0].signature==10); // 10 = 12 octal, but change number to whatever CC you want to detect!
    {
    Serial.print("x: ");
    Serial.print(pixy.blocks[0].x);
    Serial.print("  | y: ");
    Serial.print(pixy.blocks[0].y);
    Serial.print("  | angle: ");
    Serial.println(pixy.blocks[0].angle);
    }
 }  
}

Does anyone have any idea why the angle result have 65000++ value. I believe it should be between 0 to 180 degree. Radian values also shouldn’t be this big

Hello,
The angle value is a 16-bit two’s complement value.

Two’s complement can be confusing. For example, -2 in two’s complement is 0xfe or 254 decimal (8-bit representation), and 0xfffe or 65554 decimal (16-bit representation).

Hope this helps!

Edward