You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.1 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "axis.h"
enum EM_CRDID
{//坐标ID每个卡只能有2个
EM_CRD_FST = 1,
EM_CRD_SEC,
};
struct CrdData;
struct TCrd
{//坐标系数据
bool buse; //是否使用中
char crd; //坐标系ID
ushort axisCnt;
ushort axisIndex[MAXAXIS];
CrdData *pCrdData;
};
enum EM_ARC_TYPE
{//圆弧插补类型
EM_ARC_XY = 0, //xy 平面圆弧
EM_ARC_YZ,
EM_ARC_ZX,
};
class CCard
{
public:
CCard(ushort cardIndex);
virtual ~CCard();
int Open();
int Close();
int Reset();
//单轴点位运动
int AxisReset(ushort axisIndex);
int AxisZeroPos(ushort axisIndex); //单轴清零位置
int AxisIsMoving(ushort axisIndex); //1运动中 0就绪
int AxisStop(ushort axisIndex, int stopType);
int AxisSetSpeed(ushort axisIndex, double vel);
int AxisSetPos(ushort axisIndex, long pos);
int AxisGetPos(ushort axisIndex, EMPosType postype, double* pval);
//dir 0 负方向 1 正方向
int AxisMoveJog(ushort axisIndex, int dir, double vel, double acc, double dec);
int AxisMovePos(ushort axisIndex, long pos, double vel, double acc, double dec);
int AxisHome(ushort axisIndex, ushort homeType, long pos, long offset, double vel);
int AxisMoveOffset(ushort axisIndex, long offset, double vel, double acc, double dec);
//IO操作
int ReadBit(ushort in_index, EIOType di_type);
int ReadOutBit(ushort out_index, EIOType do_type);
int WriteOutBit(ushort out_index, ushort val, EIOType do_type);
//AD
int ReadADC(ushort index, double* pval);
int WriteADC(ushort index, double val);
//插补运动
int CreateCrd(ushort *pAxisIndex, ushort nsize, int& crd); //成功返回坐标系ID 失败返回-1
int CloseCrd(int index);
int AddLinePos(int index, double *ppos, double vel, double acc, double dec);
int AddArcPos(int index, double *ppos1, double *ppos2, double *ppos3, double vel, double acc, double dec);
int CrdStartMove(int index);
int CrdStatus(int index, int *progress);
//命令行 接口
int SendCustomCommand(const char* msg, char* res/* = 0*/);
int RecvCustomCommand(const char* msg, char* res/* = 0*/, int timeout/* = 0*/);
int ComparePos(ushort axisCnt, short time, long *pBuf1, short count1, long *pBuf2, short count2);
bool _bOpened; //是否已经打开
ushort _cardIndex; //卡索引
CAxis* _pAxis[MAXAXIS]; //轴数组类指针
protected:
void CloseAllAxis(); //关闭所有轴
int GetExistCrd(); //获取空闲坐标系索引
int SetCrd(TCrd& crdData); //设置坐标系参数并创建
//IO
int ReadIn(EIOType di_type, long& val);
int ReadOut(EIOType do_type, long& val);
bool IsSamePos(long* pos1, long* pos2, int axisCnt); //判断两个位置是否一样
bool IsSameLine(long* pos1, long* pos2, long* pos3); //判断三点是否共线
int CalcArcType(long* pos1, long* pos2, long* pos3, int axisCnt, int &arcType); //通过位置计算圆弧插补类型 arcType EM_ARC_TYPE
void CalcCenter(long* pos1, long* pos2, long* pos3, double &x, double &y, double&r); //3个点计算圆心数组只取前两个
bool CalcDir(long *pos1, long* pos2, long* pos3); //判断一段圆弧方向true 顺时针 false 逆时针
short TransfIOType(short di_type); //把io读取/写入类型转换成固高卡的IO类型
int ParseGearMove(char* param);
//电子齿轮运动,主轴自己设置,这里只设置从轴运动
//masterAxis 主轴索引
//slaveAxis 从轴索引
//iGearType 传动模式 参考 EM_GEAR_TYPE
//ratio 传动比 主轴位移/从轴位移 比例
//masterSlope 缓冲区 从轴到达传动比时主轴的位移量
int GearMove(ushort masterAxis, ushort slaveAxis,
int iGearType, double ratio, long masterSlope = 0);
int SetBacklash(char* param); //设置反向间隙补偿
int SetArrive(char* param); //设置到位信号
int SetAD(char* param); //设置电压值
int ParseCompare(char* param); //01高速IO口号01一维/二维模式01 set/start个数/轴号
int SetComparePrm(short chn, short mode, short encx, short ency);//0高速IO口0 0一维模式 0设置位置比较参数位置比较关联X轴一维位置比较只能比Y轴若想比较X轴只能将其关联到Y轴上
int StartCompare(short chn, short mode, int count, long *px, long *py);
private:
TCrd _crd[MAXCRD]; //最多2个坐标系
};