I’m trying to program a Dog Walking programming with limelight. But there are some problems.
Is there anyone can help me slove this problem? It’s my code below.
package frc.robot;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.math.controller.PIDController;
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
public class Robot extends TimedRobot{
private final XboxController my_Xbox = new XboxController(0);
private final WPI_VictorSPX my_LFDrive = new WPI_VictorSPX(1);
private final WPI_VictorSPX my_LRDrive = new WPI_VictorSPX(2);
private final WPI_VictorSPX my_RFDrive = new WPI_VictorSPX(3);
private final WPI_VictorSPX my_RRDrive = new WPI_VictorSPX(4);
private final MecanumDrive my_Mec = new MecanumDrive(my_LFDrive, my_LRDrive, my_RFDrive, my_RRDrive);
private final NetworkTable table = NetworkTableInstance.getDefault().getTable(“limelight”);
private final NetworkTableEntry tx = table.getEntry(“tx”);
private final NetworkTableEntry ty = table.getEntry(“ty”);
private final NetworkTableEntry ta = table.getEntry(“ta”);
private final PIDController PID = new PIDController(0.014, 0, 0);
@Override
public void robotInit(){
my_LFDrive.setInverted(true);
my_LRDrive.setInverted(true);
my_RFDrive.setInverted(false);
my_RRDrive.setInverted(false);
}
@Override
public void robotPeriodic(){
SmartDashboard.putNumber(“LimelightX”, tx.getDouble(0));
SmartDashboard.putNumber(“LimelightY”, ty.getDouble(0));
SmartDashboard.putNumber(“LimelightArea”, ta.getDouble(0));
}
@Override
public void teleopPeriodic(){
if(my_Xbox.getRawButton(1) == true){
my_Mec.driveCartesian(0, PID.calculate(ta.getDouble(0), 5)*0.6, PID.calculate(tx.getDouble(0), 0)*0.6);
}else if(my_Xbox.getRawButton(1) == false){
my_Mec.driveCartesian(0, 0, 0);
}else{}
}
}
Sorry, this is my first time posting, so the layout may look a little messy.