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:
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: **;
}
}
Thank you! We appreciate any help, the mech team is getting pretty heated :)**
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.
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!