<< return to Pixycam.com

Pixy.line.vectors

I did a quick search for pixy.line.vectors and found this: https://www.bing.com/images/search?q=pixy.line.vectors&qpvt=pixy.line.vectors&FORM=IGRE. Not too helpful!
My question is how to handle the vector info? For example, how would I extrapolate an angle? How to turn the vector into integers?

Thanks!

OK … I worked it out:
#include <Pixy2.h>
#define X_CENTER (pixy.frameWidth/2)
Pixy2 pixy;
int32_t error;

void setup()
{
Serial.begin(115200);
Serial.print(“Starting…\n”);
pixy.init();
pixy.changeProg(“line”);
pixy.setLamp(1, 1);
}

void loop()
{
pixy.line.getAllFeatures();
error = (int32_t)pixy.line.vectors->m_x1 - (int32_t)X_CENTER;
Serial.print("Error: ");Serial.println(error);
}

Hello,
This page may be helpful:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:line_api

Bear in mind that getAllFeatures() will grab all lines, and the first line/vector (referenced in your code) may not be the same line from frame to frame. The m_index field in the m_vectors can help with this.

In general, getMainFeatures() is a good place to start, because it will only return 1 line (the Vector) and the Vector will be the same line from frame to frame.

You might find the line_zumo_demo example helpful (even if you don’t have a Zumo base). It looks like you just want to track the main Vector (is this correct?)

Edward

Hi Pixy-devs!
You should change the header to include Pixy2, otherwise the licensing blabla is somewhat useless…
Cheers
O_Lampe

1 Like