Hello Everyone,
I am quite impressed with my Pixy2. I am doing testing with a stepper driven XY table and arduino mega which tracks objects above it and follows them. It’s working but getBlacks() limits my step rate to 60 steps per second while tracking. That is incredibly slow on a 800 step per revolution stepper driver. I have cheated this by not updating the getBlocks as often but that also makes it run quite jittery.
From my searching this is a known situation. When you call “pixy.ccc.getBlocks();” it will automatically wait until the next frame from the camera is available by default. I have also read on this forum that if you call “pixy.ccc.getBlocks(false);” it will not wait and return the prior data if nothing new is available. This is exactly what I want but it doesn’t seem to work. Whether I use the “false” statement or not seems to have absolutely zero effect.
Am I misunderstanding how to do this correctly? Thank you! - Brad
I have included the code that runs very slow. Hopefully I formatted it correctly.
#include <Pixy2.h>
// This is the main Pixy object
Pixy2 pixy;
// Define stepper motor connections and steps per revolution:
#define dirPin 2
#define stepPin 3
#define dirPiny 4
#define stepPiny 5
int Speed = 700;
int i = 0;
void setup()
{
// Serial.begin(115200);
// Serial.print("Starting...\n");
pixy.init();
pixy.changeProg("color_connected_components");
// Declare pins as output for stepper driver:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(stepPiny, OUTPUT);
pinMode(dirPiny, OUTPUT);
}
void loop()
{
// grab blocks!
pixy.ccc.getBlocks(false);
// If there are detect blocks, print them and check location!
if (pixy.ccc.numBlocks)
{
// Serial.print (pixy.ccc.blocks[0].m_x);
// Serial.println();
if (pixy.ccc.blocks[0].m_x < 150) //get x coordinate of block 0 and check its location from center
{
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Speed);
}
if (pixy.ccc.blocks[0].m_x > 165)
{
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Speed);
}
if (pixy.ccc.blocks[0].m_y < 96) //get y coordinate of block 0 and check its location from center
{
digitalWrite(dirPiny, LOW);
digitalWrite(stepPiny, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPiny, LOW);
delayMicroseconds(Speed);
}
if (pixy.ccc.blocks[0].m_y > 111)
{
digitalWrite(dirPiny, HIGH);
digitalWrite(stepPiny, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPiny, LOW);
delayMicroseconds(Speed);
}
}
// delay(100);
}