I cant find anything on using the battery voltage in that code or a talon. Also I read that the speed controllers have a trype of built in PID Loop. One more thing to the the battery volts we are using:
float volt
.
.
.
volt = DriverStation::GetInstance()->GetBatteryVoltage();
I think that example shows how to set a motor’s position based on the feedback from a potentiometer connected to a mechanism that turns with the motor (perhaps with some gear or sprocket reduction in the mix).
If you instead want to do velocity control, you’ll need some sort of counter or encoder connected to the motor shaft so you can read its speed.
My teams problem is that when we fire our shooter its accurate but when the compressor activates and the voltage drop so does the speed of the shooter. That is why we wanted to create a PID Loop with the battery voltage if possible
Measure the battery voltage and compensate for that by adjusting your motor command. This does not require PID. Adjusting the motor command based on voltage will help, but may not be as accurate as the 2nd solution:
Put a speed sensor on your shooter wheel, and use that as the process variable in a feedback controller. You can use PID control for this, or you can use bang-bang.
So we would have to do a type of if statement that looks at the battery voltage and if the level drops to a certain range change the speed to compensate?
The voltage compensation method is not exact. 12.5 is close. If you want, you can measure the actual battery voltage when you have a fresh battery and the shooter is running at the desired speed and the compressor is not running, and use that value instead of 12.5
If you need accurate control of shooter speed, I suggest you use speed feedback, as most teams who want accurate speed control are doing.