<< return to Pixycam.com

Pixy collecting data at 100Hz??

Hi all,

I am tracking the x and y coordinates of a colored object using the following Arduino code:

//
// begin license header
//
// This file is part of Pixy CMUcam5 or “Pixy” for short
//
// All Pixy source code is provided under the terms of the
// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
// Those wishing to use Pixy source code, software and/or
// technologies under different licensing terms should contact us at
// [email protected]. Such licensing terms are available for
// all portions of the Pixy codebase presented here.
//
// end license header
//

/*
06.04.2014 v0.1.3 John Leimon

  • Now using pixy.init() to initialize Pixy in setup().
    */

#include <SPI.h>
#include <Pixy.h>

Pixy pixy;

void setup()
{

Serial.begin(9600);
// Serial.print(“Starting…\n”);

pixy.init();
}

void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
int xvalue;
int yvalue;
//float widthvalue;

blocks = pixy.getBlocks();

xvalue = pixy.blocks[0].x;
yvalue = pixy.blocks[0].y;

Serial.println (xvalue);
Serial.println (yvalue);
//if (blocks)
// {
// i++;

// if (i%50==0)
// {
// sprintf(buf, “Detected %d:\n”, blocks);
// Serial.print(buf);
// for (j=0; j<blocks; j++)
// {
// sprintf(buf, " block %d: ", j);
// Serial.print(buf);
// pixy.blocks[j].print();
// }
// }
//}
}

For whatever reason, it appears that the Pixy is collecting data at 100Hz instead of the 50Hz that the Pixy is reported to collect.

For example, when I record 500 rows of x and y coordinates (each x and y coordinate is one row), it takes only 5 seconds (100Hz) instead of 10 seconds (50Hz). Does anyone have any clue why this might be?

Thank you!
Ethan

An update:

500 rows of data took 5 seconds to collect, suggesting 100Hz collection rate.
1,000 rows took 10 seconds to collect, suggesting 100Hz collection rate.
2,000 rows took 20 seconds to collect, suggesting 100Hz collection rate.
10,000 rows took 100 seconds to collect, suggesting 100Hz collection rate.

BUT 120,000 rows of data took 16 minutes to collect, suggesting a 125Hz collection rate.

Does anyone have any idea why or how this might be occurring?

Hello Ethan,
You should make sure that blocks!=0 before examining the pixy.blocks structure, otherwise the data is stale. The Arduino library getBlocks routine will return 0 if there is no new data as well as no detected blocks, so it sounds like you are overcounting.

Edward

Thanks Edward!

This seems to really help, so long as the target is on screen, as Pixy will return 1 for getBlocks when it is on screen.

But is there a way to distinguish between no new data and no detected blocks when getBlocks == 0? For example, can we get no data coming in when there is no new data, but get coordinates of (-1, -1) or (NaN, NaN) when there are no detected blocks?

From what I can find, I’m not sure that this is possible, but it would be of great help if it were.

Thanks again,

Ethan

Hello Ethan,
If you wait 20ms between calls to getBlocks, you will be able to distinguish: No data means no detected blocks. This works because Pixy flushes the object data at the beginning of each frame, and since frames come in every 20ms, no data is equivalent to nothing detected in the current frame.

We have plans for offering a different serial protocol that would make this better/easier, but we don’t have an estimated date yet.

Edward

Great! Thank you Edward.

I look forward to that serial protocol when you get it completed.