<< return to Pixycam.com

How to tell 0 blocks found from no new blocks

From what I understand pixy.getBlocks returns the number of blocks found. However, returning 0 could mean 0 blocks found or no new blocks available since the last call. Before I realized this, this was causing me problems as I was trying something along these lines:

while(1)
{
    blocks=pixy.getBlocks()

    if (blocks >0)
    { 
        do some stuff if pixy sees what we want......
    }
    else 
    {
        do some stuff if pixy doesnt see what we are looking for
    }
}

However, it was not behaving as expected as blocks being equal to 0 could also mean no new frames available. The fix was easy, I simply put a delay in the loop to make sure the call to getBlocks() never executes more than 50 times per second.

However, is there an easy way to tell if a 0 returned means 0 blocks found or no new data?

Hello David,
You are correct. This is something that the current serial protocol doesn’t support, and it’s something we’re going to address with a new (or tweaked) protocol (we just don’t have a release date yet!) But your workaround is what we’ve suggested. It’s guaranteed to get you the correct result.

Edward

Is there fix or work around to this?

Not sure if it has been fixed, but the workaround was pretty easy. I simply made certain I didnt call pixy.getBlocks() more than 30 times per second. You could probably get away with faster, but 30 worked well for me and my application.

Hello David,
My apologies! It sounds like you figured this out, but there are a couple threads that describe a similar approach.

http://cmucam.org/boards/9/topics/5734?r=5758#message-5758

But basically you wait 20ms between frames, and that will guarantee that when you call getBlocks(), you’ll be getting the most recent frame.

Edward

Thank you David and Edward