You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mitlib.pub/MITLIB/IODll/MotorBase.h

441 lines
14 KiB
C

// MotorBase.h: interface for the CMotorBase class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MOTORBASE_H__04B8BC9A_5FF9_4E00_BA08_FDEC856015F1__INCLUDED_)
#define AFX_MOTORBASE_H__04B8BC9A_5FF9_4E00_BA08_FDEC856015F1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Motor.h"
#ifdef BUILD_IODLL
#define IODLLCLASS __declspec(dllexport)
#else
#define IODLLCLASS __declspec(dllimport)
#endif
class IODLLCLASS CMotorBase : public CMtrPos, public CCard, public CMtrOnOff, public CMyWait
{
public:
CMotorBase();
CMotorBase(const char* cpMutexName, CMtrProfile mtrProfile, double *dpPos);
virtual ~CMotorBase();
//**************************************************************
// Virtual Methods declaration
//**************************************************************
// method to close the axis
virtual void CloseAxis();
// method to initialize and configure the axis
virtual void ConstructAxis(CMtrProfile mtrProfile);
// method to On/Off motor
virtual int OnMtr(bool bOn);
// method to stop motor with decceleration
virtual int DecStop();
// method to trigger Emergency stop the motor virtual int EStop();
virtual int EStop();
// virtual method to get commanded position
virtual double GetCommandPosition();
// virtual method to get the motor axis IO status
virtual int GetMotionIOStatus();
// virtual method to get the Motor Ready Status
virtual BOOL IsMotorReady();
// virtual method to get the Motor Alarm Status
virtual BOOL IsMotorAlarm();
// virtual method to get the Motor Negative/CCW Limit Status
virtual BOOL IsNegLmtHit();
// virtual method to get the Motor Positive/CW Limit Status
virtual BOOL IsPosLmtHit();
// virtual method to get the Motor Home Sensor Status
virtual BOOL IsHomed();
// virtual method to check if the Motor is TURN ON
virtual bool IsMtrOn();
// virtual method Check other axis home sensor
virtual BOOL IsHomed(CMtrProfile mtrProfile);
// virtual method to get other motor axis IO status
virtual int GetMotionIOStatus(CMtrProfile mtrProfile);
// virtual method to get Other axis motor ready status
virtual BOOL IsMotorReady(CMtrProfile mtrProfile);
// virtual method to get Other axis Alarm status
virtual BOOL IsMotorAlarm(CMtrProfile mtrProfile);
// virtual method to get Other axis negative/ccw limit status
virtual BOOL IsNegLmtHit(CMtrProfile mtrProfile);
// virtual method to get Other axis positive/cw limit status
virtual BOOL IsPosLmtHit(CMtrProfile mtrProfile);
// virtual method to get Other axis home sensor status
virtual bool IsMtrOn(CMtrProfile mtrProfile);
// virtual method to get other motor axis current position
virtual double GetOtherAxisPosition(CMtrProfile mtrProfile);
// virtual method to get motor axis current position error
virtual double GetPosErr();
// virtual method to get the current motor position
virtual double GetPosition();
// virtual method to do homing by limit sensor
virtual bool HomingByLimit();
// virtual method to do homing by sensor as well as index
virtual BOOL HomeBySensorAndIndex();
// virtual method to do homing by index signal
virtual BOOL HomeByIndex();
// virtual method to do homing by Home Sensor
virtual BOOL HomeBySensor();
// virtual method to move absolute
virtual int MoveAbs(double dPosition, int nPos=-1, int nMode=0);
// virtual method to move continuously
virtual int MoveContinuously(bool bCW=true);
// virtual method to move relative distance
virtual int MoveRel(double dDistance, int nPos=-1);
// virtual method to process interrupt to decode what happen to the motor
virtual void ProcessInt(int nIntCode=0);
// virtual method to reset single trigger
virtual int ResetSingleTrigger();
// virtual method to set the commanded position register
virtual int SetCommandPosition(double dPosition);
// virtual method to set the mechanical coversion factor
virtual int SetConversionFactor(double dUPR, double dPPR, double dEPPR);
// virtual method to set homing modes
virtual int SetHomeMode(int iHomeMode);
// virtual method to set multiple trigger
virtual int SetMultipleTrigger(double dStartPosition, double dStopPosition, double dIntervalDistance, int nNoOfTrigger, int nCmpSource=1);
// virtual method to force set the current position
virtual int SetPosition(double dPosition);
// virtual method to arm controller axis for single trigger
virtual int SetSingleTrigger(double dPosition, int nCmpSource=1, int nPulseStretch=STRETCH_NON);
// virtual method to arm multiaxis for simultaneous motion
virtual int SimultaneousMove(int nNoOfAxis, CMtrProfile *mtrProfile, double *dPosition, double *dStartVel, double *dMaxVel, double *dAcc, int nMode = 0);
// virtual method to move absolute with s-curve profile
virtual int SMoveAbs(double dPosition, int nPos=-1, int nMode=0);
// virtual method to move motor in s-curve continuously
virtual int SMoveContinuously(bool bCW=true);
// virtual method to move relative distance with s-curve profile
virtual int SMoveRel(double dDistance, int nPos=-1);
// return: success = MOTION_END; error = MOTION_ERROR; Force Stop = MOTION_FORCE_STOP
virtual DWORD WaitHomeDone();
// wait for motion stop based on pulse send out or in-position signal
// call this function after calling a move operation
// return: success = MOTION_END; error = MOTION_ERROR; Force Stop = MOTION_FORCE_STOP
// positive limit = MOTION_LIMIT_POS_HIT; negative limit = MOTION_LIMIT_NEG_HIT
virtual DWORD WaitMotionDone(DWORD dwTimeout=1000);
// virtual method to get the encoder index signal
virtual BOOL IsIndex();
//**************************************************************
// virtual Methods declaration applicable to
// ADLINK 8134, 8164 ONLY - starts
//**************************************************************
// virtual method to set the motor type and encoder input type
virtual int SetMtrType(int iMtrType);
// virtual method to set the motor alarm signal logic
virtual int SetALM(int iALM);
// virtual method to set the home sensor signal logic
virtual int SetORGI(int iORGI);
// virtual method to set the encoder Index signal logic
virtual int SetIndexLogic(int iIndexLogic);
// virtual method to set the in position signal logic
virtual int SetINP(int iINP);
// virtual method to set clk type, out/dir or cw/ccw
virtual int SetClk(int iClk);
//**************************************************************
// virtual Methods declaration applicable to
// ADLINK 8134, 8164 ONLY - ends
//**************************************************************
//**************************************************************
// virtual Methods declaration applicable to GALIL ONLY - STARTS
//**************************************************************
// virtual method to get motion stop code
virtual int GetStopCode();
// virtual method to get motion stop code
virtual CString GetVariable(CString csVariableName);
// virtual method to send direct command string to controller
virtual int SendCommand(CString csCommand);
// virtual method to stop any running script program and stop all motion
virtual int StopProgramAndMotion();
// virtual method to update motion profile
virtual int UpdateProfile();
//**************************************************************
// virtual Methods declaration applicable to GALIL ONLY - ENDS
//**************************************************************
//**************************************************************
// Methods declaration
//**************************************************************
// method to get the real world distance in pulse
double ConvertToPulse(double dDistance);
// method to check if Axis will check for interrupt
bool IsEnableIntCheck();
// method to check disable interrupt
void DisableIntCheck();
// method to check enable interrupt
void EnableIntCheck();
// method to enable/disable auto reset motor position during home operation
void EnableResetPositionDuringHoming(bool bResetPositionDuringHoming)
{
m_bResetPositionDuringHoming = bResetPositionDuringHoming;
}
// method to get the event for homimg complete
HANDLE GetHomeMotionDoneTrigger();
// method to get the event for motion complete
HANDLE GetMotionDoneTrigger();
// method to get the negative software limit in mm
double GetNegativeSoftLimit();
// method to get the positive software limit in mm
double GetPositiveSoftLimit();
// method to set positive software limit
void SetPositiveSoftLimit(double dPosSoftLimit);
// method to set negative software limit
void SetNegativeSoftLimit(double dPosSoftLimit);
// method to home motor, normal or use limit sensor as home.
// Whether to reset position tracking
int Home(DWORD dwTimeout, bool bResetPositionTrack=true, bool bByLimit=false);
// method to do homing, by Sensor or by Index mode
BOOL Homing();
// method to move motor based on position array
int Move(int iPos, int nMode=0);
// method to reset necessary motion events before any motion
void ResetRequiredMotionEvents();
// method to set normal, slow acceleration
int SetAcce(double dAcce, bool bHomeSlow = false);
// method to set normal, slow deceleration
int SetDec(double dDec, bool bHomeSlow = false);
// method to set normal acceleration
int SetSAcce(double dSAcce);
// method to set normal deceleration
int SetSDec(double dSDec);
// method to set constant speed
virtual int SetConst(double dConst);
// method to set normal, slow start up speed
virtual int SetStartUp(double dStartUp, bool bHomeSlow = false);
// method to set normal, slow max speed
virtual int SetCruise(double dCruise, bool bHomeSlow = false);
// method to set virtual home position
int SetVirtualHomePosition(double dVirtualHomePosition);
// method to move motor based on position array with s-curve profile
int SMove(int iPos, int nMode=0);
// method to update the current motor position number for tracking purpose
void UpdatePosition(int nPos);
// method to update auto position number tracking after any motion done
// call to manually update the motor position tracking if never use wait motion done command
// normally by calling wait motion done, position tracking is automatically updated.
void UpdatePosition();
// Gary 21Mar11, V1.28.01
// This method is used to reset alarm via MotionNet
virtual int ResetAlarm(bool bReset);
// These methods only applies to ETEL Gantry Mode
// Gary 8Apr11, V1.29.00
virtual int GantryEnable(int /*nNoOfAxis*/, CMtrProfile* /*mtrProfile*/){return MOTION_ERROR;};
virtual int GantryDisable(int /*nNoOfAxis*/, CMtrProfile* /*mtrProfile*/){return MOTION_ERROR;};
// Method to force a compare output pulse
// Gary 2Jul12, V1.29.07
virtual int TriggerCompareOutput(){return MOTION_ERROR;};
//**************************************************************
// variables declaration
//**************************************************************
// event to kill any running thread
HANDLE m_hKillThread;
// event to trigger axis interrupt
HANDLE m_hAxisInt;
// event to start normal home operation
HANDLE m_hStartHome;
// event to start home by limit operation
HANDLE m_hStartHomeByLimit;
// event to inform motion is completed
HANDLE m_hMotionDone;
// event to inform homing is completed
HANDLE m_hHomeMotionDone;
// event to inform motion has stopped
HANDLE m_hStop;
// event to inform motor trigger positive/cw limit
HANDLE m_hPosLmtHit;
// event to inform motor trigger negative/cw limit
HANDLE m_hNegLmtHit;
// Gary 24Feb11, V1.28.01, new positive limit handle for MotionNet Only
// event to inform motor trigger positive/cw limit
HANDLE m_hMotionNetPosLmtHit;
// Gary 24Feb11, V1.28.01, new negative limit handle for MotionNet Only
// event to inform motor trigger negative/cw limit
HANDLE m_hMotionNetNegLmtHit;
// mutex for interlocking
CMutex m_mutexMotion;
// flag to indicate if axis should respond to any interrupts
bool m_bEnableIntCheck;
// variable to keep track of original Home Sensor Logic
int m_nOrgLogic;
// virtual home position
double m_dVirtualHomePosition;
// flag to indicate whether to reset position during homing
bool m_bResetPositionDuringHoming;
// thread to monitor axis motion
CWinThread *m_pThread;
// thread to monitor home operation
CWinThread *m_pHomeThread;
// keep track of which motor no
int m_iMtrNo;
// keep track of no of pos
int m_iNoOfPos;
// pointer to position array
double *m_dpPos;
// motor profile
CMtrProfile m_MtrProfile;
// variable to store the no. of output pulse per mm
double m_dPulsePerMM;
// variable to store the no. of encoder input pulse per mm
double m_dEncoderPulsePerMM;
// variable to define motion acceleration
double m_dAcc;
// variable to define motion deceleration
double m_dDec;
// variable to define motion S-curve acceleration
double m_dSAcc;
// variable to define motion S-curve deceleration
double m_dSDec;
// variable to define motion start speed
double m_dStartSpeed;
// variable to define motion max speed
double m_dMaxSpeed;
// variable to define motion constant speed
double m_dConstantSpeed;
// variable to track what's the current position number of the axis
int m_nCurrentPosNo;
// variable to store home motion timeout
DWORD m_dwHomeTimeout;
protected:
// methods to reset related motion events before any motion
void ResetMotionEvents();
// methods to log trace data
void Log(CString csData);
// High resolution timer object to track motion time
CHighResPerformanceCounter m_timerMotion;
// motion time
long m_lMotionTime;
// method to return motion time in msec
inline long GetMotionTime(){return m_lMotionTime;};
};
#endif // !defined(AFX_MOTORBASE_H__04B8BC9A_5FF9_4E00_BA08_FDEC856015F1__INCLUDED_)