Hello,
I’m toying with the idea to use two pixies: one that looks on the ground and does the line following. And another one on the side to identify barcodes that may be there or removed. It’s a typicaly case that if you want the robot to stop, then you position a stand on the side with a barcode. the robot will stop when it passes nearby. Now I want the system to detect when the user removes the stand in order to resume the moving robot movements.
I do have two pixy2 connected to an arduino mega. One using the default connexion (ISP ?) and the other using I2C.
It does work but i’m concerned with one thing.
While using one pixy for the line following on the floor, I observed a typical loop duration of about 16ms. (about 61 fps). but when i use two pixies, then I see a typical loop duration at about 32ms (31 fps)
the performance of the overall system is divided by two.
It may sounds silly but i dont understand why.
Surely all the time cannot go through the mega <-> pixy communication decoding under the hood?
(i did not notice any difference between using getMainFeatures / getAllFeatures by the way)
What do I wrong? How can i get my 16ms again ?
see code below
// tested on arduino mega
// as is the loop duration is about 16ms
// but if i uncomment the code for the second pixy => then it drops to 31ms
// how come?
#include <Pixy2.h>
Pixy2 pixy_front;
#include <Pixy2I2C.h>
Pixy2I2C pixy_side;
unsigned long previous_tick = 0;
unsigned long current_tick = 0;
void setup() {
previous_tick = millis();
Serial.begin(115200);
Serial.print("init pixy_front...");
pixy_front.init();
//pixy.init(0x58); // 0x58 is i2C address
pixy_front.setLED(255, 255, 255); // white
// Change to line tracking program
pixy_front.changeProg("line");
Serial.print("ok\n");
Serial.print("init pixy_side...");
pixy_side.init();
//pixy.init(0x58); // 0x58 is i2C address
pixy_side.setLED(255, 255, 255); // white
// Change to line tracking program
pixy_side.changeProg("line");
Serial.print("ok\n");
delay(50);
}
void loop() {
current_tick = millis();
long duration = current_tick - previous_tick;
previous_tick = current_tick;
Serial.print("d:");
Serial.print(duration);
Serial.print("\t");
// put your main code here, to run repeatedly:
int8_t res;
res = pixy_front.line.getMainFeatures();
if (res > 0)
{
int32_t x1 = 0xFFFF;
if (res & LINE_VECTOR) {
x1 = (int32_t)pixy_front.line.vectors->m_x1;
}
Serial.print("x:");
Serial.print(x1);
Serial.print("\t");
int32_t b0 = 0xFF00;
if (res & LINE_BARCODE) {
b0 = (int32_t)pixy_front.line.barcodes->m_code;
Serial.print("b0:");
Serial.print(b0);
}
Serial.print("\t");
} else {
Serial.print("pixy_front_getAllFeatures error\t");
}
/* res = pixy_side.line.getMainFeatures();
if (res > 0)
{
int32_t x1 = 0xFFFF;
x1 = 0xFFFF;
if (res & LINE_VECTOR) {
x1 = (int32_t)pixy_side.line.vectors->m_x1;
}
Serial.print("x1:");
Serial.print(x1);
Serial.print("\t");
int32_t b0 = 0xFF00;
if (res & LINE_BARCODE) {
b0 = (int32_t)pixy_side.line.barcodes->m_code;
Serial.print("b1:");
Serial.print(b0);
}
} else {
Serial.print("pixy_side_getAllFeatures error\t");
}
*/
Serial.print("\n");
}