PixyCam Array Woes

Hello,
I am new to bus systems (and Java in robotics in general), but many of my offseason (midseason?) mentor projects involve both. I am trying to get the Pixy2 running on an offseason bot. I finally got it to connect and report out its findings, but I am having a type error.

Most of the example code I have found (many thanks to the incredible CD) basically do the following…

  1. Setup the Pixy Object
  2. Begin communication with the camera
  3. Get the block array
  4. Parse the block array
  5. Do stuff with the blocks.

I am stuck in step 3. I am using the PseudoResonance library, but whenever I try the following…
ArrayList<Block> blocks = pixycam.getCCC().getBlocks(); I get a Intellisense error
Type mismatch: cannot convert from int to ArrayList<Pixy2CCC.Block>Java(16777233) but what is worse, I get a build error for the same reason.

Does anyone have any thoughts about what I am doing wrong? I can run the method pixycam.getCCC().getBlocks() Straight into the smart dashboard and get a number (I believe it is the number of blocks the camera is finding).

Thanks in advance, my code is below. I am running a basic (non-framework) design right now.

/*----------------------------------------------------------------------------*
/
/* Copyright (c) 2018 FIRST. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code
*/
/* must be accompanied by the FIRST BSD license file in the root directory of
*/
/* the project.
*/
/*----------------------------------------------------------------------------*/

package frc.robot;
import java.util.ArrayList;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import io.github.pseudoresonance.pixy2api.*;
import io.github.pseudoresonance.pixy2api.Pixy2CCC.Block;
/**
* PIXY SPI EXAMPLE
* A few notes
* 1.) Two things need to be added to the build.gradle file. See the attached
tutorial document
* 2.) This code is for using Chip Select 0 (CS0) and the onboard SPI Port
* 3.) If you are using SPI mode, go into PixyMon and set the control mode to
SPI
*/
public class Robot extends TimedRobot {
  /**
* This function is run when the robot is first started up and should be used
* for any initialization code.
*/
private Pixy2 pixycam;
boolean isCamera = false ;
//private SPILink spi;
int state=- 1 ;
@Override
public void robotInit () {
  
  pixycam = Pixy2.createInstance(Pixy2.LinkType.I2C);
 // pixy.init(1);
}
@Override
public void teleopPeriodic () {
if (!isCamera)
state = pixycam.init( ); // if no camera present, try to initialize
isCamera = state>= 0 ;
SmartDashboard.putBoolean( "Camera" , isCamera); //publish if we are connected
pixycam.getCCC().getBlocks( false , 255 , 255 ); //run getBlocks with arguments to have the camera
SmartDashboard.putNumber( "Stuff" , pixycam.getCCC().getBlocks() );
//acquire target data
ArrayList<Block> blocks = pixycam.getCCC().getBlocks(); //assign the data to an ArrayList for convinience
if (blocks.size() > 0 )
{
double xcoord = blocks.get( 0 ).getX(); // x position of the largest target
double ycoord = blocks.get( 0 ).getY(); // y position of the largest target
String data = blocks.get( 0 ).toString(); // string containing target info
SmartDashboard.putBoolean( "present" , true ); // show there is a target present
SmartDashboard.putNumber( "Xccord" ,xcoord);
SmartDashboard.putNumber( "Ycoord" , ycoord);
SmartDashboard.putString( "Data" , data );
}
else
SmartDashboard.putBoolean( "present" , false );
SmartDashboard.putNumber( "size" , blocks.size());//push to dashboard how many targets are detected 

}
}

getBlocks returns the number of blocks returned, but has a side effect of adding the blocks to the block cache, which you can access using getBlockCache.

1 Like

Thank you. That is exactly what I was looking for. I will try this out.
Edit: It Worked. :slight_smile: