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

📄 ampparam.cpp

📁 美国COPLEY驱动器,程序开发工具之一.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{
   if( pin < 0 ) return &SDO_Error::Subindex;
   return sdo.Upld16( OBJID_DEBOUNCE, pin+1, value );
}

/***************************************************************************/
/**
  Set the output pin configuration for the specified pin.

  Each of the amplifier output pins can be configured to perform some
  function.  These functions break down into several basic modes:

  - manual mode: In this mode, the output pin will be controlled through the
    CANopen network using the Amp::SetOutputs function.  Output pins can be
    configured to be either active high or active low in this mode.

  - Status word tracking:  In this mode, the output pin is configured to track
    one or more bits of one of the amplifier's internal status words.  A 32-bit
    mask is also supplied which identifies which bits are to be tracked.  If any
    of the selected bits are set in the status word, the output pin will go 
    active.

  - Position trigger.  In this mode the output pin will be configured to go active
    based on the position of the motor.  In some cases the output will go active between
    two programmed positions.  In other cases the output will be triggered by crossing 
    a position and will stay active for a programmed duration.

  @param pin     The output pin to configure.  Output pins are numbered starting
                 from 0.  Check the amplifier datasheet for the number of output pins
                 available.

  @param cfg     The pin function to be assigned to this pin.

  @param param1  A 32-bit parameter used in conjunction with the output pin configuration
                 to define the pin behavior.  For most simple output pin modes this parameter
		 is a bitmask that selects bits in a status register that the output should
		 track.  If the output pin is being configured for manual mode, then the mask 
		 is not used and does not need to be specified.

  @param param2  A second 32-bit parameter used in a few output pin configurations.

  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetOutputConfig( int8 pin, OUTPUT_PIN_CONFIG cfg, uint32 param1, uint32 param2 )
{
   if( pin < 0 ) return &SDO_Error::Subindex;

   uint16 c = (uint16)cfg;
   byte buff[10];

   buff[0] = ByteCast(c);
   buff[1] = ByteCast(c>>8);
   buff[2] = ByteCast(param1);
   buff[3] = ByteCast(param1>>8);
   buff[4] = ByteCast(param1>>16);
   buff[5] = ByteCast(param1>>24);

   // In version 4.77 firmware we added additional data to the output
   // configuration settings.  This allows us to program the outputs
   // with more complex functions
   if( SwVersionNum < VERSION(4,77) )
      return sdo.Download( OBJID_OUTPUT_CFG, pin+1, 6, buff );

   buff[6] = ByteCast(param2);
   buff[7] = ByteCast(param2>>8);
   buff[8] = ByteCast(param2>>16);
   buff[9] = ByteCast(param2>>24);
   return sdo.Download( OBJID_OUTPUT_CFG, pin+1, 10, buff );
}

/***************************************************************************/
/**
  Get the output pin configuration for the specified pin.
  This function supports output pin configurations that require two 
  32-bit parameters.

  @param pin    The output pin to check.
  @param cfg    The pin configuration value will be returned here.
  @param param1 The pin's first 32-bit parameter will be returned here
  @param param2 The pin's second 32-bit parameter will be returned here
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetOutputConfig( int8 pin, OUTPUT_PIN_CONFIG &cfg, uint32 &param1, uint32 &param2 )
{
   if( pin < 0 ) return &SDO_Error::Subindex;

   int32 size = 10;
   byte buff[10];

   const Error *err = sdo.Upload( OBJID_OUTPUT_CFG, pin+1, size, buff );

   cfg = (OUTPUT_PIN_CONFIG)bytes_to_uint16(buff);
   param1 = bytes_to_uint32(&buff[2]);

   if( size > 6 )
      param2 = bytes_to_uint32(&buff[6]);
   else
      param2 = 0;

   return err;
}

/***************************************************************************/
/**
  Get the output pin configuration for the specified pin.

  @param pin The output pin to check.
  @param cfg The pin configuration value will be returned here.
  @param mask The pin's status bit selection mask will be returned here.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetOutputConfig( int8 pin, OUTPUT_PIN_CONFIG &cfg, uint32 &mask )
{
   uint32 mask2;
   return GetOutputConfig( pin, cfg, mask, mask2 );
}

/***************************************************************************/
/**
  Get the output configuration for the specified pin.

  @param pin The output pin to check.
  @param cfg The pin configuration value will be returned here.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetOutputConfig( int8 pin, OUTPUT_PIN_CONFIG &cfg )
{
   uint32 mask1, mask2;
   return GetOutputConfig( pin, cfg, mask1, mask2 );
}

/***************************************************************************/
/**
  Update the state of the manual output pins.  The passed value will
  be written to the output pin control register.  Any of the output pins that 
  have been configured as manual outputs will be updated based on the
  value of this register.

  Bit 0 controls output pin 0, bit 1 sets output pin 1, etc.

  Note that only those output pins that have been configured as manual 
  outputs are effected by this command.  Output pins that are configured to 
  perform some other function (such as tracking bits in the event status register)
  are not effected.  See Amp::SetOutputConfig for details on configuring the 
  amplifier output pins.

  Also note that this pin controls the active/inactive state of the outputs, not
  the high/low state.  Each output pin can be individually configured as active
  high or active low.  Setting a bit in the register to 1 sets the corresponding
  output pin active.  Active high/low configuration is set using Amp::SetOutputConfig.

  @param value The new value to write to the output pin control register.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetOutputs( uint16 value )
{
   return sdo.Dnld16( OBJID_OUTPUTS, 0, value ); 
}

/***************************************************************************/
/**
  Get the present value of the output pin control register.  

  This register shows the current state of all digital output pins.  For each 
  pin, the corresponding bit in the register will be 1 if the pin is active, and
  0 if the pin is inactive.  Bit 0 follows output pin 0, bit 1 follows pin 1, etc.

  @param value variable that will store the returned value
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetOutputs( uint16 &value )
{
   return sdo.Upld16( OBJID_OUTPUTS, 0, value ); 
}

/***************************************************************************/
/**
  Get any active amplifier faults.

  @param value A bit mask identifying the active faults will be returned here.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetFaults( AMP_FAULT &value )
{
   uint32 v;
   const Error *err = sdo.Upld32( OBJID_FAULTS, 0, v );
   value = (AMP_FAULT)v;
   return err;
}

/***************************************************************************/
/**
  Clear amplifier faults.  This function can be used to clear any latching
  faults on the amplifier (see Amp::SetFaultMask for details on latching 
  fault conditions).  It also clears tracking error conditions.

  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::ClearFaults( AMP_FAULT value )
{
   const Error *err = sdo.Dnld32( OBJID_FAULTS, 0, (uint32)value );
   if( err ) return err;

   // I expect the amplifier status to be updated when the faults are
   // cleared.  I'll wait for that update here to make sure my local
   // status is consistant with the drives.
   EventNone e( AMPEVENT_FAULT );
   e.Wait( eventMap, 100 );
   return 0;
}

/***************************************************************************/
/**
  Set the amplifier's fault mask.  The fault mask identifies which conditions
  will be treated as latching faults by the amplifier.  If such a condition
  occurs, the amplifier's output will be disabled immediately, and will not 
  be enabled until the fault condition is cleared.

  @param value A bit mask identifying which fault conditions to latch.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetFaultMask( AMP_FAULT &value )
{
   return sdo.Dnld32( OBJID_FAULT_MASK, 0, (uint32)value );
}

/***************************************************************************/
/**
  Get the current value of the amplifier's fault mask.  This mask identifies
  which error conditions will be treated as latching faults by the amplifier.

  @param value The fault mask will be returned here
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetFaultMask( AMP_FAULT &value )
{
   uint32 v;
   const Error *err = sdo.Upld32( OBJID_FAULT_MASK, 0, v );
   value = (AMP_FAULT)v;
   return err;
}

/***************************************************************************/
/**
  Get the amplifier's 'event status' register.  This is the main register 
  used internal to the amplifier to describe it's current state.

  @param stat The register status is returned here.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetEventStatus( EVENT_STATUS &stat )
{
   uint32 s;
   const Error *err = sdo.Upld32( OBJID_EVENT_STAT, 0, s );
   stat = (EVENT_STATUS)s;
   return err;
}

/***************************************************************************/
/**
  Get the amplifier's 'sticky' event status register.  
  This register is a copy of the amplifiers event status register in which 
  bits are set normally, but only cleared when the register is read (i.e. 
  the bits are 'sticky').  It's useful for checking for transitory events
  which might me missed by reading the standard event status register.

  @param stat The register status is returned here.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetEventSticky( EVENT_STATUS &stat )
{
   uint32 s;
   const Error *err = sdo.Upld32( OBJID_EVENT_STAT_STICKY, 0, s );
   stat = (EVENT_STATUS)s;
   return err;
}

/***************************************************************************/
/**
  Get the amplifier's latched event status register.
  This register is a copy of the normal event status register in which bits 
  are latched, i.e. they are set bit not cleared.  Bits in this register 
  are only cleared in response to a Amp::ClearEventLatch function call (which
  is protected by the Amp object).  This register is primarily used internally
  by the Amp object to detect reset conditions on the amplifier.

  @param stat The register status is returned here.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetEventLatch( EVENT_STATUS &stat )
{
   uint32 s;
   const Error *err = sdo.Upld32( OBJID_EVENT_STAT_LATCH, 0, s );
   stat = (EVENT_STATUS)s;
   return err;
}

/***************************************************************************/
/**
  Clear the latched version of the amplifier's event status register.  This
  function is protected and generally only intended for internal use.

  @param stat Identifies which bits to clear.  Any bit set in this parameter
  will be cleared in the latched event status register.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::ClearEventLatch( EVENT_STATUS stat )
{
   return sdo.Dnld32(  OBJID_EVENT_STAT_LATCH, 0, (uint32)stat );
}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
   HOMING MODE
   */
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

⌨️ 快捷键说明

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