Problems with java devolpment on vscode

Hi lead Programmer for team 6865

I have been trying to program our robot and I keep getting an error with our program that is constant within our programer.

ERROR  1  Button indexes begin at 1 in WPILib for C++ and Java
  edu.wpi.first.wpilibj.DriverStation.reportJoystickUnpluggedError(DriverStation.java:1085) 
ERROR  1  DifferentialDrive... Output not updated often enough.  edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:101) 
ERROR  1  Button indexes begin at 1 in WPILib for C++ and Java
  edu.wpi.first.wpilibj.DriverStation.reportJoystickUnpluggedError(DriverStation.java:1085) 

This is our code

/----------------------------------------------------------------------------/
/* Copyright © 2017-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 edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Joystick;

import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;

/**

  • The VM is configured to automatically run this class, and to call the
  • functions corresponding to each mode, as described in the TimedRobot
  • documentation. If you change the name of this class or the package after
  • creating this project, you must also update the build.gradle file in the
  • project.
    */
    public class Robot extends TimedRobot {
    private static final String kDefaultAuto = “Default”;
    private static final String kCustomAuto = “My Auto”;
    private String m_autoSelected;
    private final SendableChooser m_chooser = new SendableChooser<>();

// Talon Controls

private Talon shoot = new Talon (1);
private Talon intake = new Talon (3);
private Talon Drive = new Talon (4);

private Talon Polocord = new Talon (2);

// Joystick Controls

private final Joystick bigJ = new Joystick(1);
private final Joystick xBox = new Joystick(0);

// Timer
public Timer time = new Timer();

// Constraints for the Joystick

private final double deadZone = 0.05;

// Diffrential Drive
private final DifferentialDrive move = new DifferentialDrive(new Talon(6),new Talon(7));
// Safety offline

/**

  • This function is run when the robot is first started up and should be
  • used for any initialization code.
    */
    @Override
    public void robotInit() {
// Chooser Code

m_chooser.setDefaultOption("Default Auto", kDefaultAuto);

m_chooser.addOption("Blue 1", kCustomAuto);

m_chooser.addOption("Blue 2", kCustomAuto);

m_chooser.addOption("Blue 3", kCustomAuto);

m_chooser.addOption("Red 1", kCustomAuto);

m_chooser.addOption("Red 2",kCustomAuto);

m_chooser.addOption("Red 3", kCustomAuto);

SmartDashboard.putData("Auto choices", m_chooser);

// Camera Server
CameraServer.getInstance().startAutomaticCapture();

// Data for motos

SmartDashboard.putNumber("DrivePower",0.82);
SmartDashboard.putNumber("ShootPower",0.5);
SmartDashboard.putNumber("IntakePower",.5);
SmartDashboard.putNumber("PolyCord",0.6);

}

/**

  • This function is called every robot packet, no matter the mode. Use
  • this for items like diagnostics that you want ran during disabled,
  • autonomous, teleoperated and test.
  • This runs after the mode specific periodic functions, but before

  • LiveWindow and SmartDashboard integrated updating.
    */
    @Override
    public void robotPeriodic() {
    }

/**

  • This autonomous (along with the chooser code above) shows how to select
  • between different autonomous modes using the dashboard. The sendable
  • chooser code works with the Java SmartDashboard. If you prefer the
  • LabVIEW Dashboard, remove all of the chooser code and uncomment the
  • getString line to get the auto name from the text box below the Gyro
  • You can add additional auto modes by adding additional comparisons to

  • the switch structure below with additional strings. If using the
  • SendableChooser make sure to add them to the chooser code above as well.
    */
    @Override
    public void autonomousInit() {
    m_autoSelected = m_chooser.getSelected();
    // m_autoSelected = SmartDashboard.getString(“Auto Selector”, kDefaultAuto);
    System.out.println("Auto selected: " + m_autoSelected);
    }

/**

  • This function is called periodically during autonomous.
    */
    @Override
    public void autonomousPeriodic() {

}

/**

  • This function is called periodically during operator control.
    */
    @Override
    public void teleopPeriodic() {
    // ALL THE POWER
    final double drivePower = SmartDashboard.getNumber(“DrivePower”,0.85);
    final double intakePower = SmartDashboard.getNumber(“IntakePower”,0.9);
    final double shootPower = SmartDashboard.getNumber(“ShootPower”,0.9);
    final double polocordPower = SmartDashboard.getNumber(“PolocordPower”,0.6);
// The Safety Captian should not look at this section

intake.setSafetyEnabled(false);
shoot.setSafetyEnabled(false);
Polocord.setSafetyEnabled(false);
Drive.setSafetyEnabled(false);

if (xBox.getRawButton(1) == true || xBox.getRawButton(0) == true){
if(xBox.getRawButton(1) == true){
Polocord.set(polocordPower);
}else if(xBox.getRawButton(1) == true){
Polocord.set(polocordPower);
}else{
Polocord.set(0);
}
}
if (xBox.getRawButton(5) == true || xBox.getRawButton(5) == true){
if (xBox.getRawButton(5) == true){
shoot.set(shootPower);
}else if (xBox.getRawButton(5)){
shoot.set(shootPower);
}else {
shoot.set(0);
}
}
if(Math.abs(bigJ.getY()) > deadZone || Math.abs(bigJ.getX()) > deadZone){
move.arcadeDrive(bigJ.getY()*drivePower, bigJ.getX()*drivePower);

}
// this is old scripts but are no longer current due to us trying a diffrent method
// Polycord Script
/*
if(xBox.getRawButton(0) == true) {
Polocord.set(polocordPower);
}else{
Polocord.set(0);
}

// Shooting 

if (xBox.getRawButton(5) == true){
  shoot.set(shootPower);
}else{
  shoot.set(0);
}

// Intake

if (xBox.getRawButton(4) == true || xBox.getRawButton == true){
  intake.set(intakePower);
}else{
  intake.set(0);
}




if(Math.abs(bigJ.getY()) > deadZone || Math.abs(bigJ.getX()) > deadZone){
  move.arcadeDrive(bigJ.getY()*drivePower,bigJ.getX()*drivePower);
}

*/

}

/**

  • This function is called periodically during test mode.
    */
    @Override
    public void testPeriodic() {
    }
    }

The warning is warning you because you are asking for a button that does not exist.

To quote the error message: “Button indexes begin at 1 in WPILib for C++ and Java”. In the code you ask for button 0 which is less than 1 and is an illegal button number to ask for.

 xBox.getRawButton(0) == true

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.