|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#2
|
|||
|
|||
|
Re: WPILib PIDController Question
It's a bit difficult to tell what issues you are having without seeing all of the code (in particular I could not tell how you were reading the sensor and determining the current angle), but here are some suggestions/comments.
If you haven't taken a look at the WPIlib docs on PIDController yet, check out: http://wpilib.screenstepslive.com/s/...rs-pid-control If your class extends PIDSubsystem instead of Subsystem, then you should probably remove your current PIDController object and refer to the WPIlib docs mentioned above. If your class extends Subsystem, then having your own PIDController object (controller) makes sense. Your P value of 10 looks way big for an initial starting point. The P value is multiplied by the error to come up with a motor power value in your PID. Hence a 3 degree error would result in a motor power of 30.0 given your 10.0 P multiplier. I would suggest you start with a much smaller value (like 0.01) and work your way up. Using the SmartDashboard PID control can be very useful for this (enabling this is described later). Once you get close on your P value, try adding some D to reduce oscillation. Make sure you look for inversion of source or power (if your shooter heads in the wrong direction, it typically means that the motor power or sensor reading needs to be inverted). Your pidGet() method looks something like the following: Code:
@Override
public double pidGet() {
System.out.println("Getting value: " + currentAngle);
return currentAngle;
}
Code:
@Override
public double pidGet() {
return readAngle();
}
// Later, in your subsystem add the readAngle() command ...
/**
* Reads voltage from potentiometer and converts to shooter angle in degrees.
*/
double readAngle() {
// Example of reading voltage from AnalogInput
double volts = anglePot.get();
// Convert voltage to degrees (you will need to determine the conversion
// constants shown below based on your robot)
double degs = volts / VOLTS_PER_DEG + DEG_OFS;
return degs;
}
Code:
// Temporarily add widget to dashboard to play with PID settings
SmartDashboard.putData("Angle PID", controller);
Code:
void updateDashboard() {
SmartDashboard.putNumber("Angle Degs", readAngle());
// Comment following when done tuning PID
SmartDashboard.putNumber("Angle Volts", anglePot.get());
SmartDashboard.putNumber("Angle Error", controller.getError());
SmartDashboard.putNumber("Angle Setpoint", controller.getSetpoint());
SmartDashboard.putBoolean("Angle On target", controller.onTarget());
SmartDashboard.putNumber("Angle Power", angleMotor.get());
}
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|