PID + Battery Voltage + Talon=??????

So my team needs a PID Controller code for our shooter. All the example code shows this:

	Joystick turretStick(1);
	Jaguar turretMotor(1);
	AnalogChannel turretPot(1);
	PIDController turretControl(0.1, 0.001, 0.0, &turretPot, &turretMotor);
	
	turretControl.Enable();  // start calculating PIDOutput values

	while(IsOperator())
   {
		turretControl.SetSetpoint((turretStick.GetX() + 1.0) * 2.5);
		Wait(.02);		// wait for new joystick values
	}

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.

Why do you care about battery voltage?

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

You have at least 2 choices:

  1. 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:

  2. 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?

Multiply your motor command by 12.5/V, where V is the measured voltage. As V goes down, this compensates by increasing your motor command.

This only works, of course, if you have some headroom in your motor command, i.e. you are not already commanding 100%.

but that is assuming your battery starts at 12.5 V what if you get a batter that starts at 12.8V or is that something we would have to test

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.

speed feedback?

Attach an encoder to the wheel and read the rate out of it. It’s what the example you posted does.