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

📄 cml_linkage.h

📁 美国COPLEY驱动器,程序开发工具之一.
💻 H
📖 第 1 页 / 共 2 页
字号:
/**
Linkage object, used for controlling a group of coordinated amplifiers.
*/
/***************************************************************************/
class Linkage: public Thread
{
public:
   Linkage();
   virtual ~Linkage();

   const Error *Init( uint16 ct, Amp a[] );
   const Error *Init( uint16 ct, Amp *a[] );
   const Error *Configure( LinkSettings &settings );

   Amp &GetAmp( uint16 i );

   const Error *MoveTo( PointN &p, uunit vel, uunit acc, uunit dec, uunit jrk, bool start=true );
   const Error *SetMoveLimits( uunit vel, uunit acc, uunit dec, uunit jrk );
   const Error *GetMoveLimits( uunit &vel, uunit &acc, uunit &dec, uunit &jrk );
   const Error *MoveTo( PointN &p, bool start=true );
   const Error *StartMove( void );
   const Error *WaitMoveDone( int32 timeout=-1 );
   const Error *WaitEvent( Event &e, int32 timeout, LINK_EVENT &match );
   const Error *WaitEvent( Event &e, int32 timeout=-1 );
   const Error *HaltMove( void );

   const Error *SendTrajectory( LinkTrajectory &trj, bool start=true );

   /// Return any latched error codes held by the linkage object.
   /// When an error occurs during a move, the linkage latches the first
   /// error to occure and the index of the amplifier that caused it.
   ///
   /// Note that the latched error information will be reset automatically
   /// at the start of any new move. 
   /// 
   /// @param amp The index of the amplifier producing the latched error
   /// will be returned.  -1 will be returned if the amplifier is unknown.
   /// @return A pointer to the latched error object, or NULL if no error
   /// was latched.
   const Error *GetLatchedError( int &amp )
   {
      amp = latchedErrAmp;
      return latchedErr;
   }

   /// Clear any latched errors.  This function clears the latched error
   /// information returned by Linkage::GetLatchedError().
   /// Latched errors are automatically cleared at the start of a new move.  
   /// This call may be used to clear latched error information at any other time.
   void ClearLatchedError( void )
   {
      latchedErrAmp = -1;
      latchedErr = 0;
   }

   /// Return a reference to the specified amplifier object 
   /// in this linkage.  This is the same as Linkage::GetAmp
   /// @param i The amplifier index location
   /// @return A reference to the amp object
   Amp &operator[]( uint16 i )
   {
      return GetAmp(i);
   }

   /// Return the number of amplifiers associated with this linkage
   /// @return The amplifier count.
   uint16 GetAmpCount( void )
   {
      return ampct;
   }

   /// Return the number of independent axes associated with this linkage.
   /// For a standard Linkage object, this will be the same as the amp count,
   /// however, this function is virtual to allow more complex structures to
   /// be represented in sub-classes.
   /// @return The number of independent axes for this Linkage.
   virtual uint16 GetAxesCount( void )
   {
      return ampct;
   }

   const Error *GetPositionCommand( PointN &p );

   /// Convert the linkage position from the amplifier frame to the axis frame.
   /// The passed array contains a position for each amplifer on entry.  These
   /// positions should be converted to axis positions in this function.  By 
   /// default, this function doesn't do anything, however it is a virtual 
   /// function to allow it to be extended in sub-classes.
   /// @param pos An array of amplifer positions on entry, and axes positions
   ///            on exit.
   /// @return NULL on success or an Error pointer on failure.
   virtual const Error *ConvertAmpToAxisPos( uunit pos[] ){ return 0; }

   /// Convert the linkage position from the axis frame to the amplifier frame.
   /// The passed array contains a position for each axis on entry.  These
   /// positions should be converted to amplifier positions in this function.  By 
   /// default, this function doesn't do anything, however it is a virtual 
   /// function to allow it to be extended in sub-classes.
   /// @param pos An array of axis positions on entry, and amp positions
   ///            on exit.
   /// @return NULL on success or an Error pointer on failure.
   virtual const Error *ConvertAxisToAmpPos( uunit pos[] ){ return 0; }

   /// Convert position & velocity information from the amplifier frame to the
   /// axis frame.
   ///
   /// The passed arrays contain a position and velocity for each amplifer on entry.
   /// These values should be converted to axis positions & velocities in this function.
   ///
   /// By default, this function doesn't do anything, however it is a virtual 
   /// function to allow it to be extended in sub-classes.
   /// @param pos An array of amplifer positions on entry, and axes positions
   ///            on exit.
   /// @param vel An array of amplifier velocities on entry, and axis velocities
   ///            on exit.
   /// @return NULL on success or an Error pointer on failure.
   virtual const Error *ConvertAmpToAxis( uunit pos[], uunit vel[] ){ return 0; }

   /// Convert position & velocity information from the axis frame to the amplifier frame.
   ///
   /// The passed arrays contain a position and velocity for each axis on entry.
   /// These values should be converted to amp positions & velocities in this function.
   ///
   /// By default, this function doesn't do anything, however it is a virtual 
   /// function to allow it to be extended in sub-classes.
   /// @param pos An array of axis positions on entry, and amplifier positions
   ///            on exit.
   /// @param vel An array of axis velocities on entry, and amplifier velocities
   ///            on exit.
   /// @return NULL on success or an Error pointer on failure.
   virtual const Error *ConvertAxisToAmp( uunit pos[], uunit vel[] ){ return 0; }

   /// This is an event map that is used to track linkage
   /// events and state changes
   EventMap eventMap;

private:
   LinkSettings cfg;
   RPDO_LinkCtrl ctrlPDO;
   uint16 ampct;
   Amp *amp[ CML_MAX_AMPS_PER_LINK ];
   uunit maxVel, maxAcc, maxDec, maxJrk;
   Semaphore startSema;

#ifdef CML_ALLOW_FLOATING_POINT
   LinkTrjScurve scurve;
#endif

   int latchedErrAmp;
   const Error *latchedErr;

   const Error *LatchError( const Error *err, int ndx );

   void CheckIndex( uint16 i );

#ifdef CML_LINKAGE_TRJ_BUFFER_SIZE
   /// Utility class used internally by the linkage object
   class AmpTrj: public Trajectory
   {
      Linkage *linkPtr;
      uint8 ampNum, head, tail;
      bool inUse;
      uunit p[ CML_LINKAGE_TRJ_BUFFER_SIZE ];
      uunit v[ CML_LINKAGE_TRJ_BUFFER_SIZE ];
      uint8 t[ CML_LINKAGE_TRJ_BUFFER_SIZE ];
      bool  u[ CML_LINKAGE_TRJ_BUFFER_SIZE ];

   public:
      void Init( Linkage *lptr );
      const Error *StartNew( void );
      void Finish( void );
      bool UseVelocityInfo( void );
      const Error *NextSegment( uunit &pos, uunit &vel, uint8 &time );
      const Error *AddPoint( uunit pos, uunit vel, uint8 time, bool useVel );
   };
   friend class AmpTrj;

   const Error *RequestNextTrjPoint( void );

   LinkTrajectory *linkTrjPtr;
   AmpTrj ampTrj[ CML_MAX_AMPS_PER_LINK ];
#endif

   /// Utility class used to keep the linkage status up to date
   /// as the status of it's amplifiers change.
   class StateEvent: public Event
   {
      public:
	 Linkage *link;
	 StateEvent( void ): Event(0){}
	 bool isTrue( uint32 mask );
   };
   friend class StateEvent;
   StateEvent stateEvent[ CML_MAX_AMPS_PER_LINK ];

   int trjUseCount;
   const Error *IncTrjUseCount( void );
   const Error *DecTrjUseCount( void );
   const Error *SetControlWord( uint16 value );
   const Error *GetError( uint32 mask );
   void run( void );

   void UpdateStatus( void );

   void InvalidateAmp( Amp *a );
   friend class Amp;
};

CML_NAMESPACE_END()
#endif

⌨️ 快捷键说明

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