⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ampstruct.cpp

📁 美国COPLEY驱动器,程序开发工具之一.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  Get the configuration values of the amplifiers position loop.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetPosLoopConfig( PosLoopConfig &cfg )
{
   const Error *err = sdo.Upld16( OBJID_POSLOOP, 1, cfg.kp );
   if( !err ) err = sdo.Upld16( OBJID_POSLOOP, 2, cfg.kvff );
   if( !err ) err = sdo.Upld16( OBJID_POSLOOP, 3, cfg.kaff );

   // This parameter was added in firmware version 3.30
   if( !err )
   {
      if( SwVersionNum >= VERSION(3,30) )
	 err = sdo.Upld16( OBJID_POSLOOP, 4, cfg.scale );
      else
	 cfg.scale = 100;
   }

   return err;
}

/***************************************************************************/
/**
  Update the amplifier's position loop configuration.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetPosLoopConfig( PosLoopConfig &cfg )
{
   const Error *err = sdo.Dnld16( OBJID_POSLOOP, 1, cfg.kp );
   if( !err ) err = sdo.Dnld16( OBJID_POSLOOP, 2, cfg.kvff );
   if( !err ) err = sdo.Dnld16( OBJID_POSLOOP, 3, cfg.kaff );

   // This parameter was added in firmware version 3.30
   if( !err )
   {
      if( SwVersionNum >= VERSION(3,30) )
	 err = sdo.Dnld16( OBJID_POSLOOP, 4, cfg.scale );
   }

   return err;
}

/***************************************************************************/
/**
  Get the configuration values of the amplifiers velocity loop.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetVelLoopConfig( VelLoopConfig &cfg )
{
   int32 maxVel, maxAcc, maxDec, eStop;

   const Error *err = sdo.Upld16( OBJID_VELLOOP, 1, cfg.kp );
   if( !err ) err = sdo.Upld16( OBJID_VELLOOP, 2, cfg.ki );
   if( !err ) err = sdo.Upld16( OBJID_VELLOOP, 3, cfg.kaff );
   if( !err ) err = sdo.Upld16( OBJID_VELLOOP, 4, cfg.shift );
   if( !err ) err = sdo.Upld32( OBJID_VELLIM_MAXACC, 0, maxAcc );
   if( !err ) err = sdo.Upld32( OBJID_VELLIM_MAXDEC, 0, maxDec );
   if( !err ) err = sdo.Upld32( OBJID_VELLIM_ESTOP,  0, eStop  );
   if( !err ) err = sdo.Upld32( OBJID_VELLIM_MAXVEL, 0, maxVel );

   // Convert the velocity and accelerations from internal units to user
   // units.  Note that these acceleration values are not in standard
   // amplifier units of 10 cts/sec^2.  Rather, they are in 1000 cts/sec^2.
   // We'll adjust for this here.
   cfg.maxVel = VelMtr2User( maxVel );
   cfg.maxAcc = AccMtr2User( maxAcc * 100 );
   cfg.maxDec = AccMtr2User( maxDec * 100 );
   cfg.estopDec = AccMtr2User( eStop * 100 );

   return err;
}

/***************************************************************************/
/**
  Update the amplifier's velocity loop configuration.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetVelLoopConfig( VelLoopConfig &cfg )
{
   // Convert from user unit acceleration and velocity
   // values to internal amplifier units.
   int32 maxAcc   = AccUser2Mtr(cfg.maxAcc);
   int32 maxDec   = AccUser2Mtr(cfg.maxDec);
   int32 estopDec = AccUser2Mtr(cfg.estopDec);
   int32 maxVel   = VelUser2Mtr(cfg.maxVel);

   // Note that these accelerations are not in the standard
   // 10 ct/sec^2 units, but rather in 1000 ct/sec^2 units.
   // I'll adjust for that here.
   maxAcc   = (maxAcc+50) / 100;
   maxDec   = (maxDec+50) / 100;
   estopDec = (estopDec+50) / 100;

   const Error *err = sdo.Dnld16( OBJID_VELLOOP, 1, cfg.kp );
   if( !err ) err = sdo.Dnld16( OBJID_VELLOOP, 2, cfg.ki );
   if( !err ) err = sdo.Dnld16( OBJID_VELLOOP, 3, cfg.kaff );
   if( !err ) err = sdo.Dnld16( OBJID_VELLOOP, 4, cfg.shift );
   if( !err ) err = sdo.Dnld32( OBJID_VELLIM_MAXACC, 0, maxAcc   );
   if( !err ) err = sdo.Dnld32( OBJID_VELLIM_MAXDEC, 0, maxDec   );
   if( !err ) err = sdo.Dnld32( OBJID_VELLIM_ESTOP,  0, estopDec );
   if( !err ) err = sdo.Dnld32( OBJID_VELLIM_MAXVEL, 0, maxVel   );
   return err;
}

/***************************************************************************/
/**
  Get the configuration values of the amplifiers current loop.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetCrntLoopConfig( CrntLoopConfig &cfg )
{
   const Error *err = sdo.Upld16( OBJID_CRNTLOOP, 1, cfg.kp );
   if( !err ) err = sdo.Upld16( OBJID_CRNTLOOP, 2, cfg.ki );
   if( !err ) err = sdo.Upld16( OBJID_CRNTLOOP, 3, cfg.offset );
   if( !err ) err = sdo.Upld16( OBJID_CRNTLIM_PEAK, 0, cfg.peakLim );
   if( !err ) err = sdo.Upld16( OBJID_CRNTLIM_CONT, 0, cfg.contLim );
   if( !err ) err = sdo.Upld16( OBJID_CRNTLIM_TIME, 0, cfg.peakTime );

   // the following configuration values were added in firmware version 3.10
   if( SwVersionNum >= VERSION(3,10) )
   {
      // Upload the remaining parameters directly into the output structure
      if( !err ) err = sdo.Upld16( OBJID_USTEP_HOLDCRNT, 0, cfg.stepHoldCurrent  );
      if( !err ) err = sdo.Upld16( OBJID_USTEP_HOLDTIME, 0, cfg.stepRun2HoldTime );
      if( !err ) err = sdo.Upld16( OBJID_USTEP_VOLTIME, 0, cfg.stepVolControlDelayTime );
   }

   if( !err && (SwVersionNum >= VERSION(4,60) ) )
      err = sdo.Upld32( OBJID_CRNT_SLOPE, 0, cfg.slope );
   return err;
}

/***************************************************************************/
/**
  Update the amplifier's current loop configuration.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetCrntLoopConfig( CrntLoopConfig &cfg )
{
   const Error *err = sdo.Dnld16( OBJID_CRNTLOOP, 1, cfg.kp );
   if( !err ) err = sdo.Dnld16( OBJID_CRNTLOOP, 2, cfg.ki );
   if( !err ) err = sdo.Dnld16( OBJID_CRNTLOOP, 3, cfg.offset );
   if( !err ) err = sdo.Dnld16( OBJID_CRNTLIM_PEAK, 0, cfg.peakLim );
   if( !err ) err = sdo.Dnld16( OBJID_CRNTLIM_CONT, 0, cfg.contLim );
   if( !err ) err = sdo.Dnld16( OBJID_CRNTLIM_TIME, 0, cfg.peakTime );

   // the following configuration values were added in firmware version 3.10
   if( SwVersionNum >= VERSION(3,10) )
   {
      if( !err ) err = sdo.Dnld16( OBJID_USTEP_HOLDCRNT, 0, cfg.stepHoldCurrent  );
      if( !err ) err = sdo.Dnld16( OBJID_USTEP_HOLDTIME, 0, cfg.stepRun2HoldTime );
      if( !err ) err = sdo.Dnld16( OBJID_USTEP_VOLTIME, 0, cfg.stepVolControlDelayTime );
   }

   if( !err && (SwVersionNum >= VERSION(4,60) ) )
      err = sdo.Dnld32( OBJID_CRNT_SLOPE, 0, cfg.slope );

   return err;
}


/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
   Tracking windows (position & velocity)
   */
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

/***************************************************************************/
/**
  Default constructor for tracking window structure.  This simply sets all
  tracking window parameter default values of zero.
  */
/***************************************************************************/
TrackingWindows::TrackingWindows( void )
{
   trackErr     = 0;
   trackWarn    = 0;
   settlingWin  = 0;
   settlingTime = 0;
   velWarnWin   = 0;
   velWarnTime  = 0;
}

/***************************************************************************/
/**
  Update the amplifier's tracking window configuration.  This function allows
  all tracking window parameters to be configured with one function call.
  @param cfg A structure that holds the configuration settings.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetTrackingWindows( TrackingWindows &cfg )
{
   const Error *err = SetPositionErrorWindow( cfg.trackErr );
   if( !err ) err = SetPositionWarnWindow( cfg.trackWarn );
   if( !err ) err = SetSettlingWindow( cfg.settlingWin );
   if( !err ) err = SetSettlingTime( cfg.settlingTime );
   if( !err ) err = SetVelocityWarnWindow( cfg.velWarnWin );
   if( !err ) err = SetVelocityWarnTime( cfg.velWarnTime );
   return err;
}

/***************************************************************************/
/**
  Get the configuration values of the amplifiers position & velocity 
  tracking windows.  This function allows all tracking window paramters
  to be read from the amplifier as a group.
  @param cfg A structure that will be filled with the config info.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetTrackingWindows( TrackingWindows &cfg )
{
   const Error *err = GetPositionErrorWindow( cfg.trackErr );
   if( !err ) err = GetPositionWarnWindow( cfg.trackWarn );
   if( !err ) err = GetSettlingWindow( cfg.settlingWin );
   if( !err ) err = GetSettlingTime( cfg.settlingTime );
   if( !err ) err = GetVelocityWarnWindow( cfg.velWarnWin );
   if( !err ) err = GetVelocityWarnTime( cfg.velWarnTime );
   return err;
}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
   Software limit switch configuration.
   */
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

/***************************************************************************/
/**
  Set software limit switch settings.  The amplifier's software limit settings
  consist of a positive and negative absolute position.  Any time the motors
  actual position is greater then the positive limit, or less then the negative
  limit, a limit event occurs.  Software limit events are treated by the amplifer
  in the same way that physical limit switches are, no current will be output 
  in the direction of the limit switch, and any running trajectory will be 
  aborted.

  Software limit switches are not used until the amplifier has been homed.  Also,
  if the positive software limit is set to a value greater then or equal to the
  negative software limit, then the limits are disabled.

  @param cfg The limit switch settings to use
  @return A pointer to an error object, or NULL on success.
  */
/***************************************************************************/
const Error *Amp::SetSoftLimits( SoftPosLimit &cfg )
{
   int32 p = PosUser2Load( cfg.pos );
   int32 n = PosUser2Load( cfg.neg );
   int32 a = AccUser2Load( cfg.accel );

   const Error *err = sdo.Dnld32( OBJID_SOFTLIM, 1, n );
   if( !err ) err = sdo.Dnld32( OBJID_SOFTLIM, 2, p );

   // Software limit acceleration was added in version 4.60
   if( !err && (SwVersionNum >= VERSION(4,60) ) )
      err = sdo.Dnld32( OBJID_SOFTLIM_ACCEL, 0, a );

   return err;
}

/***************************************************************************/
/**
  Upload the current software limit switch settings from the amplifier
  @param cfg The limit switch settings will be returned in this structure.
  @return A pointer to an error object, or NULL on success.
  */
/***************************************************************************/
const Error *Amp::GetSoftLimits( SoftPosLimit &cfg )
{
   int32 p, n;
   int32 a = 0;

   const Error *err = sdo.Upld32( OBJID_SOFTLIM, 1, n );

   if( !err )
      err = sdo.Upld32( OBJID_SOFTLIM, 2, p );

   if( !err && (SwVersionNum >= VERSION(4,60) ) )
      err = sdo.Upld32( OBJID_SOFTLIM_ACCEL, 0, a );

   cfg.pos = PosLoad2User( p );
   cfg.neg = PosLoad2User( n );
   cfg.accel = AccLoad2User( a );

   return err;
}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -