mpiFilterGainSet

Declaration

int32_t mpiFilterGainSet(MPIFilter     filter,
                      int32_t          gainIndex,
                      MPIFilterGain *gain)             

Required Header: stdmpi.h

Description

mpiFilterGainSet sets the gain coefficients of a Filter (filter, for the gain index specified by gainIndex) using data from the structure pointed to by gain. Post filters are set using the mpiFilterPostFilterGet/Set and mpiFilterPostFilterSectionGet/Set methods.

filter          A handle to a Filter object.

gainIndex       The index number of the filter gain table. Unless you are using gain tables, set this value to 
                0. If you are setting gain tables in Motion Console, this is the drop down box in Filter 
                Summary->Coeffs that says "Gain Table 0", "Gain Table 1", etc. In standard firmware, the
                gain table indexes are in the following order:
                
                MPIFilterGainIndexNO_MOTION = 0, 
                MPIFilterGainIndexACCEL = 1, 
                MPIFilterGainIndexDECEL = 2, and 
                MPIFilterGainIndexVELOCITY = 3 
                
                To see information on gain indexes in non-standard firmware, see MPIFilterGainIndex.

*gain           Pointer to the gain structure. The gain structure holds the closed loop filter gains. The PID and PIV 
                gains are both set here. The only difference in setting PID vs. PIV gains are the names for the gain 
                indices (see PID example below).
Return Values
MPIMessageOK

Sample Code

/* Sets reasonable tuning parameters for a Trust TA9000 test stand */
void setPIDs(MPIFilter filter)
{
   MPIFilterGain gain;
   MPIFilterGainPID* pid;
   int32_t returnValue;

returnValue = mpiFilterGainGet(filter, 0, &gain); msgCHECK(returnValue);
pid = (MPIFilterGainPID *)&gain;
pid->gain.proportional = 256.0; pid->gain.integral = 0.5; pid->gain.derivative = 2048.0;
pid->feedForward.position = 0.0; pid->feedForward.velocity = 0.0; pid->feedForward.acceleration = 0.0; pid->feedForward.friction = 0.0; pid->dRate = 0;
pid->integrationMax.rest = 32767.0; pid->integrationMax.moving = 0.0;
pid->output.limitHigh = 32767.0; pid->output.limitLow = -32767.0; pid->output.velocityLimitHigh = 32767.0; pid->output.velocityLimitLow = -32767.0; pid->output.offset = 0.0;
pid->noise.positionFFT = 0.0;
returnValue = mpiFilterGainSet(filter, 0, &gain); msgCHECK(returnValue); }

------------------

Another way to change filter coefficients is to use mpiFilterConfigGet /Set.

returnValue = mpiFilterConfigGet(filter, &config);
   msgCHECK(returnValue);
   
   pid = (MPIFilterGainPID*)&filterConfig.gain[gainIndex];
			
   pid->gain.proportional   = 256.0;
   pid->gain.integral       = 0.5;
   pid->gain.derivative     = 2048.0;
  
returnValue = mpiFilterConfigSet(filter, &config, NULL);
  msgCHECK(returnValue);

            

See Also

mpiFilterGainGet | mpiFilterConfigGet | mpiFilterConfigSet | mpiFilterPostFilterGet | mpiFilterPostFilterSet | mpiFilterPostFilterSectionGet | mpiFilterPostFilterSectionSet | Gain Tables