Help with Errors

Hey, we are new to programming and when we run the code, we get this error.

ERROR Unhandled exception: java.lang.RuntimeException: 
 Code: -1029. HAL: Resource already allocated at [edu.wpi.first.wpilibj.hal.PWMJNI.allocatePWMChannel(Native Method),
 edu.wpi.first.wpilibj.PWM.initPWM(PWM.java:117),
 edu.wpi.first.wpilibj.PWM.<init>(PWM.java:134),
 edu.wpi.first.wpilibj.SafePWM.<init>(SafePWM.java:35),
 edu.wpi.first.wpilibj.Talon.<init>(Talon.java:51),
 org.usfirst.frc.team3023.robot.DriveTrain.<init>(DriveTrain.java:10), 
 org.usfirst.frc.team3023.robot.Robot.robotInit(Robot.java:122), 
 edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:72), 
 edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:241)]

We are wondering if anyone has a solution to this

You are trying to allocate the same PWM more than once.

For clarification, somewhere in your code you have


motor = Talon(0) //or a different number

then later in your code you have


motor = Talon(0)//or a different number, but same number as before

You can’t assign two motor to the same PWM in code. If it so happens that you want to run two motors the exact same way (for a gearbox perhaps?) then you should use a pwm splitter (KOP I believe)

I’m guessing you already fixed this problem with previous comments. An alternate to the PWM splitting in hardware is to map it in software. This can make life easier for your mechanical/electrical teams because they just plug each motor into a PWM slot and then you write the same value out multiple times in each software iteration:

init:
motor1 = Talon(0);
motor2 = Talon(1);

loop:
desiredMotor = 250;
motor1.Set(desiredMotor);
motor2.Set(desiredMotor);