<< return to Pixycam.com

Problem with FPS with PIXY2

Hi there

For my bachelor thesis, I’m creating an air hockey robot, with ESP32 and Pixy2 cam. Because the speed of the puck can be quite high in some cases, high framerate is an absolute necessity. With the pixymon app, it says the Pixy2 has about 60 FPS. However, when in Arduino IDE, I’ve tried seeing how much recordings the pixy2 will make of an object in tracks, I’ve found that it sends only about 34 recordings (I’ll attach the code I used for this). Is there something I’m doing wrong? Or is this because of Arduino IDE? Or maybe something to do with the Baud rate? How can I be sure I’m actually getting 60 recorded positions of the puck every second, and thus be able to track the puck and predict it’s next move?

(FYI : I’ve assigned Signature 1 to a red puck and have kept the red puck in front of the pixy2 to track from the moment the program starts running.)

Kind regards,
LT

Code :

#include <Pixy2SPI_SS.h>
Pixy2SPI_SS pixy;

//------------------------

int counter = 0;

void setup()
{
Serial.begin(9600);
Serial.print(“Starting…\n”);
pixy.init();
}

void loop()
{
pixy.ccc.getBlocks();

if (pixy.ccc.numBlocks)
{
if (pixy.ccc.numBlocks == 1)
{
while(millis()<1000)
{
Serial.println(" Puck detected");
Serial.print("X : “);
Serial.print(pixy.ccc.blocks[0].m_x);
Serial.print(” Y : ");
Serial.print(pixy.ccc.blocks[0].m_y);
counter++;
}
}
}
Serial.print(“There were “);
Serial.print(counter);
Serial.print(” recordings.”);
}

Hello,
Bear in mind that printing will slow thing down significantly :slight_smile:

Edward

Thank you for your reply.

How can I know when the Pixy2 does a recording? Does it do so every loop it goes through? Or do I need to compare the 60 FPS to the Hz the ESP32 is working on? I want to be sure that I’m using the correct timings (so that I know that if the puck moves over a distance of X cm in 1 frame, thus 1/60 of a second --> i can calculate it’s speed) - so that I can estimate the pucks speed and trajectory accurately.

Hello,
When you run the code below (for example):

while(1)
{
   pixy.ccc.getBlocks()
}

Each call to getBlocks() will take one frame period. That is, getBlocks will wait until new data is available. If you have a timer you can take the time before calling getBlocks and you will get an accurate idea of when the data was calculated.

Hope this helps

Edward