Go to Post The GDC is the Grinch because they just stole my Christmas! - scottmacdonald [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 03-02-2017, 19:49
matthewha123 matthewha123 is offline
Registered User
FRC #3929
 
Join Date: Feb 2017
Location: Philadelphia, PA
Posts: 2
matthewha123 is an unknown quantity at this point
PixyCam Communication with Roborio through SPI on MXP ports

Hello, I am a programming co-captain for team 3929. This year, we have decided to opt for a PixyCam vision processing system. We have tried using the I2C ports, but were unable to achieve this (we did not know what internal register address to pass into the read() method), we decided to use the SPI ports instead. Here is the relevant code:
Code:
import edu.wpi.first.wpilibj.SerialPort;
 import edu.wpi.first.wpilibj.SerialPort.Port;
public class Robot extends IterativeRobot {
	final String defaultAuto = "Default";
	final String customAuto = "My Auto";
	String autoSelected;
	SendableChooser<String> chooser = new SendableChooser<>();
	
	SerialPort pixy;
	Port port = Port.kMXP;
      public void robotInit() {
		chooser.addDefault("Default Auto", defaultAuto);
		chooser.addObject("My Auto", customAuto);
		SmartDashboard.putData("Auto choices", chooser);
		
		pixy = new SerialPort(19200, port);
		pixy.setReadBufferSize(2);
		
	}

	@Override
	public void teleopPeriodic() {
		//This prints out zero
		System.out.println(pixy.read(2).length);
               
               //print outs are like: [B@8139f0 ; very slow, like 1 line /5sec
               	System.out.println(pixy.read(2));

               //this gives an out of bounds error
               System.out.println(pixy.read(2)[0];

		}
}
Thank you! We appreciate any help, the mech team is getting pretty heated
Reply With Quote
  #2   Spotlight this post!  
Unread 03-02-2017, 21:04
loafdog loafdog is offline
Registered User
AKA: Maciej
FRC #2876 (DevilBotz)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2009
Location: Burlington, MA
Posts: 39
loafdog is on a distinguished road
Re: PixyCam Communication with Roborio through SPI on MXP ports

Regardless if you use i2c or spi to get data from pixy, you need to be to interpret the data coming across. Look at the section called 'The serial protocol' on http://www.cmucam.org/projects/cmuca.../Porting_Guide

We were able to get our pixy working with i2c. Found some posts and code on CD that helped immensely. Take a look at our pixy reading code here:
https://github.com/BHSRobotix/Steamw...s/PixyI2C.java

Here's an example of a team using serial port, I don't know if it works:
https://github.com/AllSparks2848/Pix...obot/Pixy.java

Notice that both examples are reading bytes and than interpreting them according to the pixy serial protocol.

If all that is too much, then try using the pixy via digital and analog inputs.
I haven't seen any examples of code that uses that method but you could search on github.. something like https://github.com/search?utf8=%E2%9C%93&q=frc+pixy+analog&type=Code& ref=searchresults
Reply With Quote
  #3   Spotlight this post!  
Unread 06-02-2017, 15:49
matthewha123 matthewha123 is offline
Registered User
FRC #3929
 
Join Date: Feb 2017
Location: Philadelphia, PA
Posts: 2
matthewha123 is an unknown quantity at this point
Re: PixyCam Communication with Roborio through SPI on MXP ports

Thank you for the links. We have been referencing the cmucam wiki for the pixy cam, and do have code for data interpretation, but we neglected to include it because that code is not the issue, at least as far as we know. We were not able to test the interpreting code because our code to receive data, and place them into arrays, is not working.

One thing that are unsure about is which spi protocol to use, or whether we should use the UART protocol, since one of the SerialPort arguments, (19200), is the default UART baudrate.
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2017, 21:53
azules azules is offline
Registered User
FRC #0702
 
Join Date: Jan 2017
Location: Culver City, CA
Posts: 1
azules is an unknown quantity at this point
Re: PixyCam Communication with Roborio through SPI on MXP ports

Here is a link to our team's Bitbucket with the pixy code from last year.

It uses I2C to communicate and read the first signature identified. The class is set up to run in it's own thread on the RoboRIO and periodically update with new data. Hope it's helpful!
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 09:44.

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