<< return to Pixycam.com

Why is getblocks() taking so long?

I am using pixy for the first time, and one thing I noticed is when I call pixy.ccc.getblocks(), it takes really long time to execute. First time I took time it took 16 ms, and trying out the same code later, it gave me time of about 50 ms. I guess it is not supposed to take this long? Am I timing it correctly and is there something I can do to fix this? Code below:

#include <Pixy2.h>
Pixy2 pixy;

unsigned long loopTime;

void setup() {
Serial.begin(115200);
pixy.init();
}

void loop() {
Serial.println(millis() - loopTime);
loopTime = millis();
pixy.ccc.getBlocks();
}

Hello,
If you are running PixyMon while doing this, it will slow things down especially if you are in full video view with blocks overlaid.

Also bear in mind that printing takes a significant amount of time. If your baudrate is 9600, it takes 1ms per character. You can try averaging over 10 or 100 periods to keep the printing down. Or you can do something like:

t0 = millis();
pixy.ccc.getBlocks();
t1 = millis();
Serial.println(t1-t0)

Edward

I was using baudrate of 115200 which was suggested in pixywiki. I also tried what you suggested over 1000 periods and still getBlocks took about 14 milliseconds to excecute. And the test where I got the time of 50 ms, I had pixymon running.
But what I gathered from your answer, getBlocks shouldn’t take this long?

I’m no expert, but I know the algorithm is running at ~60fps, which works out to 16.7 milliseconds per frame.

So 14 milliseconds for getBlocks seems about right to me…

The problem is that the function is blocking my program for 14 ms when I call it. I’m using pixy in an air hockey robot project, and I would like to constantly check for new information from the pixy camera, but not to stay waiting for the next frame when calling getBlocks().

Is this even possible? I guess I don’t fully understand the function since I have not found much information about it.

Ah! Sorry, I didn’t understand. You should be able to call getBlocks() with the wait argument set to false for non-blocking. Like this:

getBlocks(false)

Our API doc is here, FYI: https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api

Hope this helps!

Cheers,
Jesse

Yes that’s it, thank you this was a big help!

1 Like