#pragma once

 
#include "bombax.h"
#include "..\pilelibs\includes\robbase\Robot.h"
  
 

#define ROB_MAX_LATENCE           800
  
//系统保留的动作类ID 
#define ROB_AID_JOG_XY        3
#define ROB_AID_HOME_XY       4
#define ROB_AID_MOVE_XY       5   //同时移动
#define ROB_AID_HOME_ZXY      6     
#define ROB_AID_MOVE_ZXY      7   //先移动xy, 然后移动z。
#define ROB_AID_MOVE_XYZ      8   //先移动xy, 然后移动z。
#define ROB_AID_SEQ2          9   //先后移动2个轴。
#define ROB_AID_SEQ3          10   //先后移动3个轴。
#define ROB_AID_SEQX          13   //先后移动X个轴。
#define ROB_AID_MOVE_ZXYZ     14   //先Z到初始位置，移动xy, 然后移动z。

#define ROB_AID_LINE_XY       21   //插补移动，形成直线
#define ROB_AID_CIRCLE_XY     22   //插补移动，形成圆
#define ROB_AID_ARC_XY        23   //插补移动，形成圆弧
  
 
class BOMBAX_API CRobbax: public CRobot
{
public:
	CRobbax(void);
	virtual ~CRobbax(void);

	virtual BOOL Start(int activity,  HWND hNotifyWnd ,  int* pErrCode);  //窗口消息
	virtual void Stop();

	virtual CMotion* Attach(CMotion* pRobMot);
	virtual void Detach();
	 

 	//获取当前位置
	 BOOL GetCurPos(double* pX, double* pY, double* pZ, int* pErrCode );
	 BOOL GetCurPos(double* pX, double* pYorY1, double* pZ, double * pRorY2, int* pErrCode );
	 BOOL GetCurPos(WORD axis, double * pPos, int* pErrCode );

	 //获取当前速度
	 BOOL GetCurSpeed(double* pX, double* pY, double* pZ, int* pErrCode );
	 BOOL GetCurSpeed(double* pX, double* pYorY1, double* pZ, double * pRorY2, int* pErrCode );
	  
	 //ECAT, GOOGOL
	 BOOL SetOutputLevel(int offset, int bit, int level,int* pErrCode);
	 BOOL GetOutputLevel(int offset, int bit, int* level,int* pErrCode);
	 BOOL GetInputLevel(int offset, int bit, int* level, int* pErrCode);

	 //Motion time
	 BOOL SetOutputLevel(UINT slave, int bit, int level,int* pErrCode);
	 BOOL GetOutputLevel(UINT slave, int bit, int* level,int* pErrCode);
	 BOOL GetInputLevel(UINT slave, int bit, int* level, int* pErrCode);

	 //BOOL Jog(WORD axis,  COptions* option,  int dir, int* pErrCode);
	 //BOOL StopJog(WORD axis, COptions* option,  int* pErrCode);
	 //
	 ////以下三个函数用于相机视场移动
	 //BOOL StartJog(WORD* axes, COptions* options,  int* dirs, int count,  int* pErrCode);
	 //BOOL ChangeJog(WORD* axes, COptions* options,  int* dirs, int count,  int* pErrCode); //变速和变方向
	 //BOOL StopJog(WORD* axes, COptions* options, int count,  int* pErrCode);

  //   //同步（无线程,久了的话会阻塞线程)，会等待完成
	 ////同步移动是在没有任何异步方式移动的情况下进行
	 //BOOL Move( WORD axis,  double pos, BOOL bAbsolute, int sceneId,  int* pErrCode);
	 //BOOL MoveAny2( WORD axisX, WORD axisY,  double x, double y, BOOL bAbsolute, int sceneId,  int* pErrCode);
	 //BOOL Home(WORD axis, int sceneId,   int* pErrCode);
	 //BOOL HomeAny2( WORD axisX, WORD axisY, int sceneId, int* pErrCode);


	 ////支持等待结束,支持暂停
	 //BOOL Move(DWORD actId, WORD axis, double pos, BOOL bAbsolute, int sceneId, BOOL  bWaitComplete,  int* pErrCode);
	 //BOOL MoveAny2(DWORD actId,WORD axisX, WORD axisY, double x, double y, BOOL bAbsolute, int sceneId, BOOL  bWaitComplete, int* pErrCode);
	 //BOOL MoveAny3(DWORD actId, WORD axisX, WORD axisY, WORD axisZ, double x, double y, double z,  BOOL bAbsolute, int sceneId, BOOL  bWaitComplete, int* pErrCode);
 	// 
	 //BOOL Home(DWORD actId, WORD axis, int sceneId, BOOL  bWaitComplete,  int* pErrCode);
	 //BOOL HomeAny2(DWORD actId, WORD axisX, WORD axisY, int sceneId, BOOL  bWaitComplete,  int* pErrCode);
	 //BOOL HomeAny3(DWORD actId, WORD axisX, WORD axisY, WORD axisZ, int sceneId, BOOL  bWaitComplete,  int* pErrCode);


	//等待信号和动作完成
	//virtual BOOL WaitQueue(int bankId, int* pErrCode);
	  
 
	//BOOL WaitAny2(DWORD actId, CAxes& axes, BOOL bCheckPause, COptions* option,  int* pErrCode) ; //等任意2轴 
	//BOOL WaitAny3(DWORD actId, CAxes& axes, BOOL bCheckPause, COptions* option,  int* pErrCode) ; //等任意3轴 
	//BOOL WaitAny4(DWORD actId, CAxes& axes, BOOL bCheckPause, COptions* option,  int* pErrCode) ; //等任意4轴回零
	//BOOL WaitAnyX(DWORD actId, CAxes& axes, BOOL bCheckPause, COptions* option,  int* pErrCode) ; //等任意多轴回零


	////运动停止,将轴设为不可用
	//BOOL HaltMovingAxis(WORD axis, COptions* option, int* pErrCode);
	//BOOL HaltHomingAxis(WORD axis, COptions* option, int* pErrCode);
	// 
	////运动停止,轴继续可用
	//BOOL StopMovingAxis(WORD axis, COptions* option, int* pErrCode);
	//BOOL StopHomingAxis(WORD axis, COptions* option, int* pErrCode);
	 
 
	//多动作执行，暂未实现
	BOOL  ActivateActions(CAction* pAction, int count, HWND hNotifyWnd, int * pErrCode);
	BOOL  ActivateAllActions(HWND hNotifyWnd, int * pErrCode);
	
	//单轴移动情况,可以修改目标值
	//如果需要修改当前轴或相对移动，请使用Action相关函数
	BOOL  ActivateAction(DWORD actId, int scene,  double pos, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);
	BOOL  ActivateAction(CAction* pAction, COptions* pOptions,  double pos, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);
	BOOL  ActivateAction(CAction* pAction, COptions* pOptions,  double x, double y, BOOL bAlongLine, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);
	BOOL  ActivateAction(DWORD actId, int scene,  double x, double y, BOOL bAlongLine, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);


	 
	//以下只能使用内置action id有效
	 
	CAction* AddActionHomeXY(DWORD actId,  WORD axisX, WORD axisY, int* pErrCode);   //内置动作,X,Y轴回零
	CAction* AddActionHomeXYZ(DWORD actId,    WORD axisX, WORD axisY, WORD axisZ, BOOL bFreeMove, int* pErrCode);   //内置动作,X,Y, Z轴回零
	 
	//多轴移动
	CAction* AddActionMoveXY(DWORD actId,   WORD axisX, WORD axisY, double posX, double posY, BOOL bAbsolute, int* pErrCode);   //内置动作,X,Y轴回零
	CAction* AddActionLineXY(DWORD actId,   WORD axisX, WORD axisY, double posX, double posY, BOOL bAbsolute, int* pErrCode);   //内置动作,X,Y轴回零

	CAction* AddActionMoveXYZ(DWORD actId,   WORD axisX, WORD axisY, WORD axisZ, double posX, double posY, double posZ, BOOL bAbsolute, int* pErrCode);   //内置动作,X,Y轴回零
	CAction* AddActionCustom(DWORD actId,  /* WORD* pAxisArray, int axisCount,*/ROB_ACTION_IMPLEMENT_FUNC pfnActionImplement, void* pUserData,int* pErrCode);   //自定义动作
	  
	//运动卡执行时间，部分卡需要
	int  GetMotionLatence();
	void SetMotionLatence(int miniSeconds);
	 
	BOOL DelayForLatence(DWORD actId);

	//生成过渡线，保证过渡行走安全
	//使用: 
	//startXY： 平面起点坐标
	//endXY：   平面终点坐标
	//startZ:   Z轴起点位置
	//endZ:     Z轴起点位置
	//transZ:   Z轴过渡位置
	//safeZ:    Z轴安全位置
	//fillet:   最小倒角长度, 最小值不小于为1
	//bCheckOnly: 仅检测输入的数据是符合生成过渡条件， 否则强制生成可能没有倒角的过渡线。
	//CQueue:     保存路径和结果, 3D插补曲线
	//注意： 1. 所有的位置和坐标为绝对位置; 2. z轴工作在坐标系正区间，z轴位置越大，越接近工作表面
	//       3. transZ 一般小于 safeZ位置，否则可能强制产生一个新位置
	BOOL GenTransitLine(RvPoint_f64 startXY, double startZ,  RvPoint_f64 endXY, double endZ, double transZ, double safeZ, double fillet, BOOL bCheckOnly, double* pNewTransZ,  CQueue* pQueue);

//	BOOL LockMove(DWORD actId,int* pErrCode);
//	BOOL UnlockMove(DWORD actId,int* pErrCode);
   


protected:
	//int  m_nLatence;       //移动作业执行时间，有些卡需要


};

