Robots Should not quit, but yours did!

HELP, our teams code isnt working and we arent sure why, the code deploys but when it starts it it gives us these errors

  • ********** Robot program starting **********

  • Unhandled exception instantiating robot edu.wpi.first.hal.DIOJNI edu.wpi.first.hal.util.UncleanStatusException: Code: -1029. HAL: Resource already allocated

  • Error at frc.robot.Robot.(Robot.java:63): Unhandled exception instantiating robot edu.wpi.first.hal.DIOJNI edu.wpi.first.hal.util.UncleanStatusException: Code: -1029. HAL: Resource already allocated

  • at edu.wpi.first.hal.DIOJNI.initializeDIOPort(Native Method)

  • Robots should not quit, but yours did!

  • at edu.wpi.first.wpilibj.DigitalInput.(DigitalInput.java:36)

  • at edu.wpi.first.wpilibj.Encoder.(Encoder.java:137)

  • at frc.robot.Robot.(Robot.java:63)

  • at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:231)

  • at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:348)

  • at frc.robot.Main.main(Main.java:27)

  • Could not instantiate robot edu.wpi.first.hal.DIOJNI!

  • Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:244): Robots should not quit, but yours did!

  • Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:245): Could not instantiate robot edu.wpi.first.hal.DIOJNI!

ill post our coding below, i cant seem to find the issue!

do any of your vi have a broken arrow as the run button?

/----------------------------------------------------------------------------/
/* 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.Encoder;
import edu.wpi.first.wpilibj.PWMVictorSPX;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.CounterBase.EncodingType;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.controller.ProfiledPIDController;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
/**

  • 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<>();
    //Drive Motors
    private final SpeedController MotorfntL = new Spark(0);
    private final SpeedController MotorbckL = new Spark(1);
    private final SpeedController MotorfntR = new Spark(2);
    private final SpeedController MotorbckR = new Spark(3);
    private final SpeedControllerGroup DriveL = new SpeedControllerGroup(MotorfntL, MotorbckL);
    private final SpeedControllerGroup DriveR = new SpeedControllerGroup(MotorfntR, MotorbckR);
    private final DifferentialDrive Drivebase = new DifferentialDrive(DriveL, DriveR);

// ARM
private final SpeedController ArmL = new PWMVictorSPX(4);
private final SpeedController ArmR = new PWMVictorSPX(5);
private final SpeedControllerGroup ARM = new SpeedControllerGroup(ArmL, ArmR);

// INTAKE
private final SpeedController IntakeT = new PWMVictorSPX(6);
private final SpeedController IntakeB = new PWMVictorSPX(7);
private final SpeedControllerGroup INTAKE = new SpeedControllerGroup(IntakeT, IntakeB);

//SHOOTER
private final SpeedController ShooterL = new PWMVictorSPX(8);
private final SpeedController ShooterR = new PWMVictorSPX(9);
private final SpeedControllerGroup SHOOTER = new SpeedControllerGroup(ShooterL,ShooterR);

//PID
private final TrapezoidProfile.Constraints m_constraints = new TrapezoidProfile.Constraints(.5, 0.25);
private final ProfiledPIDController PID = new ProfiledPIDController(.3, 6.5, 0, m_constraints);

//ENCODER
private final Encoder ENC = new Encoder(0,0,false,EncodingType.k4X);

//Controllers
private final Joystick Joy = new Joystick(0);
private final XboxController Xbox = new XboxController(1);

//Variables, doubles,integers, and booleans

private final double AnalogToDegrees = .3515625;
private final double ShaftAngle =(ENC.get()*0.3515625);
private final double EncRaw =ENC.get();
private final double SlowUp = .2;
private final double SlowDown = -.2;
private final double updown = Joy.getPOV(0);

private final boolean isinverted =(true);
private final boolean ispressed = (true);

private final int RightTrigger = 1;
private final int RightStick_X = 5;
/**

  • This function is run when the robot is first started up and should be
  • used for any initialization code.
    */
    @Override
    public void robotInit() {
    m_chooser.setDefaultOption(“Default Auto”, kDefaultAuto);
    m_chooser.addOption(“My Auto”, kCustomAuto);
    SmartDashboard.putData(“Auto choices”, m_chooser);
    CameraServer.getInstance().startAutomaticCapture();
    CameraServer.getInstance().startAutomaticCapture();
    SmartDashboard.putNumber(“Encoder Raw”, EncRaw);
    SmartDashboard.putNumber(“shaft Angle”, ShaftAngle);
    ENC.setDistancePerPulse(AnalogToDegrees);
    ArmL.setInverted(isinverted);

}

/**

  • 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() {
    switch (m_autoSelected) {
    case kCustomAuto:
    // Put custom auto code here
    break;
    case kDefaultAuto:
    default:
    // Put default auto code here
    break;
    }
    }

/**

  • This function is called periodically during operator control.
    */
    @Override
    public void teleopPeriodic() {
while (isOperatorControl() && isEnabled() ) {


Drive();

ArmPositions();

ArmManual();

Intake();

Shooter();

WheelSpin();

Timer.delay(.05);

}}

public void Drive() {

Drivebase.arcadeDrive(-Joy.getRawAxis(1), Joy.getRawAxis(0));
}

public void ArmPositions() {

if (Joy.getRawButton(1) == ispressed) { PID.setGoal(70);
ARM.set(PID.calculate(ENC.getDistance())); }

if (Joy.getRawButton(2) == ispressed) { PID.setGoal(30);
ARM.set(PID.calculate(ENC.getDistance())); }

if (Joy.getRawButton(3) == ispressed) { PID.setGoal(10);
ARM.set(PID.calculate(ENC.getDistance())); }
}

public void ArmManual() {

if (updown == (0)) {ARM.set(SlowUp);}
if (updown == (180)) {ARM.set(SlowDown);}

double output = Joy.getY(); //Moves the Joystick based on Y value
if (ENC.get() < 10) // If the lower soft limit switch is reached, we want to keep the values between -1 and 0
    output = Math.min(output, 0);
else if(ENC.get() > 500) // If the higher soft limit switch is reached, we want to keep the values between 0 and 1
    output = Math.max(output, 0);
ARM.set(output);

}

public void Intake() {

while(Xbox.getRawAxis(1) <= (0.5) && Xbox.getRawAxis(1) >= (-.5))
{Double IntakeSpeed = Xbox.getRawAxis(1);
INTAKE.set(IntakeSpeed);
}
while(Xbox.getRawAxis(1) > (0.5))
{Double IntakeSpeed = .5;
INTAKE.set(IntakeSpeed);
}
while(Xbox.getRawAxis(1) < (-0.5))
{Double IntakeSpeed = -0.5;
INTAKE.set(IntakeSpeed);
}
}

public void Shooter() {

SHOOTER.set(Xbox.getRawAxis(RightTrigger));
}

public void WheelSpin() {

if (Joy.getRawButton(2) == ispressed) { PID.setGoal(35);
ARM.set(PID.calculate(ENC.getDistance())); }

ShooterL.set(-Xbox.getRawAxis(RightStick_X));
ShooterR.set(Xbox.getRawAxis(RightStick_X));

}

//https://github.com/wpilibsuite/allwpilib/blob/master/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorprofiledpid/Robot.java

//https://first.wpi.edu/FRC/roborio/release/docs/java/index.html

/**

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

This is java?

1 Like

dont know what a vi is

oh never mind its not labVIEW

1 Like

yes

yeah its a labVIEW thing i didn’t see that it said Java

This is the clue
Code: -1029. HAL: Resource already allocated

You are most likely trying to allocate or declare a DigitalInput in more than one place, which isn’t allowed.

The stack trace you posted points to an intermediate cause. See here for info on how to interpret it.

In particular:

image

Why are both ports of your encoder set to use pin 0?

2 Likes

I believe the first two numbers should be different. Encoder(0,0, …) doesn’t make sense because there should be 2 channels that are different (A and B channels)

2 Likes

well im using a MA3 absolute encoder which only has 1 output? not quite sure how to wire an encoder tbh

Somebody got pinged for no reason lol

5 Likes

i changed the second input to a 1(which is not being used) will this cause issues?

I believe you want to use the Class DutyCycleEncoder, not the standard encoder.

https://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/DutyCycleEncoder.html

Never use while loops in FRC code. The periodic functions will already be called repeatedly, effectively looping. Introducing an additional loop will stop the rest of your code from running. The error you are getting is because these loops are preventing the code from properly executing as it is within a loop you created.

The reason it throws this error instead of just letting you do this, is because you could potentially code yourself into a situation where you are unable to tell a motor to stop moving. Listen to the error!

Every time you use a while loop, you can often just replace it with an if statement instead. Same goes for for loops. Just don’t.

new issue!, DifferentialDrive… Output not updated often enough.
(please bear with us, we have minimal experience and are building as we speak

It’s the same issue as “robots don’t quit”, more or less. Other code is looping, which prevents this function from being called frequently enough to safely operate the robot. If this error didn’t stop you, your robot would be unable to stop driving. Please see my post above.

Can’t tell if you made the change suggested by Chris_is_me, but it looks like you have some old code where it was possible to have your own operatorControl loop, but that is obsolete now. That does need to be fixed.

should we change that to a if function?