View Single Post
  #1   Spotlight this post!  
Unread 23-11-2016, 15:19
jman4747's Avatar
jman4747 jman4747 is offline
Just building robots
AKA: Josh
FRC #4080 (Team Reboot)
Team Role: CAD
 
Join Date: Apr 2013
Rookie Year: 2011
Location: Atlanta GA
Posts: 415
jman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant futurejman4747 has a brilliant future
Quick fix for getting serial data from CMUcam5 Pixy

So I have a way to get the data from the pixy cam to the RoboRIO via USB at 50 frames a second. The pixy is plugged in to an Arduino Uno with the induced cable and the Arduino is plugged into a PC or RoboRIO via USB. This assumes the pixy is set up to track one object (ie. reflective tape). I set up the Arduino running this:

Code:
#include <SPI.h>  
#include <Pixy.h>

// This is the main Pixy object 
Pixy pixy;

void setup()
{
  Serial.begin(57600);
  Serial.print("on\n");
  delay(1000);
  Serial.print("waiting\n");

  pixy.init();
}

void loop()
{ 
  static String C = "wait";
  int j;
  uint16_t blocks;
  char buf[32]; 
  
  // grab blocks!
  blocks = pixy.getBlocks();
  
  
  if (Serial.available() > 0)
  {
    C = Serial.readString();
    if (C == "go")
    {
      Serial.print("User command: " + C + "\n");
      //delay(500);
      //Serial.print("Data start in 1 second!\n");
      delay(1000);
    }
    else
    {
    Serial.print("User command: " + C + "\n");
    }
  }
// else
//{

//} 
  if(C == "go")
  {
     if (blocks)// If there are blocks detected, print them!
     {
                  //i++;
                   // do this (print) every 2 frames because printing every
                   // frame would bog down the Arduino(not)
                   /*if (i%2==0)
                     {*/
       for (j=0; j<blocks; j++)
       {
       //sprintf(buf, "  block %d: ", j);
       //Serial.print(buf); 
       pixy.blocks[j].print();
       }
         //}
      }  
  }
/*  else if(C == "stop")
  {
    C = "wait";
  } */
  else if(C == "wait")
  {
    //C = "hold";
    delay(250);
  }
  else if(C == "light")
  {
    Serial.print("not implemented\n");
    C = "wait";
    Serial.print("waiting\n");
    delay(250);
  }
  else if(C == "help")
  {
    Serial.print("command list:\ncommand: go = activate camera & start data stream\n");
    Serial.print("command: wait = stop data stream\n");
    Serial.print("command: light = toggle LED ring on or off\nLED ring cannot be toggled off if camera is active\r\n");
    C = "wait";
    Serial.print("waiting\n");
    delay(250);
  }
  else
  {
    Serial.print("bad command\n");
    C = "wait";
    Serial.print("waiting\n");
    delay(250);
  }

}

I then plug in the Arduino to a PC or the RIO and run the attached LabVIEW snippet. The main difference between running it on the computer and the RIO is the visa resource name. On the computer it is "COM3" on the RIO it is "ASRL3::INSTR".

Data comes over USB like this: "sig: 1 x: 164 y: 78 width: 81 height: 71"

I'm not a C programmer or all tha good at LabVIEW so this is all very rough but it seems to get the job done with minimal latency.
Attached Thumbnails
Click image for larger version

Name:	Pixy_COM-PC.png
Views:	72
Size:	145.5 KB
ID:	21297  Click image for larger version

Name:	Pixy_COM-RIO.png
Views:	64
Size:	140.9 KB
ID:	21298  
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

Mentor: Rookie FTC Team "EVE" #10458, FRC Team "Drewbotics" #5812

#banthebag
#RIBMEATS
Reply With Quote