optical/NxFuncs/motions/motion.h
2025-09-04 09:45:08 +08:00

177 lines
4.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __MOTION_H__
#define __MOTION_H__
#include "config.h"
//--------------------------------------------------
// 运动控制
#ifndef MAX_AXIS_NUM
#define MAX_AXIS_NUM 4
#endif
//----------------------------------------------------------------------------------------------------------
// 电机速度结构
typedef struct
{
u32 startPPS; // 启动速度
u32 stopPPS; // 停止速度
u32 runPPS; // 运动速度
u32 slowPPS; // 慢速速度
u32 addPPSS; // 变速加速度
u32 brkPPSS; // 刹车加速度
u32 slowPPSS; // 慢速加速度
}MotionSpeedCtrl;
typedef struct
{
void (*RefreshPosition)(u32, s32*); // 坐标刷新回调函数
u32 refPosPara; // 坐标刷新参数
int (*GetSlowDown)(u32,u32); // 慢速运动条件函数,当为空时,不检测降速条件; 不为空时,条件满足,速度降低,条件消失,速度恢复
int (*GetNormalStop)(u32,u32); // 一般停止条件函数,当为空时,不检测停止条件; 不为空时,条件满足,降速到停止(按降速加速度)
int (*GetQuickStop)(u32,u32); // 快速停止条件函数,当为空时,不检测停止条件; 不为空时,条件满足,降速到停止(按刹车加速度)
int (*GetEmergencyStop)(u32,u32); // 紧急停止条件函数,当为空时,不检测急停条件; 不为空时,条件满足,立刻停止发送脉冲(无需降速)
u32 condPara1, condPara2; // 条件函数参数
}MotionCallbackCtrl;
//--------------------------------------------------
// 单轴异步轨迹运动
#define SPM_PARA_NUM 100 // 大于等于SeparateMotionCtrl.paraList
typedef struct
{
int motoIdx; // 运动轴索引
int runtype; // 运动模式0, 位移模式(位移完成,然后停止); 1, 速度模式(无限运动模式,直到停止条件触发停止)
int blockRun; // 阻塞运行标志
s32 movement; // 位移量
MotionSpeedCtrl spdPara; // 速度
// 回调函数
MotionCallbackCtrl callback;
// 反馈信息
int errInfo; // 错误信息
int exerslt; // 执行结果
int runningflag; // 运行标志
int startflag; // 启动标志
int stopflag; // 停止标志(外部设置)
// 中间变量
union
{
u32 buff[SPM_PARA_NUM];
struct
{
int initedflag;
int outdir;
int oldcondsel;
s32 posbeforerun; // 运动前的位置
float startpps, runpps, slowpps, stoppps; // 速度
float addppss, brkppss, slowppss; // 加速度
u32 totalnum, runmidx;
u32 mvmtseg[3]; // 运动的三段的位移
u32 decpoint; // 降速分界点
u32 tablen12, tablen3;
u32 slowmvmt;
int slowsta, inslow; // 降速状态,正在降速标志
int brksta, inbrk; // 刹车状态,正在刹车标志
int nstpsta, innstp; // 停车状态,正在停车标志
}paraList;
}ctrlPara;
}SeparateMotionCtrl;
#define PULSE_DIR_POSI 1
#define PULSE_DIR_NEGA -1
#define SEPRUN_TPYE_MVMT 0 // 位置控制
#define SEPRUN_TPYE_SPEED 1 // 速度控制
//--------------------------------------------------
// 多轴直线插补运动
// 直线插补运动控制结构
typedef struct
{
s32 movement[MAX_AXIS_NUM]; // 各个轴的运动量0无运动其他运动长度单位p
MotionSpeedCtrl spdPara; // 速度控制参数
// 回调函数及参数
MotionCallbackCtrl callback;
// 反馈信息
int errInfo; // 错误信息
}InterMotionCtrl;
//--------------------------------------------------
// 单轴连续位移运动
// 交换数据
typedef struct
{
// 设置数据
u32 mvmtStatus; // 本次运动数据状态0无效1有效
s32 movement; // 位移参数,本段位移
s32 thisIdx;
float thisBegPPS; // 本次的启动速度,也是上段结束时的速度
float thisEndPPS; // 本次结束时的速度
float thisRunPPS; // 本次的运行速度
float thisAddPPSS; // 本次的运行加速度
//----反馈状态
int bufsta; // 缓冲区状态
int runsta;
s32 exeingIdx;
float exeingMaxPPS;
s32 lastmvmt; // 上段的位移
float lastRunPPS;
float lastEndPPS; // 上次结束时的速度,也就是本段(正在执行段)的起始速度(每次表结束时设置)
float lastAddPPSS; //
int rslt;
int err;
}MotionSwapData;
typedef struct
{
int motoIdx; // 运动轴索引
// 回调函数
void (*RefreshPosition)(u32, s32*); // 坐标刷新回调函数
u32 refPosPara; // 坐标刷新参数
void (*RefreshData)(u32, u32); // 数据刷新回调函数
u32 refDatPara; // 数据刷新函数参数
MotionSwapData swapData; // 交换的位移和速度
// 反馈信息
int errInfo; // 错误信息
int exerslt;
int stopflag;
int runningflag;
// 中间变量
}ContinuousMotionCtrl;
#endif