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

📄 cml_amp.h

📁 美国COPLEY驱动器,程序开发工具之一.
💻 H
📖 第 1 页 / 共 3 页
字号:
/************************************************************/
/*                                                          */
/*  Copley Motion Libraries                                 */
/*                                                          */
/*  Author: Stephen Glow                                    */
/*                                                          */
/*  Copyright (c) 2002-2005 Copley Controls Corp.           */
/*                          http://www.copleycontrols.com   */
/*                                                          */
/************************************************************/

/** \file

This file defines the Copley Amplifier object.  This object may be
used to interface to an amplifier over the CANopen network.

*/

#ifndef _DEF_INC_COPLEYAMP
#define _DEF_INC_COPLEYAMP

#include "CML_Settings.h"
#include "CML_AmpDef.h"
#include "CML_AmpStruct.h"
#include "CML_CanOpen.h"
#include "CML_EventMap.h"
#include "CML_Copley.h"
#include "CML_PDO.h"
#include "CML_Trajectory.h"

CML_NAMESPACE_START()

/***************************************************************************/
/**
This class represents error conditions that can occur in the Copley Amplifier
object.
*/
/***************************************************************************/
class AmpError: public NodeError
{
public:
   static const AmpError Fault;         ///< Latching fault is active
   static const AmpError ShortCircuit;  ///< Short circuit detected
   static const AmpError AmpTemp;       ///< Amplifier over temp.
   static const AmpError OverVolt;      ///< Amplifier over voltage
   static const AmpError UnderVolt;     ///< Amplifier under voltage
   static const AmpError MotorTemp;     ///< Motor over temp.
   static const AmpError EncoderPower;  ///< Encoder power error
   static const AmpError PhaseErr;      ///< Motor phasing error
   static const AmpError TrackErr;      ///< Position tracking error
   static const AmpError NodeState;     ///< The drive's state is inappropriate for the requested operation
   static const AmpError pvtSegPos;     ///< PVT segment position value over 24-bits
   static const AmpError pvtSegVel;     ///< PVT segment velocity value too large        
   static const AmpError pvtBufferFull; ///< PVT trajectory buffer full
   static const AmpError badDeviceID;   ///< Unknown device identity
   static const AmpError badHomeParam;  ///< Bad parameter specified to home command
   static const AmpError badMoveParam;  ///< Bad parameter specified to move command
   static const AmpError InMotion;      ///< Amplifier is currently in motion
   static const AmpError GuardError;    ///< The amplifier's heartbeat message timed out
   static const AmpError PosLim;        ///< Positive limit switch is active
   static const AmpError NegLim;        ///< Negative limit switch is active
   static const AmpError PosSoftLim;    ///< Positive software limit is active
   static const AmpError NegSoftLim;    ///< Negative software limit is active
   static const AmpError TrackWarn;     ///< Position tracking warning
   static const AmpError Unknown;       ///< An error occurred, but went away before it could be decoded.
   static const AmpError Reset;         ///< The amplifier has been reset.
   static const AmpError Disabled;      ///< The amplifier is disabled
   static const AmpError QuickStopMode; ///< The amplifier is doing a quick stop
   static const AmpError NoUserUnits;   ///< User units are not available (see CML_Settings.h)
   static const AmpError Abort;         ///< Last trajectory aborted
   static const AmpError pvtPosUnavail; ///< The PVT segment position is not available.
   static const AmpError VelWin;        ///< Velocity tracking window exceeded

   static const AmpError *DecodeStatus( EVENT_STATUS stat );
protected:
   /// Standard protected constructor
   AmpError( uint16 id, const char *desc ): NodeError( id, desc ){}
};

/***************************************************************************/
/**
This class represents latching amplifier fault conditions.  
*/
/***************************************************************************/
class AmpFault: public AmpError
{
public:
   static const AmpFault Memory;         ///< Fatal hardware error: the flash data is corrupt.         
   static const AmpFault ADC;            ///< Fatal hardware error: An A/D offset error has occurred.  
   static const AmpFault ShortCircuit;   ///< The amplifier detected a short circuit condition         
   static const AmpFault AmpTemp;        ///< The amplifier is over temperature                        
   static const AmpFault MotorTemp;      ///< A motor temperature error was detected                   
   static const AmpFault OverVolt;       ///< The amplifier bus voltage is over the acceptable limit   
   static const AmpFault UnderVolt;      ///< The amplifier bus voltage is below the acceptable limit  
   static const AmpFault EncoderPower;   ///< Over current on the encoder power supply                 
   static const AmpFault PhaseErr;       ///< Amplifier phasing error                                  
   static const AmpFault TrackErr;       ///< Tracking error, the position error is too large.         
   static const AmpFault I2TLimit;       ///< Current limited by I^2 algorithm.         
   static const AmpFault Unknown;		  ///< Some unknown amplifier fault has occurred

   static const AmpFault *DecodeFault( AMP_FAULT f );
protected:
   /// Standard protected constructor
   AmpFault( uint16 id, const char *desc ): AmpError( id, desc ){}
};

/***************************************************************************/
/**
Transmit PDO used to send out status word updates.
*/
/***************************************************************************/
class TPDO_Status: public TPDO
{
   class Amp *ampPtr;                ///< Points to the amplifier to which this PDO belongs
public:
   Pmap16 status;                    ///< Used to map the CAN status word passed in the PDO
   Pmap32 estat;                     ///< Used to map the 'event status' word to the PDO
   Pmap16 inputs;

   /// Default constructor for this PDO
   TPDO_Status(){}
   const Error *Init( Amp &amp, uint16 slot );
   virtual void Received( void );
private:
   void UpdateEvents( uint16 stat, uint32 events, uint16 inputs );
};

/***************************************************************************/
/**
Transmit PDO used to send out PVT buffer status updates
*/
/***************************************************************************/
class TPDO_PvtBuffStat: public TPDO
{
   class Amp *ampPtr;                ///< Points to the amplifier to which this PDO belongs
   Pmap32 stat;                      ///< Used to map the PVT buffer status information
   uint8 ct;

public:
   /// Default constructor for this PDO
   TPDO_PvtBuffStat(){}
   const Error *Init( Amp &amp, uint16 slot );
   virtual void Received( void );
};

/***************************************************************************/
/**
Receive PDO used to send PVT segments to the amplifier
*/
/***************************************************************************/
class RPDO_Pvt: public RPDO
{
   class Amp *ampPtr;                ///< Points to the amplifier to which this PDO belongs
   PmapRaw dat;                      ///< Used to map PVT buffer information passed to the amplifier

public:
   /// Default constructor for this PDO
   RPDO_Pvt(){}

   const Error *Init( Amp &amp, uint16 slot );

   const Error *Transmit( byte *data );
};

/***************************************************************************/
/**
Copley amplifier settings object.  This object is passed to the Init() 
method of the Copley amp.  It holds the various customizable settings 
used by the amplifier.  
*/
/***************************************************************************/
class AmpSettings
{
public:
   /// Create a settings object with all default values.
   /// The default values for each member of this class are defined below.
   AmpSettings();

   /// Synch object period in microseconds.
   /// The synch object is a message that is transmitted by one node on a 
   /// CANopen network at a fixed interval.  This message is used to 
   /// synchronize the devices on the network.
   ///
   /// Default is 10,000 (10 ms).
   uint32 synchPeriod;

   /// Synch object CAN message ID.
   /// This is the message ID used for the synch message.
   /// Default is 0x00000080
   uint32 synchID;

   /// Use first initialized amplifier as synch producer.
   /// If this setting is true (default), then the first amplifier
   /// to be initialized will be set as the synch producer, and
   /// all other amplifier's will be setup as synch consumers.
   /// This causes the value of the 'synchProducer' setting
   /// to be updated during init to indicate whether the amp
   /// is producing synch messages or not.
   ///
   /// By default, this setting is true
   bool synchUseFirstAmp;

   /// Synch producer (true/false)
   /// If true, this node will produce synch messages.
   /// Default: false
   ///
   /// Note: If the 'synchUseFirstAmp' setting of this object is true,
   ///       then the passed value of this settings will not be used, 
   ///       and will be overwritten during initialization.
   ///
   /// Note: There should be exactly one synch producer on every network.
   bool synchProducer;

   /// High resolution time stamp CAN ID.  The high resolution time stamp
   /// is a PDO that is generated by the synch producer and consumed by 
   /// the other amplifiers on the network.  It is used to synchronize the
   /// clocks of the amplifiers.  This parameter defines the CAN ID that
   /// will be used for this message.
   /// Setting to zero will disable the time stamp message.
   /// Default 0x0180
   uint32 timeStampID;

   /// The CANopen heartbeat protocol is one of two standard methods used
   /// to constantly watch for network or device problems.  
   /// When the heartbeat protocol is used, each device on the CANopen
   /// network transmits a 'heartbeat' message at a specified interval.
   /// The network master watches for these messages, and is able to 
   /// detect a device error if it's heartbeat message is not received
   /// within the expected time.
   ///
   /// This parameter configures the heartbeat period (milliseconds)
   /// that will be used by this amplifier to transmit it's heartbeat
   /// message.
   ///
   /// If this parameter is set to zero, then the heartbeat protocol
   /// is disabled on this node.
   ///
   /// Default: zero (not used)
   uint16 heartbeatPeriod;

   /// Additional time to wait before generating a heartbeat error (milliseconds)
   /// If the heartbeat protocol is used, then this value, combined with the
   /// heartbeatTime will determine how long the network master waits for the
   /// node's heartbeat message before it generates a heartbeat error.
   ///
   /// Note that setting this to zero does not disable the heartbeat protocol.
   /// set the heartbeatPeriod value to zero to disable heartbeat.
   ///
   /// Default 200 (ms)
   uint16 heartbeatTimeout;

   /// Node guarding guard time (milliseconds)
   ///
   /// The CANopen node guarding protocol is a second method (the first being the
   /// heartbeat protocol) for devices on the network to watch for network problems.
   /// In this protocol, the master controller sends a request message out to the 
   /// slave device at a specified interval.  The slave device responds to this 
   /// request with a message indicating it's state.
   ///
   /// The main difference between this protocol and the heartbeat protocol is that
   /// both the slave node and the master are able to recognize network errors.
   /// With the heartbeat protocol only the network master is able to identify 
   /// network problems.
   ///
   /// Note that only one of these two protocols can be active in a node device at
   /// any time.  If the heartbeat period is non-zero, then the heartbeat protocol
   /// will be used.
   ///
   /// This parameter gives the node guarding period for use with this node.  This
   /// is the period between node guarding request messages sent by the master 
   /// controller.
   ///
   /// Note that both this parameter, and the life time factor must be non-zero for
   /// node guarding to be used.
   ///
   /// Default 200 (ms)
   uint16 guardTime;

   /// Node guarding life time factor
   ///
   /// When the node guarding protocol is used, this parameter is used by the slave
   /// device to determine how long to wait for a node guarding request from the 
   /// master controller before signaling an error condition.
   ///
   /// The life time factor is treated as a multiple of the guard time.  
   ///
   /// If this parameter and the node guard time are both non-zero,
   /// and the heartbeatTime is zero, then node guarding will be setup 
   /// for the amplifier.
   ///
   /// Default 3 (multiples of the guard time)
   uint8 lifeFactor;

   /// Enable amplifier at init time.  If this is true, then the amplifier
   /// will be enabled at the end of a successful init().  If false, the 
   /// amplifier will be disabled when init() returns.
   ///
   /// Default: true
   bool enableOnInit;

   /// Initial mode of operation.  This defines the mode of operation that the
   /// amplifier will be placed in when it is initialized.
   ///
   /// Default: AMPMODE_CAN_HOMING
   AMP_MODE initialMode;

   /// Reset the amplifier on init.  If true, the amplifier will be reset 
   /// when it is initialized.  This has the advantage of clearing out any
   /// fault conditions and putting the amplifier in a known state.
   ///
   /// Default: false
   bool resetOnInit;

   /// Max PVT segments to send in response to a PVT status update.  This
   /// parameter may be used to limit the number of new PVT segments to send
   /// in response to a PVT status update.  Normally, this parameter may be
   /// safely left at it's default setting.
   ///
   /// Default 6
   uint8 maxPvtSendCt;
};

/***************************************************************************/
/**
PVT trajectory segment cache object.  This is used internally by the Amp
object to keep track of PVT segments recently sent.  It allows the amp object
to recover if a segment is lost in transit by resending the missing segments.
*/
/***************************************************************************/
class PvtSegCache
{
   #define PVTCACHESIZE  32
public:
   /// Default constructor.  Clears the cache.
   PvtSegCache(){ Clear(); }

   /// Clear the cache
   void Clear(){ ct = top = 0; }

   void AddSegment( uint8 *seg, uint16 id, uunit p );
   bool GetSegment( uint8 *seg, uint16 id );
   bool GetPosition( uunit *p, uint16 id );

⌨️ 快捷键说明

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