<< return to Pixycam.com

Libpixyusb2 and callChirp Reference

Hi to all,

I’ve received my new Pixycam2, it’s a great product, with an interesting build-in functions…

However, I would like to program the camera from myself to try some different applications. I read about the cool library libpixyusb2 for interact with the device, but unfortunately I haven’t found a program reference like in the last PixyCam, I reviewed the examples but I think it is still enough info unavailable(Also I saw there are recent commits in Github). So, there are my questions…

  • Is there available any reference of the library libpixyusb2? (I also tried to build Doxygen doc)
  • Is there any reference for arguments to callChirp(I saw examples about getting image of the Camera with cam_getFrame)

Greetings,

José

Hello Jose,
We have this information:
https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:building_the_libpixyusb_example_on_linux

What are you trying to do? Perhaps we can point you in the right direction.

Edward

Hi Edward,

I would like to save images in a Webserver, when an action is performed(Ex. A new color detected), now I have a working Node.JS server with a C++ Client to send and show images in a webpage.

So, in that way I will have a registry of actions in my web page, well so I have tried some “functional” examples to get images from the Pixycam2 through callChirp but unfortunately the code response me a -3 parsing error… Well it’s my idea, so I appreciate to have the new reference for getImage

Cheers

Hello Jose,
I’ll pass this on to our development team.

This code snippet below will get a frame. Hope it helps!

Edward

int32_t response;
uint32_t fourcc;
int8_t renderflags;
uint16_t width, height;
uint32_t numPixels;
uint8_t frame[316*208];

return_value = pixy.callChirp(“cam_getFrame”, // String id for remote procedure
1,0x21, // mode
2, 0, // xoffset
2, 0, // yoffset
2, 316, // width
2, 208, // height
0, // separator
&response, // pointer to mem address for return value
&fourcc,
&renderflags,
&width,
&height,
&numPixels,
&frame, // pointer to mem address for returned frame
0);

Hi, Edge…

Thanks for your response, I’ve tried that code, but unfortunately I’ve got a -3(Chirp Parse Error) as a response.

I noticed that in Pixymon -> View -> Console I can get the “reference” of the function cam_getFrame(), it is

help cam_getFrame
> cam_getFrame(INT8 mode, INT16 xOffset, INT16 yOffset, INT16 width, INT16 height)
Get a frame from the camera
Parameters:
   mode: one of the following CAM_GRAB_M0R0 (0x00), CAM_GRAB_M1R1 (0x11), CAM_GRAB_M1R2 (0x21)
   xOffset: x offset counting from left
   yOffset: y offset counting from top
   width: width of frame
   height: height of frame
Returns:
   0 if success, negative if error
   BA81 formatted data

So I format the command callChirp() as you can see in the reference, whatever, I still getting the same error, I think that I’m bad formatting my callChirp arguments due my code is stuck on Chirp::loadArgs library…

How can I debug that args to get the image?

#include "libpixyusb2.h"

using namespace std;

void errores(int resultado, String proceso) {
    if (resultado == PIXY_RESULT_OK) cout << proceso << " Comando finalizado satisfactoriamente " << resultado << endl;
    else if (resultado == PIXY_RESULT_ERROR) cout << proceso << " Comando con error de resultado " << resultado << endl;
    else if (resultado == CRP_RES_ERROR_CRC) cout << proceso << " Error CRC " << resultado << endl;
    else if (resultado == CRP_RES_ERROR_PARSE) cout << proceso << " Parse error " << resultado << endl;
    else if (resultado == PIXY_RESULT_ERROR) cout << proceso << " Comando sin respuesta " << resultado << endl;
    else if (resultado == PIXY_RESULT_BUTTON_OVERRIDE) cout << proceso << " Comando, buscando override" << resultado << endl;

}


Pixy2 camarapixy;
int estadopixy = 0;
int Result;

int main(int argc, char** argv) {

    uint8_t Purple_Color = 0xFF;
    uint8_t Green_Color = 0x00;
    uint32_t Color;
    Color = (Purple_Color << 16) + (Green_Color << 8) + Purple_Color;

    estadopixy = camarapixy.init();
    if (estadopixy) {
        cout << "Error de conexion con Pixy, seguro que esta conectada?" << endl;
        return -1;
    }

    //cout << "Version: " << camarapixy->version << std::endl;

    int return_value = camarapixy.m_link.callChirp("led_set", INT32(Color), END_OUT_ARGS, &Result, END_IN_ARGS);
    errores(return_value, "Led_set");
    int32_t response;
    uint32_t fourcc;
    int8_t renderflags;
    uint16_t width, height;
    uint32_t numPixels;
    uint8_t frame[316 * 208];
    return_value = camarapixy.m_link.callChirp("cam_getFrame", // String id for remote procedure
            INT8(0x21), // mode
            INT16(0), // xoffset
            INT16(0), // yoffset
            INT16(316), // width
            INT16(208), // height
            END_OUT_ARGS,
            &response, // pointer to mem address for return value
            &fourcc,
            &renderflags,
            &width,
            &height,
            &numPixels,
            &frame//z, // pointer to mem address for returned frame
            //END_IN_ARGS
            );
    errores(return_value, "cam_getFrame");
    cout << "Respuesta camara: " << response << endl;
    cout << "Codec FourCC: " << fourcc << endl;
    cout << "Render flags: " << renderflags << endl;
    cout << "width: " << width << endl;
    cout << "height: " << height << endl;
    cout << "Numero Pixeles: " << numPixels << endl;
    cout << "Captura: " << frame << endl;
    return_value = camarapixy.m_link.callChirp("cam_getFrame", // String id for remote procedure
            1, 0x21, // mode
            2, 0, // xoffset
            2, 0, // yoffset
            2, 316, // width
            2, 208, // height
            0, // separator
            &response, // pointer to mem address for return value
            &fourcc,
            &renderflags,
            &width,
            &height,
            &numPixels,
            &frame, // pointer to mem address for returned frame
            0);
    errores(return_value, "cam_getFrame");
    return_value = camarapixy.m_link.callChirp("version");
    errores(return_value, "Version");
    return_value = camarapixy.m_link.callChirp("led_setRGB", INT8(55), INT8(125), INT8(255));
    errores(return_value, "led_setRGB");
    sleep(3);
    return_value = camarapixy.m_link.callChirp("led_setRGB", INT8(255), INT8(125), INT8(5));
    errores(return_value, "led_set_RGB");
    sleep(3);
    return 0;
}

Response

Led_set Comando finalizado satisfactoriamente 0
cam_getFrame Parse error -3
Respuesta camara: -1
Codec FourCC: 0
Render flags: 
width: 0
height: 0
Numero Pixeles: 0
Captura: 
cam_getFrame Parse error -3
Version Parse error -3
led_setRGB Parse error -3
led_set_RGB Parse error -3

One thing I noticed is that you didn’t terminate your first call with a 0, or END_IN_ARGS

There may be a parse error (which may indeed be a bug), but I’m curious – it may still return the data.

Edward

Edward,

Thanks for response, I’ve terminated all my calls with END_IN_ARGS, like I show below, in the “working example”

return_value = camarapixy.m_link.callChirp("cam_getFrame", // String id for remote procedure
            INT8(0x21), // mode
            INT16(0), // xoffset
            INT16(0), // yoffset
            INT16(316), // width
            INT16(208), // height
            END_OUT_ARGS,
            &response, // pointer to mem address for return value
            &fourcc,
            &renderflags,
            &width,
            &height,
            &numPixels,
            &frame, // pointer to mem address for returned frame
            END_IN_ARGS
            );

and in your code

    return_value = camarapixy.m_link.callChirp("cam_getFrame", // String id for remote procedure
            1, 0x21, // mode
            2, 0, // xoffset
            2, 0, // yoffset
            2, 316, // width
            2, 208, // height
            END_OUT_ARGS, // separator
            &response, // pointer to mem address for return value
            &fourcc,
            &renderflags,
            &width,
            &height,
            &numPixels,
            &frame, // pointer to mem address for returned frame
            END_IN_ARGS);

But it still give me a parse error, I searched more deep and I found that I fails in the function int Chirp::loadArgs(va_list *args, void *recvArgs[]) especifically in

    // check to see if last arg is NULL, if not, we have a parse error
    // if the arg isn't null, it means the caller is expecting data to be
    // put there.  If data isn't put there, and the caller dereferences, segfault
    if (va_arg(*args, void **) != NULL) {
        return CRP_RES_ERROR_PARSE;
    }

It’s possible that we miss some value in callChirp()?

José

Hello Jose,
I will log this as a bug so that a developer will look into it. I don’t have an accurate timeframe for when this will be examimined/fixed. My apologies…

Edward

1 Like

Hi Edwar,

I got the same issue using F/W:3.0.10 with libPixyUSB2
the “cam_getFrame” always return -3 when trying above examples…

Any fixing/workaround information available yet?

Best Regards,

Jimmy

Hello Jimmy,
We are working on the next version of firmware – hopefully release in the next couple weeks.

Edward

Thank you very much!

Hello Jimmy,
Our new release should resolve your issue. :slight_smile: Please check our blog for some details about the latest release:

https://pixycam.com/blog/

Edward