#pragma once

 
#include "robbase.h"
#include "Action.h"
 
#include "SoftTrigger.h"
#include "Options.h"
#include "Motion.h"
#include "Gpio.h"
#include "Queue.h"



#define ROB_MODULE_UNKNOWN        (-1)   
#define ROB_MODULE_MOTION         1     
#define ROB_MODULE_CAMERA         2    
#define ROB_MODULE_PLC            3 
#define ROB_MODULE_MES            4 


#define ROB_MAX_LATENCE           800
 
//系统保留的动作类ID
#define ROB_AID_UNKNOWN       (-1)
#define ROB_AID_JOG           0  //排它移动
#define ROB_AID_HOME          1
#define ROB_AID_MOVE          2
#define ROB_AID_EXTEND        41   //AUTOTAB系统扩展
#define ROB_AID_CUSTOM        101  //用户程序自定义

#define ROB_MAX_SAFETY_ACTION_COUNT    17
//最多触发器数量

#define ROB_MAX_TRIGGER_COUNT      16
#define ROB_MAX_ACTION_COUNT       (/*ROB_STOCK_ACTION_COUNT +*/ 32)    
#define ROB_MAX_SCENE_COUNT        32   
#define ROB_MAX_EMERGENCE_COUNT    8
#define ROB_MAX_SAFETY_COUNT     32
#define ROB_MAX_FUNCIN_COUNT       7
   

//自定义消息事件
#define ROB_ON_ACT_START         (WM_USER + 1301) //13月01号，避开按月份编号的自定义消息
#define ROB_ON_ACT_STOP          (WM_USER + 1302) //13月02号，避开按月份编号的自定义消息
 
#define ROB_ON_TRIGGER_OCCUR     (WM_USER + 1305) //13月05号，避开按月份编号的自定义消息
#define ROB_ON_EMERGENCE_OCCUR   (WM_USER + 1306) //13月06号，避开按月份编号的自定义消息
#define ROB_ON_ERROR_OCCUR       (WM_USER + 1307) //13月07号，避开按月份编号的自定义消息
#define ROB_ON_SAFEDOOR_OPENED   (WM_USER + 1308) //13月08号，避开按月份编号的自定义消息
#define ROB_ON_EXCEPTION_OCCUR   (WM_USER + 1309) //13月09号，避开按月份编号的自定义消息
#define ROB_ON_FUNCIN_OCCUR      (WM_USER + 1310) //13月09号，避开按月份编号的自定义消息
 

//中断处理回调
typedef BOOL ( *ROB_SUPPLEMENT_FUNC)(DWORD actId, HANDLE hRobot, HANDLE hMotion,  void* pUserParams, int* pErrCode);

typedef struct __rob_supple_triple_
{
	void* pUserParams;
	ROB_SUPPLEMENT_FUNC pfnAfterPausedCallback;
	ROB_SUPPLEMENT_FUNC pfnBeforeContinueCallback;
}RobSuppleTriple;

 
typedef struct __rob_safety_
{
	int    type;  //0-默认
	CGpio  din;   //
	int    actCount;
	DWORD  actArr[ROB_MAX_SAFETY_ACTION_COUNT];
}RobSafety;
  
//实例或派生类实例，请添加至少回零,
//编辑,连续运动三个场景的参数
class ROBBASE_API CRobot
{
public:
	CRobot(void);
	virtual ~CRobot(void);

	//启动选项
    enum RS_ACTS{
		DUMMY   = 0,
		ACTION  = (1),         //动作
		EMERG   = (1<<1),      //急停
		SAFETY  = (1<<2),      //安全
		TRIGGER = (1<<3),      //触发
		FUNCIN  = (1<<4),      //专用输入
		ALARM   = (1<<5),      //报警
	};
	
	//机器状态
	enum MS_STATE
	{
	   MS_UNKNOWN  = (-1),
       MS_STANDBY  =  0,  //待机
       MS_MOVING  =  1,   //轴正在移动(action)
       MS_PAUSED   =  2,  //暂停, 
       MS_BROKEN   =  3,  //故障发生, 
       MS_EMERGENCE =  4,  //急停, 	 
	};

	//动作状态
	enum PS_STATE{
		PS_UNKNOWN  = -1,
	    PS_NORMAL   = 0,
		PS_EXCEPT   = 1,   //例外处理
		PS_CANCEL   = 2,   //取消, 不停止线程
		PS_ABORT    = 3,   //终止，停止线程时发生
		PS_DEAD     = 4,   //终止后，线程退出前发生
	};

	//报警灯状态
	enum ALARM_LIGHT{
		AL_ALL_OFF    =  0,
	    AL_GREEN  =  1,
		AL_YELLOW =  (1<<1),
		AL_RED    =  (1<<2),   
		AL_ALL_ON =  (AL_GREEN | AL_YELLOW | AL_RED),
	};
 
	//等待状态信号
	enum WAIT_STATE{
	    WS_PAUSE   =  1,
	    WS_EMERG   = (1<<1),
	    WS_BROKEN  =(1<<2),
	};

	//action优先级
	enum ACTION_PRIORITY{
		 AP_ERROR    =-1,
	     AP_IDEL    =0,
		 AP_LOWEST  =1,
		 AP_BELOW_NORMAL =2,
		 AP_NORMAL       =3,
		 AP_ABOVE_NORMAL =4,
		 AP_HIGHEST      =5,
		 AP_TIME_CRITICAL=6,
	};

	//安全门类型
	enum SAFETY_TYPE{
	     ST_GENERIC = 0 ,
		 ST_ACTION  = 1,    
	};
	 

	//新接口 on 25-01-23
	//activity: ACTION,  EMERG, SAFETY,  TRIGGER, FUNCIN
	virtual BOOL Start(int activity,  HWND hNotifyWnd ,  int* pErrCode);  //窗口消息
	virtual void Stop();
	void StopEx(BOOL bEmerg);	 //支持急停

	BOOL Delay(DWORD actId,  int timeout);
	 
	int  GetCurState(){ return m_nCurState; };  
	 
	//返回motion错误，否则，返回空
    virtual const char* GetErrorDesc(int errCode) ;

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

	// //获取当前速度
	BOOL GetCurSpeed(WORD axis, double * pSpeed, int* pErrCode );
	// 
	// //获取当前输出输出状态，无转置（原生状态）
	BOOL SetOutputLevel(int bit, int level,int* pErrCode);
	BOOL GetOutputLevel(int bit, int* level,int* pErrCode);
	BOOL GetInputLevel(int bit, int* level, int* pErrCode);
	  
	//以下函数支持暂停和继续
	//@20250429
	//单轴
	BOOL  GoHome(DWORD actId, WORD axis, COptions* options, int* pErrCode) ;
	BOOL  MoveTo(DWORD actId, WORD axis, double pos, BOOL bAbsolute, COptions* option, int* pErrCode);
	//多轴
	BOOL  GoHomeMany(DWORD actId,WORD* pAxisArray, int count, COptions* options, int* pErrCode) ;
	BOOL  MoveManyTo(DWORD actId,WORD* pAxisArray, double* pPosArray, int count, BOOL bAbsolute, COptions* option, int* pErrCode);
	BOOL  MoveManyTo(DWORD actId,WORD* pAxisArray, double* pPosArray, COptions** pOptArray, int count, BOOL bAbsolute,  int* pErrCode);

	//插补
	BOOL  LineAnyTo(DWORD actId,   DWORD csid, WORD* pAxisArray, double* pPosArray, int count, BOOL bAbsolute, COptions* option, int* pErrCode); //插补
	BOOL  LineTo(DWORD actId, DWORD csid, WORD axisX, WORD axisY, double x, double y, BOOL bAbsolute, COptions* option, int* pErrCode);        //插补
	BOOL  ArcTo (DWORD actId,  DWORD csid, WORD axisX, WORD axisY, double cx, double cy, double ex, double ey, int dir, COptions* option, int* pErrCode);
	//队列
	BOOL  Go(DWORD actId,   CQueue* pQueue, COptions* options, int* pErrCode);

	//支持补充回调 @20250519
	BOOL  GoHomeEx(DWORD actId, WORD axis, COptions* options, RobSuppleTriple suppleTriple, int* pErrCode) ;
	BOOL  MoveToEx(DWORD actId, WORD axis, double pos, BOOL bAbsolute, COptions* option, RobSuppleTriple suppleTriple, int* pErrCode);
	//多轴
	BOOL  GoHomeManyEx(DWORD actId,WORD* pAxisArray, int count, COptions* options, RobSuppleTriple suppleTriple, int* pErrCode) ;
	BOOL  MoveManyToEx(DWORD actId,WORD* pAxisArray, double* pPosArray, int count, BOOL bAbsolute, COptions* option, RobSuppleTriple suppleTriple, int* pErrCode);
	BOOL  MoveManyToEx(DWORD actId,WORD* pAxisArray, double* pPosArray, COptions** pOptArray, int count, BOOL bAbsolute, RobSuppleTriple suppleTriple,  int* pErrCode);
	//插补
	BOOL  LineAnyToEx(DWORD actId, DWORD csid, WORD* pAxisArray, double* pPosArray, int count, BOOL bAbsolute, COptions* option, RobSuppleTriple suppleTriple, int* pErrCode); //插补
	BOOL  LineToEx(DWORD actId, DWORD csid, WORD axisX,   WORD axisY, double x, double y, BOOL bAbsolute, COptions* option, RobSuppleTriple suppleTriple, int* pErrCode);        //插补
	BOOL  ArcToEx(DWORD actId, DWORD csid, WORD axisX,    WORD axisY, RvPoint_f64 center, RvPoint_f64 end, int dir, COptions* option, RobSuppleTriple suppleTriple, int* pErrCode);
	//队列
	BOOL  GoEx(DWORD actId,  CQueue* pQueue, COptions* options, RobSuppleTriple suppleTriple, int* pErrCode);
	//End of @20250519

	//等待单移动轴回零，支持暂停和继续
	//pos必须为绝对位置
	//BOOL WaitMove(DWORD actId, WORD axis, double pos, COptions* option,  int* pErrCode);	
	//BOOL WaitHome(DWORD actId, WORD axis,  COptions* option,  int* pErrCode);	
	//BOOL WaitQueue(DWORD actId,	DWORD qid,  COptions* option,  int* pErrCode);	//等待队列执行

	//remove by hdy @@20250429.2
	//BOOL Move(DWORD actId, WORD axis, double pos, BOOL bAbsolute, COptions* option,   int* pErrCode);
	//BOOL Home(DWORD actId, WORD axis, COptions* option,   int* pErrCode);
	//end of @20250429.2

	//WaitInput不受影响,可通过CGpio反置点平 
	virtual BOOL WaitInput(DWORD actId, CGpio* pIn, int nCheckFlags, int timeout, int* pErrCode);
	 
	//可选支持暂停,但等待当前动作完成才暂停 
	BOOL WaitHome(DWORD actId, WORD axis, int nCheckFlags, COptions* option,  int* pErrCode);	
	BOOL WaitMove(DWORD actId, WORD axis, int nCheckFlags, COptions* option,  int* pErrCode);	
	//插补等待完成
    BOOL WaitAny(DWORD actId, DWORD csid, CAxes& axes,   int nCheckFlags, COptions* option, int* pErrCode);
    //等待队列完成
	BOOL WaitQueue(DWORD actId,	DWORD qid, int nCheckFlags, 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  ActivateAction(CAction* pAction, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);
	BOOL  ActivateAction(CAction* pAction, COptions* option, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);

	BOOL  ActivateAction(DWORD actId, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);
	BOOL  ActivateAction(DWORD actId, int sceneId, BOOL bSynch, HWND hNotifyWnd, int * pErrCode);

	 BOOL  IsActionActive(DWORD actId);   //判断动作是否活动状态,其状态小于 CANCEL
	void  TerminateAction(DWORD actId);  //结束动作
	void  TerminateAllActions();         //结束动作
	BOOL  IsActionAbort(DWORD actId);    //判断动作是否放弃了
	int   GetActivationCount();          //激活的action数量，包括已经dead
	BOOL  IsAnyActionActive();
	//IsAnyActionActivated包括非活动的action
	BOOL  IsAnyActionActivated();       
	BOOL  IsActionDead(DWORD actId);       //动作已经dead
	BOOL  IsActionActivated(DWORD actId);  //动作被激活过的，包括已经dead
	 
	void SetActionPriority(DWORD actId, int level);
	int  GetActionPriority(DWORD actId);
	int  GetActionState(DWORD actId);
	
	 
	//辅助
	//判断轴是否占用
	BOOL IsAxisOccupied(WORD axis);
 
	//急停
	BOOL AddEmerg(int bit,  BOOL bReverse,  int* pErrCode);
	BOOL GetEmergLevel(int bit,  int* pLevel,  int* pErrCode);

	int  GetEmergCount();
	void RemoveEmerg(int bit);
	void RemoveAllEmerg();

	//安全输入
	BOOL AddSafety(int type, int bit,  BOOL bReverse,  int* pErrCode);
	int  GetSafetyCount();
	void RemoveSafety(int bit);
	void RemoveAllSafety();
	BOOL GetSafetyLevel(int bit, int* pLevel,   int* pErrCode);
	
	BOOL AddActionToSafety(int bit, DWORD actId,   int* pErrCode);
	int  GetActionCountInSafety(int bit);
	void  RemoveActionFromSafety (int bit,  DWORD actId);
	 
	//触发器
	//输入触发位， 初始电平，触发类型，触发周期(高低电平类型有效)
	int  GetTriggerCount();

	//外部不要删除trigger
	BOOL AddTrigger(int bit, int type , int nInitLevel,  int* pErrCode);
	BOOL GetTriggerLevel(int bit,  int* pLevel,  int* pErrCode);
 
	void RemoveTrigger(int bit);
	void RemoveAllTrigger();



	//外部不要删除options
	//使用RemoveScene或RemoveAllScene代替
	//根据不同的，如果已经存在，会返回对应的options
	const COptions* AddScene(int scene, double speed, double acc, double dec, BOOL bUpdateIfExist = TRUE, int* pErrCode = NULL);
	int   GetSceneCount();
	int   GetSceneId(int index);
	BOOL  IsSceneExist(int id); 
	BOOL  IsOptionsExist(COptions* pOptions); 
	int   GetSceneId(COptions* pOptions);



	//外部程序不要删除
	const COptions* GetSceneAt(int index); 
	//const COptions* GetSceneOptionsById(int scene); 
	 
	//这两个函数仅删除bAutoDelete=FALSE的scene
	void RemoveScene(int sceneId);
	void RemoveAllScene();

	//AddAction 输入的action指针由robot通过调用相关函数删除。
	//如果想自己删除，不要使用该函数添加
	BOOL AddAction(CAction*  action,  int* pErrCode);
	

    int  GetActionCount(); 
	//外部程序不能删除，只能通过接口删除
	const CAction* AddActionHome(DWORD actId,  WORD axis, int* pErrCode);
	const CAction* AddActionJog(DWORD actId,  WORD axis, int* pErrCode);
	const CAction* AddActionMove(DWORD actId,  WORD axis, double pos, BOOL bAbosolute, int* pErrCode);
	 
	const CAction*  GetActionAt(int index);
	const CAction*  GetAction(DWORD actId); 
	int   GetActionId(int index);
	void  RemoveAction(DWORD actId);
	void  RemoveAction(CAction* pAction);
	void  RemoveAllAction();

	//动态关联action的安全输入,bit必须是safety
	BOOL AddBan(DWORD actId, int bit, int* pErrCode); 
	void RemoveAllBans(DWORD actId);
	void RemoveBan(DWORD actId, int bit);
	

	//是否正在运行
	BOOL IsRunning() {return m_bRunning  /*m_nCurState >= MS_STANDBY*/ ;}
	BOOL IsAbnormal() { return m_nCurState >  MS_PAUSED ; };
	//监视触发器状态
	BOOL IsTriggerOn();
	//Obsolete @250125
	//BOOL ActivateTrigger(HWND hNotifyWnd);
	//void DeactivateTrigger();
	//end of @250125
	BOOL  SwitchTrigger(BOOL bOn, HWND hNotifyWnd);

	//急停监视
	BOOL  IsEmergenceOn(); //该函数表示是否急停监听已经启动
	BOOL  SwitchEmergence(BOOL bOn, HWND hNotifyWnd);

	//安全门监视
	BOOL  IsSafetyOn();         
	BOOL  SwitchSafety(BOOL bOn, HWND hNotifyWnd);

	//专用输入监视，功能与触发器其实一样
	BOOL  SwitchFuncInput(BOOL bOn, HWND hNotifyWnd);
	BOOL  IsFuncInputOn();
	
	//三色报警灯
	BOOL  SwitchAlarmLight(BOOL bOn);
	BOOL  IsAlarmLigthOn();
	BOOL  SetAlarmLights(int lights, BOOL bFlicker , BOOL bBeep , int* pErrCode = NULL);
	BOOL  SetBeepSilent(int* pErrCode);
	void  SetFlickerDuration(int duration);
	int   GetFlickerDuration();

	 
	//运动
	virtual CMotion* Attach(CMotion* pRobMot);
	virtual void Detach();

	CMotion*         GetMotion();

	//暂停
	BOOL Pause(int* pErrCode);
	BOOL Continue(int* pErrCode);
	BOOL IsPaused();

	//取消action
	void CancelAction(DWORD actId);
	BOOL IsActionCanceled(DWORD actId);
	void SetActionNormal(DWORD actId); //将取消的线程设置正常状态


	//动作中检测暂停和继续两种状态，如果在暂停状态，该函数会等待。
	BOOL CheckPauseAndResume(DWORD actId, int* pErrCode);

	//急停,EnterEmergState返回的FALSE,也意味着进行了急停处理
	void EnterEmergState(int* pErrCode);
	BOOL ClearEmergState(int* pErrCode);

	//复位,该动作仅仅奖状态清除
	BOOL Reset(int* pErrCode);

	//检测通知
	//void RaiseInspect();
	//void FlatInspect();
	

	 
	void ClearActionLog(void);

	//产生例外， EXID由用户设定, EXID必须大于0
	BOOL RaiseException( DWORD actId ,  int exId, void* pExceptData, int size, int* pErrCode);
	void TreatException( DWORD actId , int exId ,   BOOL bAbort, void* pExceptData, int size );
	BOOL WaitConfirm( DWORD actId , int exId , int timeOut, int* pErrCode);
	BOOL GetExceptionData( DWORD actId , int exId , void* pExceptData, int size );

	   
	//强制软限位关闭
	BOOL ForceSoftLimitOff(WORD axis,   int* pErrCode);
	BOOL RestoreSoftLimitOn(WORD axis,   int* pErrCode);
	  
	//static CAction* NewActionJog(int actId, WORD axis, COptions* pOptions =NULL);
	//static CAction* NewActionHome(int actId, WORD axis, COptions* pOptions = NULL);
	//static CAction* NewActionMove(int actId, WORD axis, COptions* pOptions = NULL);
		
	void SetSupplementTriple(DWORD actId, RobSuppleTriple triple);
	//void SetBeforeContinueSupplement(DWORD actId, FS_SUPPLEMENT_FUNC fnSupplement);
	RobSuppleTriple GetSupplementTriple(DWORD actId);
	//FS_SUPPLEMENT_FUNC GetAfterPauseSupplement(DWORD actId);
	//FS_SUPPLEMENT_FUNC GetBeforeContinueSupplement(DWORD actId);



public:
	int    m_nPosType;
	int    m_nLatence ;  //响应时间， 50ms default

protected:
	HWND   m_hNotifyWnd;  //

	//HWND   m_hFuncInWnd;
	//HWND   m_hTriggerWnd;
	//HWND   m_hEmergWnd;
	//HWND   m_hSafetyWnd;
	   
//内部调用
public:
 
	//触发器相关
	void CheckTriggerInputState(int* pExitCode);
	void CheckFuncInputState(int* pExitCode);

	//检查与action相关的安全信号
	BOOL  IsActionAnySafetyOn(DWORD actId, int* pErrCode);     
	
	//急停相关
	void CheckEmergenceState();

	//安全门相关
	void CheckSafetyState();

	//报警灯控制
	void CheckAlarmLightState();

	//子类重载该函数进行具体功能,该函数不要处理长时间任务，避免阻塞。
	//bit:输入位号, type: 触发类型,  bOn: 是否为发生触发状态
 
	//按照场景选择运动参数
	virtual COptions* GetSceneOptions(int scene); 
	  
	//BOOL* GetCancelFlag(){ return &m_bCanceled; };

	int  Excute(CAction* pAction,   HWND hNotifyWnd, int logIdx );
	 
	void LogActFinish(DWORD actId, int /*retCode*/);
	 
	
protected:
	 
	const CAction* FindActionById(DWORD actId, int* pIndex);
	
	//内部调用
	BOOL AddActionAny(CAction* pAction,  int* pErrCode);

	BOOL CheckStateBeforeMove(DWORD actId, int* pErrCode);
	
	

protected :
	
 
	struct __act_log_
	{
		//BOOL     bActive;  //是否已经结束
		int       actId;
		int       state;      //状态		
		//BOOL     bAbort;
		int      exceptId;     //例外ID, 
		void*    pExceptData;
		int      exceptDataSize;   

		//暂停和继续回调
		RobSuppleTriple suppleTriple;
		//RobSuppleQuad m_suppleQuad;
		//FS_SUPPLEMENT_FUNC fnAfterPause;     //暂停以后
		//FS_SUPPLEMENT_FUNC fnBeforeContinue; //继续之前
		int     banCount ;
		CGpio*  ppBanArray[ROB_MAX_SAFETY_COUNT];

		CAction* pAction;
		BOOL     bSynch;       //同步运行
		HWND     hNotifyWnd;   //接受消息		
		HANDLE   hThread;
	}m_actLogArray[ROB_MAX_ACTION_COUNT];
	int  m_nLogActionCount ;

	//场景速度参数
	struct __scene_options__{
		int scene;
		//BOOL bAutoDelete;
		COptions* pOptions;
	};
	 
	int  m_nCurActivities;
 

protected:
	void UpdateSafetyToLog(DWORD actId, struct __act_log_* pActLog);	 
	CGpio* FindInputInSafety(int type, int bit);

	//改函数限制state >= m_nCurState
	BOOL   SetCurState(int state);

	//等待回归完成
	BOOL WaitHomeComplete(DWORD actId, WORD axis, int nCheckFlags,  COptions* options, int* pErrCode);
	//等的回归完成
	BOOL WaitMoveComplete(DWORD actId, WORD axis, int nCheckFlags,  COptions* options, int* pErrCode);

	////同步移动下的等待
	//BOOL WaitAxisNoPause(  WORD axis, BOOL bHome, int* pErrCode);

//下面的函数会返回停止消息
//会发送消息	
protected:
	BOOL CheckConcurrence(CAction* pAction);

	BOOL  CheckAcionActive(DWORD actId, int* pErrCode);

	//过时: @20250615
	//三轴
	//计算下降连续段过渡点: 输入起点（p0），末点(p1)和百分比(0~1) ，计算水平段的过渡点（n0）和垂直段的过渡点(n1)
	void CalcFallingVertex(RvPoint3D_f64 p0, RvPoint3D_f64 p1, double delta, RvPoint3D_f64& n0, RvPoint3D_f64& n1 );

	//计算上升连续段过渡点: 输入起点（p0），末点(p1)和百分比(0~1)，计算水平段的过渡点（n0）和垂直段的过渡点(n1)
	void CalcRisingVertex(RvPoint3D_f64 p0, RvPoint3D_f64 p1, double delta, RvPoint3D_f64& n0, RvPoint3D_f64& n1);

	//计算上升到下降连续段过渡点: 输入起点（p0），末点(p1)，z轴高度和百分比(0~1)，计算水平段的过渡点（n0）和垂直段的过渡点(n1)
	void CalcArchVertex(RvPoint3D_f64 p0, RvPoint3D_f64 p1, double topZ, double delta, \
	                	RvPoint3D_f64& n0,  RvPoint3D_f64& n1, RvPoint3D_f64& n2,  RvPoint3D_f64& n3  );


	//两轴,　通常x,z轴
		
	//计算下降连续段过渡点: 输入起点（p0），末点(p1)和百分比(0~1) ，计算水平段的过渡点（n0）和垂直段的过渡点(n1)
	void CalcFallingVertexXZ(RvPoint_f64 p0, RvPoint_f64 p1, double delta, RvPoint_f64& n0, RvPoint_f64& n1 );

	//计算上升连续段过渡点: 输入起点（p0），末点(p1)和百分比(0~1)，计算水平段的过渡点（n0）和垂直段的过渡点(n1)
	void CalcRisingVertexXZ(RvPoint_f64 p0, RvPoint_f64 p1, double delta, RvPoint_f64& n0, RvPoint_f64& n1);

	//计算上升到下降连续段过渡点: 输入起点（p0），末点(p1)，z轴高度和百分比(0~1)，计算水平段的过渡点（n0）和垂直段的过渡点(n1)
	void CalcArchVertexXZ(RvPoint_f64 p0, RvPoint_f64 p1, double topZ, double delta, \
	                	RvPoint_f64& n0,  RvPoint_f64& n1, RvPoint_f64& n2,  RvPoint_f64& n3  );
	//End of @20250615

protected:	 
 	  
	int  m_nCurState;  //Robot state
	//BOOL m_bCanceled;
	BOOL m_bRunning;

//	int  m_nflags;
	
	//BOOL  m_bPaused;
	//BOOL  m_bRequest; //请求检测一次

	CRITICAL_SECTION m_csState;
	 
	//运动执行类
	CMotion* m_pMtn;
	  
	//int    m_nThreadCount ;
	//HANDLE m_hWorkThreads[ROB_MAX_ACTION_COUNT];

	HANDLE m_hTriggerThread;   // 触发线程
	HANDLE m_hEmergThread;     // 急停线程
	HANDLE m_hSafetyThread;    // 安全门(包括光栅等)线程
	HANDLE m_hFuncInThread;        // 设备保留功能输入线程
	HANDLE m_hLightAlarmThread;    // 三色灯闪烁线程

	 
	//急停
	int     m_nEmergenceCount;
	CGpio*  m_ppEmergenceArray[ROB_MAX_EMERGENCE_COUNT];
	BOOL    m_bEmergenceOn;

	//安全门
	int         m_nSafetyCount;
	RobSafety*  m_ppSafetyArray[ROB_MAX_SAFETY_COUNT];
	BOOL        m_bSafetyOn;


	//触发相关
	//struct __trig_desc_
	//{
	//    HWND          _hNotifyWnd;  //保留
	//	CSoftTrigger* pTrigger;
	//}
	int           m_nTriggerCount;
	CSoftTrigger  m_triggerArray[ROB_MAX_TRIGGER_COUNT];
	BOOL          m_bTriggerOn;

	//动作相关
	int           m_nActionCount;
	CAction*      m_ppActionArray[ROB_MAX_ACTION_COUNT];
    

	//用户场景参数
	int                          m_nSceneCount;
	struct __scene_options__*    m_ppSceneArray[ROB_MAX_SCENE_COUNT];

	//三色报警灯
	BOOL  m_bFlicker;
	int   m_nFlickerDuation; //闪烁延时
	BOOL  m_bAlarmLightOn;
	BOOL  m_bBeepOn; 
	int   m_nCurLights ;

	//专用输入
	BOOL  m_bFuncInputActive;
	  
	
};

