Googol motion control card related knowledge points

Undertake all kinds of Googol motion control projects programmed with QT (C++), and those who are interested can chat privately.

# GTS motion controller-two-dimensional position comparison output extension function

Instruction 6  GT_2DCompareSetPrm

Instruction prototype short GT_2DCompareSetPrm(short chn,T2DComparePrm *pPrm);
Instructions Set two-dimensional position comparison output parameters .
Instruction type Immediate command, effective immediately after calling.
Instruction parameter This command has 2 parameters in total. The detailed information of the parameters is as follows.
chn Channel number 0: HSIO0 , channel number 1: HSIO1
pPrm

typedefstruct
{ short encx; //X comparison axis selection value range, 4-axis card is [1,4], 8-axis card is [1,8] short ency; //Y comparison axis selection value range, 4 The axis card is [1,4], the 8-axis card is [1,8] short source; //comparison source 0: planning, 1: encoder short outputType; //output mode 0: pulse, 1: level short startLevel; //Start level mode 0: position comparison output pin level reset 1: position comparison output pin level is reversed




short time; //Pulse width of pulse mode us

short maxerr; //The maximum allowable error of the comparison position in place, value range [0,512), unit: pulse

short threshold; //This parameter is set to 0

}  T2DComparePrm;

When source=0, the comparison source is the planner. When configuring the controller, the “pulse count source” of the “encoder” selection must be
set to “internal pulse counter”; when source=1, the “pulse count source must be set to “encoder”器”. Otherwise
, a parameter error will be reported.

Please refer to the command return value list.
Related instructions no
Command example Example 2 Set position comparison output data

High-speed input and output interface

The motion controller has 2 two -dimensional position comparison modules , which can be used to compare the encoder position or internal pulse counter position with the set position. The two two-dimensional position comparison modules can be connected to different comparison sources (encoders or pulse counters) .
When the encoder position or the internal pulse counter position reaches the set position, the high-speed IO (HSIO) port outputs pulse or reverse level.

The GT_2DCompareData instruction is used to transfer comparison data to the controller in an array . These comparison data are relative positions ,
that is, the offset relative to the controller position when GT_2DCompareStart is called . Supports non-monotonic direction data input, but the user needs to ensure
that the data in the position array can reach the trigger position during the movement, otherwise the system will be in a state of waiting for trigger. The user can also
set the one-dimensional comparison mode. At this time, the comparison module only compares the position data on the Y comparison axis.

After comparing the starting position, when the outer encoder or when comparing the internal pulse counter reaches the set position, if the selected fixed width pulse
impulse mode output from the output interface now provided a pulse, the pulse width can be set to 1 ~ 32767us; if Select the level
mode output, and immediately invert the level from the set output interface. When all comparison positions are triggered, the position comparison ends. Press level square
when output, can set the initial level of the comparator output, but setting up an initial pulse level output.

 

Each method includes two methods, positive and negative. The positive direction refers to the direction where the planned position is a positive number, and the negative direction refers to the direction where the planned position is a negative number. For example, "limit + Home return to origin" includes "positive Limit + Home return to origin" and "Negative limit + Home return to origin"; for each return to origin method, the offset can be set so that the final motor stop position has an offset from the origin position; The origin method may not find the origin due to factors such as the set search distance and unexpected motor stop. Most abnormal situations can be identified by checking the origin status. In addition, the SmartHome function supports each axis to return to the origin independently without affecting each other, that is, multiple axes can return to the origin at the same time.

Instruction 5  GT_2DComparePulse

Instruction prototype short GT_2DComparePulse(short chn,shortlevel,shortoutputType,short time);
Instructions Two-dimensional position comparison output single output.
Instruction type Immediate command, effective immediately after calling.
Instruction parameter This command has 4 parameters in total. The detailed information of the parameters is as follows.
chn Channel number 0: HSIO0, channel number 1: HSIO1
level The starting level of the position comparison output level mode (when outputType=0, level should be 1)
level=0, the position comparison output pin level is reset (returns to the level state after initialization)
level=1, position The comparison output pin level is reversed (the opposite of the level state after initialization)
outputType Output type 0: pulse mode , 1: level mode
time Pulse time in pulse mode, unit: us
Command return value Please refer to the command return value list.
Related instructions no
Command example Example 1 Output specified level or pulse

Instruction 4  GT_2DCompareMode

Instruction prototype short GT_2DCompareMode(short chn,short mode);
Instructions Set 2D position comparison output mode
Instruction type Immediate command, effective immediately after calling.
Instruction parameter This command has 2 parameters in total. The detailed information of the parameters is as follows.
chn Channel number 0: HSIO0 , channel number 1: HSIO1
mode Position comparison mode
COMPARE2D_MODE_1D represents one-dimensional comparison mode
COMPARE2D_MODE_2D represents two-dimensional comparison mode
Command return value Please refer to the command return value list.
Related instructions no
Command example Example 1 Output specified level or pulse

1. 开环(脉冲)控制模式
(1) 打开运动控制器, GT_Open
(2) 复位运动控制器, GT_Reset。复位后默认的控制模式为“脉冲+方向”的脉冲控制方式。若不
是采用“脉冲+方向”的控制方式,则可调用 GT_StepPulse 修改;当需要还原为“脉冲+方向”
的控制方式时,则可调用 GT_StepDir 指令;
(3) 检查相关轴驱动器报警信号有没有连接。(一般若采用步进电机,可能没有驱动器报警信
号),若没有连接,则应该调用 GT_AlarmOff 指令,使驱动器报警无效,默认是有效的;
(4) 检查相关轴的限位开关,若没有连接,则需要通过调用 GT_LmtsOff,使限位无效,默认是
有效的;若有连接,则要检查触发电平是否设置正确,可通过 GT_LmtSns 指令修改;
(5) 在确认前面两步操作之后,调用 GT_ClrSts,更新设置的状态;
(6) 调用 GT_AxisOn,使能驱动器,这样相应的电机便能工作了;
(7) 使轴运动,运动后,若出现编码器位置和规划位置方向不一致,则可通过调用 GT_EncSns
改变编码器的计数方向。
 

GT_ClrSts 清除驱动器报警标志、 跟随误差越限标志、 限位触发标志
1. 只有当驱动器没有报警时才能清除轴状态字的报警标志
2. 只有当跟随误差正常以后,才能清除跟随误差越限标志
3. 只有当离开限位开关,或者规划位置在软限位行程以内时才能
清除轴状态字的限位触发标志


 

若控制器刚复位完,轴 1 状态如图 4-12 所示;若将“4.3.3”设置写入了控制器,使报警无效,并点击“伺服使能”,轴 1 状态如图 4-13 所示。(注:可以同时启动 4 个轴状态显示对话框。对话框的“轴号”下拉列表可以选择控制轴号,选择后,对话框的标题将显示对应信息)。

紧急停止信号数字量输入选择:选择紧急停止信号的数字量输入的来源,运动控制器支持
将任何数字量输入信号配置为紧急停止信号,增加用户进行硬件接线的自由性。该项的第
一个下拉列表选择数字量输入的类型,默认为没有紧急停止信号;第二个下拉列表选择
字量输入的编号
,在第二个下拉列表中如果选择“none”,则表示该 axis 没有紧急停止信号。
紧急停止信号数字量输入选择可以通过指令 GT_SetStopIo 设置。
 

GT_GetPrfPos

指令原型 short GT_GetPrfPos(short profile, double *pValue, short count=1, unsigned long
*pClock=NULL)
指令说明 读取规划位置。
指令类型 立即指令,调用后立即生效。    
指令参数 该指令共有 4 个参数,参数的详细信息如下。
profile 起始规划轴号,正整数。
pValue 规划位置。单位: pulse。
count 读取的轴数,默认为 1, 正整数。
pClock 读取控制器时钟,默认值为: NULL,即不用读取控制器时钟。
指令返回值 请参照指令返回值列表。
相关指令 无。
指令示例 例程 5-1 获取轴 1 的轴状态、运动模式、位置、速度和加速度


 

 

GT_GetSts

指令原型 short GT_GetSts(short axis, long *pSts, short count=1, unsigned long *pClock=NULL)
指令说明 读取轴状态。
指令类型 立即指令,调用后立即生效。    
指令参数 该指令共有 4 个参数,参数的详细信息如下。
axis 起始轴号, 正整数
pSts 32 位轴状态字,详细定义参见表 5-2 轴状态定义。
count 读取的轴数,默认为 1, 正整数
pClock 读取控制器时钟,默认值为: NULL,即不用读取控制器时钟。
指令返回值 请参照指令返回值列表。
相关指令 GT_ClrSts
指令示例 例程 5-1 获取轴 1 的轴状态、运动模式、位置、速度和加速度

表 5-2 轴状态定义

0 保留
1 驱动器报警标志
控制轴连接的驱动器报警时置 1
2 保留
3 保留
4 跟随误差越限标志
控制轴规划位置和实际位置的误差大于设定极限时置 1
5 正限位触发标志
正限位开关电平状态为限位触发电平时置 1
规划位置大于正向软限位时置 1
6 负限位触发标志
负限位开关电平状态为限位触发电平时置 1
规划位置小于负向软限位时置 1
7 IO 平滑停止触发标志
如果轴设置了平滑停止 IO,当其输入为触发电平时置 1,并自动平滑停止该轴
8 IO 急停触发标志
如果轴设置了急停 IO,当其输入为触发电平时置 1,并自动急停该轴
9 电机使能标志
电机使能时置 1
10 规划运动标志
规划器运动时置 1
11 电机到位标志
规划器静止,规划位置和实际位置的误差小于设定误差带,并且在误差带内保持设定时
间后,置起到位标志
12~31 保留



 

GT_2DCompareStatus

指令原型 short GT_2DCompareStatus(short chn,short *pStatus,long *pCount,short *pFifo,short
*pFifoCount,short *pBufCount);
指令说明 读取二维位置比较输出状态。
指令类型 立即指令,调用后立即生效。    
指令参数 该指令共有 6 个参数,参数的详细信息如下。
chn 通道号 0: HSIO0,通道号 1: HSIO1
pStatus 0:正在进行比较输出 1:比较输出完成
pCount 位置比较已输出次数
pFifo 当前空闲 FIFO
pFifoCount 当前空闲 FIFO 剩余空间
pBufCount FPGA 中 FIFO 剩余空间, FPGA 的 FIFO 总大小为 512,启动位置比较之前,压入
的数据先进入 FPGA 的 FIFO
指令返回值 请参照指令返回值列表。
相关指令
指令示例


 

 

1. 后文涉及的函数指令说明均为单卡库函数指令
2. 单卡库和多卡库函数的区别在于多卡库的函数多了一个“卡号”参数(第一张卡的卡号为 0)。
3. 如果应用程序需要操作多张卡,仍然可以使用单卡库提供的函数,但是为了编程方便,建议直接使用多卡库,即使是只操作一张卡也可以使用多卡库。
4.与本说明书配套发行的 gts.dll 动态链接库包含了扩展 IO 模块的函数指令,用户可以直接调用操作扩展 IO 模块,函数指令的详细说明请参考扩展 IO 模块配套《扩展模块编程手册》。安装 GTS 控制卡的驱动后,无需再安装扩展 IO 模块驱动,两个驱动是
一样的

端子板 CN9、 CN10 和 CN11 接口是通用数字输入输出信号(简称通用 IO 信号)、原点输入信号(简称 HOME)、限位输入信号接口(简称 LIMIT)。

设置 Smart Home 回原点的参数,该参数为一结构体,详细参数定义及说明请参照
结构体 THomePrm
typedef struct
{
short mode;    // 回原点模式
short moveDir; // 设置启动搜索原点时的运动方向(如果回原点运动包含搜索 Limit 则为搜索 Limit 的运动方向):-1-负方向, 1-正方向
short indexDir; // 设置搜索 Index 的运动方向: -1-负方向,1-正方向,在限位+Index 回原点模式下 moveDir 与indexDir 应该相异
short edge; // 设置捕获沿: 0-下降沿, 1-上升沿
short triggerIndex; // 默认与回零轴号一致,不需要设置
short pad1[3]; // 保留,其中 pad1[0]表示捕获到 Home 后运动到最终位置
(捕获位置 + homeOffset)所使用的速度, 0 或其它值-
使用 velLow(默认), 1-使用 velHigh。
double velHigh; // 回原点运动的高速速度(单位: pulse/ms)
double velLow; // 回原点运动的低速速度(单位: pulse/ms)
double acc; // 回原点运动的加速度(单位: pulse/ms^2)
double dec; // 回原点运动的减速度(单位: pulse/ms^2)
short smoothTime; // 回原点运动的平滑时间:取值[0,50],单位: ms,
具体含义与 GTS 系列控制器点位运动相似
short pad2[3]; // pad2[1]表示在电机启动回零时是否检测机械处于限位或
原点位置, 0 或其它值-不检测(默认), 1-检测。如果
不启用检测则当机械刚好处于限位或原点位置时将无法
回零;如果启用检测则当机械处于限位或原点时电机会先
按照 escapeStep 参数设置的回退距离进行回退,在根据
具体回零模式进行回零,因此如果启用检测功能,那么
escapeStep 的值不能为 0,否则无法执行回退动作。对
于压到限位或原点的电平判断:控制器默认高电平触发,
即限位或原点处于高电平状态则控制器认为当前压在限
位或原点上面,若用户的限位开关或原点开关不是此种模
式接法,可以通过控制器配置里面的 Di 选择项选择限位
或原点并设置其的“输入反转”为“取反”。
long homeOffset; // 最终停止的位置相对于原点的偏移量
long searchHomeDistance; // 设定的搜索 Home 的搜索范围, 0 表示
搜索距离为 805306368
long searchIndexDistance; // 设定的搜索 Index 的搜索范围, 0 表示
搜索距离为 805306368
long escapeStep; // 采用“限位回原点” 方式时,反方向离开

限位的脱离步长
long pad3[2]; // 保留(不需要设置)
} THomePrm;

回原点模式宏定义:
HOME_MODE_LIMIT (10):限位回原点
HOME_MODE_LIMIT_HOME (11):限位+Home回原点
HOME_MODE_LIMIT_INDEX (12):限位+Index回原点
HOME_MODE_LIMIT_HOME_INDEX (13):限位+Home+Index回原点
HOME_MODE_HOME (20): Home回原点
HOME_MODE_HOME_INDEX (22): Home+Index回原点
HOME_MODE_INDEX (30): Index回原点
HOME_MODE_FORCED_HOME (40):强制Home回原点
HOME_MODE_FORCED_HOME_INDEX (41):强制Home+Index回原点

 

限位+Home 回原点:调用回原点指令,电机从所在位置以较高的速度往限位方向运动,如果
碰到限位,则反方向运动并启动高速硬件捕获,在设定的搜索范围内搜索 Home,当触发 Home
开关后,电机会以较低的速度运动到捕获的位置处(即 Home 开关)。

Home 回原点:调用回原点指令,电机从所在位置以较高的速度运动并启动高速硬件捕获,在
设定的搜索范围内寻找 Home,当触发 Home 开关后,电机会以较低的速度运动到捕获的位置
处。

int main(int argc, char* argv[])
{
short sRtn;
short gAxis = 1;
THomeStatus tHomeSts;
sRtn = GT_Open();
sRtn = GT_Reset();
sRtn = GT_AlarmOff(gAxis);
sRtn = GT_LmtsOn(gAxis); //如果没有接限位开关则需要把限位取消
sRtn = GT_LmtSns(3); //限位为低电平触发(按实际情况设置)
sRtn = GT_EncSns(1); //编码器方向设置(按实际编码器设置,保证规划位置与实际
位置方向一致)
sRtn = GT_ClrSts(gAxis);
sRtn = GT_ZeroPos(gAxis);
sRtn = GT_AxisOn(gAxis); //必须使能轴
//设置 Smart Home 回原点参数
THomePrm tHomePrm;
sRtn = GT_GetHomePrm(1,&tHomePrm);
tHomePrm.mode = 20;
tHomePrm.moveDir = 1;
tHomePrm.indexDir = 1;
tHomePrm.edge = 0;
tHomePrm.velHigh = 5;
tHomePrm.velLow = 1;
tHomePrm.acc = 0.1;
tHomePrm.dec = 0.1;
tHomePrm.searchHomeDistance = 200000;
tHomePrm.searchIndexDistance = 30000;
tHomePrm.escapeStep = 1000;
sRtn = GT_GoHome(1,&tHomePrm); //启动 Smart Home 回原点
do
{
sRtn = GT_GetHomeStatus(1,&tHomeSts); //获取回原点状态
} while(tHomeSts.run); //等待搜索原点停止
例程 3-1 检测 GT 指令是否正常执行
例程 4-1 修改编码器计数方向
例程 4-2 修改限位开关触发电平
例程 4-3 设置第 1 轴为脉冲控制“脉冲+方向”方式
例程 4-4 设置第 1 轴为闭环控制方式
例程 5-1 获取轴 1 的轴状态、运动模式、位置、速度和加速度
例程 6-1 点位运动
例程 6-2 Jog 运动
例程 6-3 PT 静态 FIFO
例程 6-4 PT 动态 FIFO
例程 6-5 电子齿轮跟随
例程 6-6 飞剪中的 follow 模式应用
例程 6-7 Follow 单 FIFO 模式
例程 6-8 Follow 双 FIFO 切换
例程 6-9 建立坐标系
例程 6-10 直线插补例程
例程 6-11 圆弧插补例程
例程 6-12 插补 FIFO 管理
例程 6-13 前瞻预处理例程
例程 6-14 刀向跟随功能 GT_BufMove()
例程 6-15 刀向跟随功能 GT_BufGear()
例程 6-16 刀向跟随功能——实际工件加工
例程 6-17 PVT 描述方式
例程 6-18 Complete 描述方式
例程 6-19 Percent 描述方式
例程 6-20 Continuous 描述方式
例程 7-1 访问数字 IO
例程 7-2 读取 8 个轴编码器和辅助编码器位置值
例程 7-3 访问 DAC
例程 7-4 访问 ADC
例程 8-1 Home/Index 捕获
例程 8-2 Home 回原点
例程 8-3 Home+Index 回原点
例程 8-4 探针捕获
例程 8-5 HSIO 捕获用法示例
例程 8-6 重复捕获使用说明
例程 9-1 软限位使用
例程 10-1 运动程序单线程累加求和
例程 10-2 运动程序多线程累加求和
例程 11-1 读取运动控制器版本号
例程 11-2 电机到位检测功能
例程 11-3 自动回原点
例程 11-4 位置比较输出指令详细的用法

例程代码
gitee

例程 4 二维位置比较的一维模式
由于二维位置比较模块对压入的数据没有单调性要求,其一维模式也同样对比较数据没有单调
性要求。

short rtn;
T2DComparePrm prm;
rtn =GT_2DCompareMode(0,COMPARE2D_MODE_1D); //使用二维位置比较的 1 维模式
prm.encx = 1; //1 维模式时,这个值没有用,但是必须是一个非 0 值
prm.ency = 1; //以 1 轴作为比较源
prm.maxerr = 3; //最大误差 pulse
prm.outputType = 0; //输出脉冲
prm.source = 0; //内部脉冲计数器
prm.startLevel = 0; //设置初始电平
prm.threshold = 0; //最优点计算阈值,用户无需关心,取 0
prm.time = 500; //脉冲宽度 us
rtn =GT_2DCompareSetPrm(0,&prm);二维位置比较输出

rtn =GT_2DCompareMode(1,COMPARE2D_MODE_1D); //使用二维位置比较的 1 维模式
T2DCompareData databuf[5];
databuf[0].px = 0;
databuf[0].py = 10000;
databuf[0].px = 0;
databuf[0].py = 20000;
rtn =GT_2DCompareData(0,2,databuf,0); //设置比较数据,只需设置 y 的数据, x 的数据取 0
rtn =GT_2DCompareStart(0);


 

Guess you like

Origin blog.csdn.net/qingzhuyuxian/article/details/98744633