Command Scheduler Loop Overrun

I have been getting this error since i wrote the vision class. Does anyone know its cause?
The error is :

CommandScheduler loop overrun
Warning at edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:83): Drive.periodic(): 0,081111s
buttons.run(): 0,000977s
Vision.periodic(): 0,000466s

Warning at edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:83): SmartDashboard.updateValues(): 0,000324s
disabledInit(): 0,000130s
robotPeriodic(): 0,090373s
LiveWindow.updateValues(): 0,000015s
Shuffleboard.update(): 0,000017s
disabledPeriodic(): 0,000050s
simulationPeriodic(): 0.000127s

code link : GitHub - kuzeyatay/swerve-code-new

One thing that sticks out to me is you’re calling the vision simulation code from the Drive periodic function. Not sure how expensive that is.

yea i just discovered that this was the problem. Any idea how to fix it?

If you don’t mind a quick code review…

You have vision defined as a subsystem (extending SubsystemBase), but you’re instantiating it in your Drive subsystem. This is a recipe for issues later on, e.g. if you try to use vision in another subsystem.

I would remove SubsystemBase and let it just be a POJO class, then perhaps make it a singleton instead of a public constructor so you don’t end up with multiple instances.

Then you’ll likely want to fix what Peter mentioned. Only update sim stuff in sim mode as that can be a lengthy operation and will have zero benefit on the actual robot. To test if this the cause of your loop overrun issue, you can simply comment out the call to Vision.simulationPeriodic(…)

outed the call, did all your suggestions (thanks alot btw,)that was the issue, however now im getting this error:
Warning at org.photonvision.PhotonCamera.verifyVersion(PhotonCamera.java:368): PhotonVision coprocessor at path /photonvision/limelight is not sending new data.

and im unable to see the estimated position on advantage scope