Troubleshooting

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

What exactly is the issue youre having?

Also, if you add triple backticks (```) before and after your code, it’ll format properly. Even better, link to github is helpful

Looking at the errors and code you have provided. It looks like it is having a loop overrun error. Though I do not know much about it, it happened to us when we tried to run a method using a while true loop.

We were using Command Based Robot so all we had to do was change the method into a command and it stopped the errors.

I am not too familiar with Timed Robot, but I would suggest looking into making it into a command rather than a while true based off of a boolean value.

Even if this isn’t the solution, I hope this gives at least an idea on what to look into regarding fixing this problem.

The loop overrun message may indicate a problem, but it is common to get a couple of them when the robot is first starting up. I see your two culprits are SmartDashboard.updateValue and teleopPeriodic. For the latter case, the while loop is clearly causing it. Periodic methods (along with command life cycle methods) should be quick in-and-out, not lengthy. In particular, so long as your teleopPeriodic is running, nothing else in the main event loop can run.

Also, consider making the motor power proportional to the size of the (error) angle. This would make your code a simple P-controller.

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