📄 ampstruct.cpp
字号:
Programmable I/O pins
*/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/**
Default constructor for AmpIoCfg structure. This simply sets all member
parameters to default values of zero.
*/
/***************************************************************************/
AmpIoCfg::AmpIoCfg( void )
{
int i;
inputCt = 0;
outputCt = 0;
inPullUpCfg = 0;
for( i=0; i<COPLEY_MAX_INPUTS; i++ )
{
inCfg[i] = (INPUT_PIN_CONFIG)0;
inDebounce[i] = 0;
}
for( i=0; i<COPLEY_MAX_OUTPUTS; i++ )
{
outCfg[i] = (OUTPUT_PIN_CONFIG)0;
outMask[i] = 0;
outMask1[i] = 0;
}
}
/***************************************************************************/
/**
Configure the amplifier's programmable I/O pins using the values passed
in the config structure.
The inputCt and outputCt values of the config structure should indicate the
total number of input & output pins to configure. If the amplifier has more
pins then these values indicate, the configuration of the remaining amplifier
pins will not be changed.
@param cfg A structure that holds the configuration settings.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::SetIoConfig( AmpIoCfg &cfg )
{
uint8 inCt, outCt;
int i;
const Error *err = sdo.Upld8( OBJID_INPUT_CFG, 0, inCt );
if( !err ) err = sdo.Upld8( OBJID_OUTPUT_CFG, 0, outCt );
if( !err ) err = SetIoPullup( cfg.inPullUpCfg );
if( inCt > cfg.inputCt ) inCt = cfg.inputCt;
if( outCt > cfg.outputCt ) outCt = cfg.outputCt;
if( inCt > COPLEY_MAX_INPUTS ) inCt = COPLEY_MAX_INPUTS;
if( outCt > COPLEY_MAX_OUTPUTS ) outCt = COPLEY_MAX_OUTPUTS;
for( i=0; i<inCt && !err; i++ )
{
err = SetInputConfig( i, cfg.inCfg[i] );
if( !err )
err = SetInputDebounce( i, cfg.inDebounce[i] );
}
for( i=0; i<outCt && !err; i++ )
err = SetOutputConfig( i, cfg.outCfg[i], cfg.outMask[i], cfg.outMask1[i] );
return err;
}
/***************************************************************************/
/**
Read the amplifier's programmable I/O pin configuration and return it in
the passed config structure.
@param cfg A structure that holds the configuration settings.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::GetIoConfig( AmpIoCfg &cfg )
{
int i;
const Error *err = sdo.Upld8( OBJID_INPUT_CFG, 0, cfg.inputCt );
if( !err ) err = sdo.Upld8( OBJID_OUTPUT_CFG, 0, cfg.outputCt );
if( !err ) err = GetIoPullup( cfg.inPullUpCfg );
if( cfg.inputCt > COPLEY_MAX_INPUTS ) cfg.inputCt = COPLEY_MAX_INPUTS;
if( cfg.outputCt > COPLEY_MAX_OUTPUTS ) cfg.outputCt = COPLEY_MAX_OUTPUTS;
for( i=0; i<cfg.inputCt && !err; i++ )
{
err = GetInputConfig( i, cfg.inCfg[i] );
if( !err )
err = GetInputDebounce( i, cfg.inDebounce[i] );
}
for( i=0; i<cfg.outputCt && !err; i++ )
err = GetOutputConfig( i, cfg.outCfg[i], cfg.outMask[i], cfg.outMask1[i] );
return err;
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
Regen resister configuration
*/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/**
Download a new configuration structure for the power regeneration resister.
Note that not all amplifiers support a regen resister. Please see the
amplifier datasheet to determine if this feature is available for the
amplifier being used.
@param cfg A structure containing the configuration parameters to set.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::SetRegenConfig( RegenConfig &cfg )
{
const Error *err = sdo.DnldString( OBJID_REGEN_MODEL, 0, cfg.model );
if( !err ) err = sdo.Dnld16( OBJID_REGEN_TIME, 0, cfg.peakTime );
if( !err ) err = sdo.Dnld16( OBJID_REGEN_RES, 0, cfg.resistance );
if( !err ) err = sdo.Dnld16( OBJID_REGEN_CONT, 0, cfg.contPower );
if( !err ) err = sdo.Dnld16( OBJID_REGEN_PEAK, 0, cfg.peakPower );
if( !err ) err = sdo.Dnld16( OBJID_REGEN_VON, 0, cfg.vOn );
if( !err ) err = sdo.Dnld16( OBJID_REGEN_VOFF, 0, cfg.vOff );
return err;
}
/***************************************************************************/
/**
Upload the current configuration parameters for the power regeneration
resister connected to the amplifier.
Note that not all amplifiers support a regen resister. Please see the
amplifier datasheet to determine if this feature is available for the
amplifier being used.
@param cfg A structure where the configuration parameters will be returned.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::GetRegenConfig( RegenConfig &cfg )
{
int32 l;
const Error *err = sdo.UpldString( OBJID_REGEN_MODEL, 0, l=COPLEY_MAX_STRING, cfg.model );
if( !err ) err = sdo.Upld16( OBJID_REGEN_TIME, 0, cfg.peakTime );
if( !err ) err = sdo.Upld16( OBJID_REGEN_RES, 0, cfg.resistance );
if( !err ) err = sdo.Upld16( OBJID_REGEN_CONT, 0, cfg.contPower );
if( !err ) err = sdo.Upld16( OBJID_REGEN_PEAK, 0, cfg.peakPower );
if( !err ) err = sdo.Upld16( OBJID_REGEN_VON, 0, cfg.vOn );
if( !err ) err = sdo.Upld16( OBJID_REGEN_VOFF, 0, cfg.vOff );
return 0;
}
/***************************************************************************/
/**
Configure the amplifier's homing related parameters. The passed structure
contains all parameters related to performing a home routine.
@param cfg A structure holding the configuration parameters.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::SetHomeConfig( HomeConfig &cfg )
{
const Error *err = SetHomeMethod( cfg.method, cfg.extended );
if( !err ) err = SetHomeOffset( cfg.offset );
if( !err ) err = SetHomeVelFast( cfg.velFast );
if( !err ) err = SetHomeVelSlow( cfg.velSlow );
if( !err ) err = SetHomeAccel( cfg.accel );
if( !err ) err = SetHomeCurrent( cfg.current );
if( !err ) err = SetHomeDelay( cfg.delay );
return err;
}
/***************************************************************************/
/**
Load a structure with all parameters related to homing the amplifier.
@param cfg A structure where the configuration parameters will be returned.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::GetHomeConfig( HomeConfig &cfg )
{
const Error *err = GetHomeMethod( cfg.method, &cfg.extended );
if( !err ) err = GetHomeOffset( cfg.offset );
if( !err ) err = GetHomeVelFast( cfg.velFast );
if( !err ) err = GetHomeVelSlow( cfg.velSlow );
if( !err ) err = GetHomeAccel( cfg.accel );
if( !err ) err = GetHomeCurrent( cfg.current );
if( !err ) err = GetHomeDelay( cfg.delay );
return err;
}
/***************************************************************************/
/**
Configure the amplifier's parameters related to point-to-point moves.
@param cfg A structure holding the configuration parameters.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::SetProfileConfig( ProfileConfig &cfg )
{
const Error *err = SetProfileType( cfg.type );
if( !err ) err = SetTargetPos( cfg.pos );
if( !err ) err = SetProfileVel( cfg.vel );
if( !err ) err = SetProfileAcc( cfg.acc );
if( !err ) err = SetProfileDec( cfg.dec );
if( !err ) err = SetProfileJerk( cfg.jrk );
if( !err ) err = SetQuickStopDec( cfg.abort );
return err;
}
/***************************************************************************/
/**
Load a structure with all parameters related to point-to-point moves.
@param cfg A structure where the configuration parameters will be returned.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::GetProfileConfig( ProfileConfig &cfg )
{
const Error *err = GetProfileType( cfg.type );
if( !err ) err = GetTargetPos( cfg.pos );
if( !err ) err = GetProfileVel( cfg.vel );
if( !err ) err = GetProfileAcc( cfg.acc );
if( !err ) err = GetProfileDec( cfg.dec );
if( !err ) err = GetProfileJerk( cfg.jrk );
if( !err ) err = GetQuickStopDec( cfg.abort );
return err;
}
/***************************************************************************/
/**
Configure the amplifier's internal function generator.
@param cfg A structure holding the configuration to download
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::SetFuncGenConfig( FuncGenConfig &cfg )
{
const Error *err = sdo.Dnld16( OBJID_FGEN_CFG, 0, cfg.cfg );
if( !err ) err = sdo.Dnld16( OBJID_FGEN_FREQ, 0, cfg.freq );
if( !err ) err = sdo.Dnld32( OBJID_FGEN_AMP, 0, cfg.amp );
if( !err ) err = sdo.Dnld16( OBJID_FGEN_DUTY, 0, cfg.duty );
return err;
}
/***************************************************************************/
/**
Upload the current configuration of the amplifier's internal function generator.
@param cfg A structure where the configuration will be returned.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::GetFuncGenConfig( FuncGenConfig &cfg )
{
const Error *err = sdo.Upld16( OBJID_FGEN_CFG, 0, cfg.cfg );
if( !err ) err = sdo.Upld16( OBJID_FGEN_FREQ, 0, cfg.freq );
if( !err ) err = sdo.Upld32( OBJID_FGEN_AMP, 0, cfg.amp );
if( !err ) err = sdo.Upld16( OBJID_FGEN_DUTY, 0, cfg.duty );
return err;
}
/***************************************************************************/
/**
Configure the amplifier's analog reference input. Note that some amplifier
models do not support the analog reference.
@param cfg A structure holding the configuration to download
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::SetAnalogRefConfig( AnalogRefConfig &cfg )
{
const Error *err = sdo.Dnld32( OBJID_REF_SCALE, 0, cfg.scale );
if( !err ) err = sdo.Dnld16( OBJID_REF_OFFSET, 0, cfg.offset );
if( !err ) err = sdo.Dnld16( OBJID_REF_CALOFF, 0, cfg.calibration );
if( !err ) err = sdo.Dnld16( OBJID_REF_DEADBAND, 0, cfg.deadband );
return err;
}
/***************************************************************************/
/**
Upload the amplifier's analog reference input configuration.
@param cfg A structure where the configuration parameters will be returned.
@return A pointer to an error object, or NULL on success
*/
/***************************************************************************/
const Error *Amp::GetAnalogRefConfig( AnalogRefConfig &cfg )
{
const Error *err = sdo.Upld32( OBJID_REF_SCALE, 0, cfg.scale );
if( !err ) err = sdo.Upld16( OBJID_REF_OFFSET, 0, cfg.offset );
if( !err ) err = sdo.Upld16( OBJID_REF_CALOFF, 0, cfg.calibration );
if( !err ) err = sdo.Upld16( OBJID_REF_DEADBAND, 0, cfg.deadband );
return err;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -