|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#13
|
|||
|
|||
|
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)));
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; 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);
}
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]
}
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. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|