Hi, I am a rookie coder on the Cybertroniclancers team 6087 I’m coding a piece of code for our 2023 robot and I ran into an obscure issue I couldn’t find, the code is a piece of logic that balances the robot using data from an accelerometer mounted on the RIO.
Code:
imports
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import com.kauailabs.navx.frc.AHRS;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
Not inside teleopPeriodic
// Xbox controller method decloration.
private final XboxController xb = new XboxController(0);
// Drive system decloration.
private PWMSparkMax m_leftMotor = new PWMSparkMax(0);
private PWMSparkMax m_rightMotor = new PWMSparkMax(1);
private DifferentialDrive m_robotDrive = new DifferentialDrive(m_leftMotor, m_rightMotor);
// Variable declaration.
boolean balance;
int balanceTimer;
inside roborInit
m_rightMotor.setInverted(true);
m_leftMotor.setSafetyEnabled(false);
m_rightMotor.setSafetyEnabled(false);
m_robotDrive.setSafetyEnabled(false);
inside teleopPeriodic
float pitchValue = cAHRS.getPitch();
balanceTimer++;
if(xb.getLeftBumperPressed() == true && balance == false) {
balance = true;
balanceTimer = 0;
}else if(balance == true && xb.getLeftBumperReleased() == true) {
while(balance == true) {
if(pitchValue <= -20) {
m_leftMotor.set(1);
m_rightMotor.set(1);
}else if(pitchValue >= 20) {
m_leftMotor.set(-1);
m_rightMotor.set(-1);
}
}
}else if (balanceTimer > 1000 && xb.getLeftBumperPressed() == true){
balance = false;
m_leftMotor.set(0);
m_rightMotor.set(0);
}
Console error log:
-
NT: Got a NT4 connection from 172.22.11.1 port 62610
-
NT: CONNECTED NT4 client ‘Dashboard’ (from 172.22.11.1:62610)
-
********** Robot program starting **********
-
NT: Listening on NT3 port 1735, NT4 port 5810
-
NT: Got a NT4 connection from 172.22.11.1 port 62665
-
NT: CONNECTED NT4 client ‘Dashboard’ (from 172.22.11.1:62665)
-
navX-Sensor Java library for FRC
-
navX-Sensor Connected.
-
********** Robot program startup complete **********
-
Default disabledPeriodic() method… Override me!
-
Default robotPeriodic() method… Override me!
-
Loop time of 0.02s overrun
-
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:387): Loop time of 0.02s overrun
-
navX-Sensor Board Type 50 (navX-MXP (Classic))
-
navX-Sensor firmware version 3.1
-
navX-Sensor onboard startup calibration complete.
-
navX-Sensor Yaw angle auto-reset to 0.0 due to startup calibration.
-
SmartDashboard.updateValues(): 0.022723s
disabledInit(): 0.000482s
robotPeriodic(): 0.002340s
LiveWindow.updateValues(): 0.009208s
Shuffleboard.update(): 0.000533s
disabledPeriodic(): 0.003606s -
Warning at edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:62): SmartDashboard.updateValues(): 0.022723s
-
disabledInit(): 0.000482s
-
robotPeriodic(): 0.002340s
-
LiveWindow.updateValues(): 0.009208s
-
Shuffleboard.update(): 0.000533s
-
disabledPeriodic(): 0.003606s
-
Loop time of 0.02s overrun
-
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:387): Loop time of 0.02s overrun
-
teleopPeriodic(): 0.020476s
SmartDashboard.updateValues(): 0.000070s
robotPeriodic(): 0.000024s
LiveWindow.updateValues(): 0.000013s
Shuffleboard.update(): 0.000024s
teleopInit(): 0.000194s -
Warning at edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:62): teleopPeriodic(): 0.020476s
-
SmartDashboard.updateValues(): 0.000070s
-
robotPeriodic(): 0.000024s
-
LiveWindow.updateValues(): 0.000013s
-
Shuffleboard.update(): 0.000024s
-
teleopInit(): 0.000194s
-
Loop time of 0.02s overrun
-
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:387): Loop time of 0.02s overrun
-
NT: DISCONNECTED NT4 client ‘Dashboard’ (from 172.22.11.1:62665): remote end closed connection
-
NT: NT4 socket error: operation canceled