View Single Post
  #41   Spotlight this post!  
Unread 01-02-2011, 15:54
dyanoshak dyanoshak is offline
Registered User
AKA: David Yanoshak
FRC #2158 (ausTIN CANs)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Austin, TX
Posts: 189
dyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond reputedyanoshak has a reputation beyond repute
Re: Jaguar Speed Control Only Reaches 50% of Setpoint

Taken directly from the Jaguar source code:

Code:
//
// Compute the new control value.
//
llOutput = (((long long)psState->lPGain * (long long)lError) +
            ((long long)psState->lIGain *
             (long long)psState->lIntegrator) +
            ((long long)psState->lDGain *
             (long long)(lError - psState->lPrevError)));
Which translates into: P*Error + I*Integrator + D*(Error - Previous Error)

Error is passed in to the PIDUpdate() function and is calculated as your Target Speed - Current Speed, Target Position - Current Position, and so on.

Integrator is calculated every time PIDUpdate is called:

Code:
//
// Add the error to the integrator.
//
psState->lIntegrator += lError;
New Integrator = Current Integrator + Error

Previous Error is the previously stored error.

The PIDUpdate is called every time ControllerSpeedMode() is called (or any closed loop mode).

Code:
//*****************************************************************************
//
// This function handles the periodic processing for speed control mode.
//
//*****************************************************************************
static void
ControllerSpeedMode(void)
{
    [Omitted Code]

        //
        // Run the PID controller, with the output being the output voltage
        // that should be driven to the motor.
        //
        lTemp = PIDUpdate(&g_sSpeedPID, lTemp) / 256;

    [Omitted Code]

    //
    // Send the new output voltage to the H-bridge.
    //
    HBridgeVoltageSet(g_lVoltage);
}
Which is called by the Controller Interrupt Handler which is triggered every 1ms by the H-Bridge.

Code:
//*****************************************************************************
//
// This function is called to handle the timer interrupt from the PWM module,
// which generates the 1 ms system timing.
//
//*****************************************************************************
void
ControllerIntHandler(void)
{
                [Omitted Code]
                //
                // Call the appropriate control method based on the control mode
                // that is currently enabled.
                //
                if(HWREGBITW(&g_ulFlags, FLAG_VCOMP_MODE))
                {
                    ControllerVCompMode();
                }
                else if(HWREGBITW(&g_ulFlags, FLAG_CURRENT_MODE))
                {
                    ControllerCurrentMode();
                }
                else if(HWREGBITW(&g_ulFlags, FLAG_SPEED_MODE))
                {
                    ControllerSpeedMode();
                }
                else if(HWREGBITW(&g_ulFlags, FLAG_POSITION_MODE))
                {
                    ControllerPositionMode();
                }
                else
                {
                    ControllerVoltageMode();
                }
            [Omitted Code]
    }
Note: I left out code so that this wouldn't be too long.

In each mode the error is in terms of the mode you're in (speed, current, position, voltage). When the PID is updated, the output is converted to a voltage command to the H-Bridge.
Reply With Quote