// MotionController.h: interface for the CMotionController class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MOTIONCONTROLLER_H__65E8EEA5_D76F_11D7_89B3_000629A6E157__INCLUDED_)
#define AFX_MOTIONCONTROLLER_H__65E8EEA5_D76F_11D7_89B3_000629A6E157__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <map>
#include "Motor.h"
#include "MotionControllerBase.h"

#ifdef  BUILD_IODLL
#define     IODLLCLASS  __declspec(dllexport)
#else
#define     IODLLCLASS  __declspec(dllimport)
#endif

class IODLLCLASS CMotionController : public CCard
{
public:
//  static void SetGalilMotionInt(int nAxisNo);
    BOOL           IsInPosition(CMtrProfile mtrProfile);
    unsigned short GetMotionIOStatus(CMtrProfile mtrProfile);

    CMotionController();
    virtual ~CMotionController();

    BOOL InitController(int iNoOfMtr);

//  check if negative limit hit
// BOOL IsNegLimHit(int iMotorNo);
    BOOL IsNegLimHit(CMtrProfile mtrProfile);

//  check if positive limit hit
// BOOL IsPosLimHit(int iMotorNo);
    BOOL IsPosLimHit(CMtrProfile mtrProfile);

//  check if motor at home position
// BOOL IsHomed(int iMotorNo);
    BOOL IsHomed(CMtrProfile mtrProfile);

//  check if servo ready
// BOOL IsServoReady(int iMotorNo);
    BOOL IsServoReady(CMtrProfile mtrProfile);

//  check if servo alarm
// BOOL IsServoAlarm(int iMotorNo);
    BOOL IsServoAlarm(CMtrProfile mtrProfile);

//  get Motor Pos value
// double GetMtrPos(int iMotorNo);
    double GetMtrPos(CMtrProfile mtrProfile);

//  get Motion status of motor
// int GetMotionStatus(int iMotorNo);
    int GetMotionStatus(CMtrProfile mtrProfile);

//  get proportional gain value
    double GetPValue(int iMotorNo);

//  get Integral gain value
    double GetIValue(int iMotorNo);

//  get Deriative gain value
    double GetDValue(int iMotorNo);

//  get position error value
// double GetPosErr(int iMotorNo);
    double GetPosErr(CMtrProfile mtrProfile);

//  check if Motor type is servo motor
    BOOL IsServoMtrType(CMtrProfile mtrProfile);

//  copy all motor status
    void CopyMtrStatus();

//  check if motor position changed
    bool IsMtrPosChanged(int iMtrNo, int &iPos);

//  check if motor On/Off States changed
    bool IsMtrOnOffStateChanged(int iMtrNo, bool &bOnOffState);

//  check if motor is on
    BOOL IsMtrOn(CMtrProfile mtrProfile);

/*  Return Motor(specify by iMtrNo) on or off state.
    Function Return true = Motor specify by iMtrNo Is On, else return false = Motor is off */
    bool GetMtrOnOffState(int iMtrNo);

    void                      RegisterMotor(const CMtrProfile &mtrProfile, CMotorBase *pMotor);
    void                      UnRegisterMotor(const CMtrProfile &mtrProfiler);
    static CMotionController &Instance();
    CMotionControllerBase    *GetBaseController(int controllerType);
//  int m_nCurrentGalilCard;
private:

/**
 * @brief   all the various motion controller objects indexed by the controller ID.
 */

    std::map<int, CMotionControllerBase*> m_motionControllerBase;

    CMtrPos   m_mtrPos;        // object to keep track of current motor position
    CMtrOnOff m_mtrOnOff;      // object to keep track of current motor On/Off States
    int      *m_ipMtrCurPos;   // array to store motor position before maintenance mode
    bool     *m_bpMtrCurOnOff; // array to store motor On/Off States before maintenance mode
    int       m_iNoOfMtr;      // total no of motor

    int          m_nNoOfCardType;
    CHardwareIni m_iniHardware;

    bool                      m_bBenchDebugWithActualHardware;
    static CMotionController *m_pInstance;
};

#endif // !defined(AFX_MOTIONCONTROLLER_H__65E8EEA5_D76F_11D7_89B3_000629A6E157__INCLUDED_)
