#ifndef __DRIVERMOTION_H__ #define __DRIVERMOTION_H__ #include "config.h" #define DEV_MOTIONS_NUM DRIVERS_NUM // 运动控制器数量 // 驱动器运动控制 typedef struct { // 输入参数 s32 movement; // 位移量 u32 startPPS; // 启动速度(位置/秒) u32 runPPS; // 运动速度(位置/秒) u32 addPPSS; // 启停加速度(位置/秒) u32 brkPPSS; // 刹车加速度(位置/秒) u32 funTestTime; // 运行过程中外部函数检测间隔时间 0:不检测外部函数 (单位:0.1ms) // 函数指针 int (*GetNormalStop)(u32,u32); // 一般停止条件函数,当为空时,不检测停止条件; 不为空时,条件满足,降速到停止(按启停加速度降速) int (*GetQuickStop)(u32,u32); // 快速停止条件函数,当为空时,不检测停止条件; 不为空时,条件满足,降速到停止(按刹车加速度降速) u32 condPara1, condPara2; // 条件函数参数 int blockRunflag; // 阻塞运行标志, =1阻塞运行,同步运动 =0,非阻塞,异步运动 void (*ExecWhenRun)(void); // 电机运行过程中执行的函数 void (*ExecWhenStart)(void); // 电机启动时执行的函数 void (*ExecWhenStop)(void); // 电机停止时执行的函数 void (*DelayWhenBlock)(u32); // 阻塞时的Delay函数(编译为速度模式时且阻塞运动时需要此处不为空,否则无法跳出循环) }DrvMotionPara; //------------------------------------------------------------------------------- //--------------------------------------------------------------- void InitDrvMotions(); void DrvMotionCalcProc(); //------------------------------- int DrvMotionStart(int driverIdx, DrvMotionPara * pPara); // 启动运动控制(停止状态时可用) void DrvMotionStop(int driverIdx); // 停止运动控制(非阻塞运动时用到) void DrvMotionBreak(int driverIdx); // 停止运动控制(非阻塞运动时用到) int DrvMotionRun(int driverIdx); // 运行函数 int GetDrvMotionState(int driverIdx); // 得到运动状态(非阻塞运动时用到) s32 GetDrvMotionRealPos(int driverIdx); // 得到当前运动位置(非阻塞运动时用到) void SetDrvMotionRealPos(int driverIdx, s32 pos); // 设置当前运动位置(停止状态时可用) //------------------------------- // 运动状态定义 #define DRV_MOTION_ERR -1 // 异常 #define DRV_MOTION_STOP 0 // 停止 #define DRV_MOTION_ADD 1 // 加速 #define DRV_MOTION_RUN 2 // 匀速 #define DRV_MOTION_DEC 3 // 降速(计数降速) #define DRV_MOTION_NSTOP 4 // 停车(条件停车) #define DRV_MOTION_ESTOP 5 // 刹车(条件刹车) #define DRV_MOTION_STOPING 6 // 停止中 //------------------------------- #endif