Go to Post "Rookie" just means you are new to the game, not that your team isn't as skilled as many already in the competition. - Bill Moore [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-23-2016, 03:19 PM
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: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
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:	77
Size:	145.5 KB
ID:	21297  Click image for larger version

Name:	Pixy_COM-RIO.png
Views:	73
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
#1620
Reply With Quote
  #2   Spotlight this post!  
Unread 11-23-2016, 07:54 PM
dirtbikerxz's Avatar
dirtbikerxz dirtbikerxz is offline
Captain | Driver | CAD | Junior
AKA: Rohit Gondi
FRC #3991 (KnightVision)
Team Role: Driver
 
Join Date: Nov 2014
Rookie Year: 2015
Location: Baton Rouge, LA
Posts: 441
dirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud of
Re: Quick fix for getting serial data from CMUcam5 Pixy

Can you make the Labview code downloadable please. Thanks. Also, I'm assuming you are running that in Periodic tasks on the roborio right? I'm also extremely new to labview.
__________________

Team 3991: Driver since freshman (2015-), Captain since sophomore (2016-), CADer
"The human condition is not perfect. We are not perfect specimens, any of us. We're not robots." - Michael Ovitz
My posts may or may not reflect the views of my team, they are my opinions, and mine alone.
Reply With Quote
  #3   Spotlight this post!  
Unread 11-23-2016, 08:01 PM
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: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Re: Quick fix for getting serial data from CMUcam5 Pixy

Quote:
Originally Posted by dirtbikerxz View Post
Can you make the Labview code downloadable please. Thanks. Also, I'm assuming you are running that in Periodic tasks on the roborio right? I'm also extremely new to labview.
Cool thing is it is downloadable. Click on the image and open it in a new tab then open a blank VI. Click and drag the image from your web browser and on to the VI block diagram. This is called a VI snippet, see here: http://www.ni.com/tutorial/9330/en/

And yes this belongs in periodic tasks.
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

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

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #4   Spotlight this post!  
Unread 11-23-2016, 08:51 PM
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: Quick fix for getting serial data from CMUcam5 Pixy

Quote:
Originally Posted by jman4747 View Post
Cool thing is it is downloadable. Click on the image and open it in a new tab then open a blank VI. Click and drag the image from your web browser and on to the VI block diagram. This is called a VI snippet, see here: http://www.ni.com/tutorial/9330/en/

And yes this belongs in periodic tasks.
The code is awesome. Thanks for sharing. That being said, telling me about VI snippet tool I think is just as awesome. That's going to be super usefu .
Reply With Quote
  #5   Spotlight this post!  
Unread 11-23-2016, 08:55 PM
dirtbikerxz's Avatar
dirtbikerxz dirtbikerxz is offline
Captain | Driver | CAD | Junior
AKA: Rohit Gondi
FRC #3991 (KnightVision)
Team Role: Driver
 
Join Date: Nov 2014
Rookie Year: 2015
Location: Baton Rouge, LA
Posts: 441
dirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud of
Re: Quick fix for getting serial data from CMUcam5 Pixy

Quote:
Originally Posted by jman4747 View Post
Cool thing is it is downloadable. Click on the image and open it in a new tab then open a blank VI. Click and drag the image from your web browser and on to the VI block diagram. This is called a VI snippet, see here: http://www.ni.com/tutorial/9330/en/

And yes this belongs in periodic tasks.
Woah. That's cool. Also what does ur begin.vi look like?
__________________

Team 3991: Driver since freshman (2015-), Captain since sophomore (2016-), CADer
"The human condition is not perfect. We are not perfect specimens, any of us. We're not robots." - Michael Ovitz
My posts may or may not reflect the views of my team, they are my opinions, and mine alone.
Reply With Quote
  #6   Spotlight this post!  
Unread 11-23-2016, 09:22 PM
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: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Re: Quick fix for getting serial data from CMUcam5 Pixy

There isn't anything related to serial communication in the begin VI. In this case having the initialization code outside of and feeding the loop is effectively the same as having it in the begin VI. The only difference is that code in the begin VI executes before code in periodic tasks. There is also no need for a Refnum set/get VI.

The begin VI exists to help organize code that only needs to execute once and at the beginning of the program, and to ensure that code that initializes something executes before that thing is called in other VIs like periodic tasks or teleop.
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

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

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #7   Spotlight this post!  
Unread 11-25-2016, 05:24 AM
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: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Re: Quick fix for getting serial data from CMUcam5 Pixy

This has been turned into a git hub repo here: https://github.com/FRC4080Turner/Pixy-cam-to-RoboRIO. I will be updating it tomorrow and over the weekend after I have tested this on the RIO again. I will also be testing the Pixy with this lens: http://www.ebay.com/itm/122198892672 and its standard lens on 2016 reflective tape targets.
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

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

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #8   Spotlight this post!  
Unread 11-27-2016, 04:04 PM
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: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Re: Quick fix for getting serial data from CMUcam5 Pixy

So far the Pixy has done a pretty good job of finding reflective tape lit with green LED rings in a well lit area.

Right now I am having an odd problem with the RIO talking to the arduino. Whenever I run the labview code on my computer it works as intended but when I run it on the RIO it seems the RIO is writing to the serial port several times every time I tell it to write once. I double checked with the arduino sketch below and it seems to confirm that the RIO is writing several times every time the VISA write VI executes while the computer only writes once as intended.

Arduino:
Code:
void setup() {
  // put your setup code here, to run once:
Serial.begin(57600);
delay(2000);
Serial.print("on\n");

}

void loop() {

static String C = "wait\n";

  if (Serial.available() > 0)
  {
    C = Serial.readString();
    Serial.print(C);
  }

}
Attached Thumbnails
Click image for larger version

Name:	pixy-COM-RIO.png
Views:	26
Size:	164.2 KB
ID:	21307  
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

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

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #9   Spotlight this post!  
Unread 11-28-2016, 10:00 AM
Bpk9p4's Avatar
Bpk9p4 Bpk9p4 is offline
Registered User
FRC #1756
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Illinios
Posts: 271
Bpk9p4 is on a distinguished road
Re: Quick fix for getting serial data from CMUcam5 Pixy

nice work. Is there any reason you chose this method or i2c
__________________
2015 Midwest Regional Finalist
2015 Central Illinois Regional Winner
2015 Newton Division Finalist
2015 Newton Quality Award
Reply With Quote
  #10   Spotlight this post!  
Unread 11-28-2016, 10:35 AM
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: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Re: Quick fix for getting serial data from CMUcam5 Pixy

One is how easy the wiring is:

Plug in provided ribbon cable (Pixy to Arduino)
Plug in USB cable (Arduino to RoboRIO)

It's basically impossible for that set up to go wrong.

I also find that rs-232 style serial communication is (was...) very easy to wrap my head around.

Has anyone else tested this by the way?
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

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

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #11   Spotlight this post!  
Unread 11-28-2016, 10:55 AM
dirtbikerxz's Avatar
dirtbikerxz dirtbikerxz is offline
Captain | Driver | CAD | Junior
AKA: Rohit Gondi
FRC #3991 (KnightVision)
Team Role: Driver
 
Join Date: Nov 2014
Rookie Year: 2015
Location: Baton Rouge, LA
Posts: 441
dirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud of
Re: Quick fix for getting serial data from CMUcam5 Pixy

Quote:
Originally Posted by jman4747 View Post
One is how easy the wiring is:

Plug in provided ribbon cable (Pixy to Arduino)
Plug in USB cable (Arduino to RoboRIO)

It's basically impossible for that set up to go wrong.

I also find that rs-232 style serial communication is (was...) very easy to wrap my head around.

Has anyone else tested this by the way?
I am about to after school today.
__________________

Team 3991: Driver since freshman (2015-), Captain since sophomore (2016-), CADer
"The human condition is not perfect. We are not perfect specimens, any of us. We're not robots." - Michael Ovitz
My posts may or may not reflect the views of my team, they are my opinions, and mine alone.
Reply With Quote
  #12   Spotlight this post!  
Unread 01-04-2017, 10:03 PM
dirtbikerxz's Avatar
dirtbikerxz dirtbikerxz is offline
Captain | Driver | CAD | Junior
AKA: Rohit Gondi
FRC #3991 (KnightVision)
Team Role: Driver
 
Join Date: Nov 2014
Rookie Year: 2015
Location: Baton Rouge, LA
Posts: 441
dirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud of
Re: Quick fix for getting serial data from CMUcam5 Pixy

I haven't tried the RoboRio code yet, but trying the PC code is giving me an error. I don't know much about labview personally, just trying to figure this out because my team uses labview. I attached a screenshot of the front panel with the error.

The pixy itself does indeed detect my object (I can tell because the light in front of the pixy lights up when the object is placed in front). But the computer/arduino isn't receiving any data. All the connections are good, because the pixy example code in arduino works fine.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_7.png
Views:	12
Size:	49.7 KB
ID:	21448  
__________________

Team 3991: Driver since freshman (2015-), Captain since sophomore (2016-), CADer
"The human condition is not perfect. We are not perfect specimens, any of us. We're not robots." - Michael Ovitz
My posts may or may not reflect the views of my team, they are my opinions, and mine alone.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:02 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi