结合我学习c语言的经验, 总结一下几个典型的脚本运用;
一阶惯性滤波:
float k = GetTagFloat("factor"); //滤波系数
float out = GetTagFloat("filterOut") * (1 - k) + GetTagFLoat("filterIn")*k;
SetTagFloat("filterOut", out);
可设时间脉冲, 妙级, 需要在全局脚本1S动作中运行;
int n = GetTagSWord("Tn"); //脉冲长度
static int count = 0;
static int tmp = 0;
static int flag = 0;
if(!tmp && GetTagBit("Tirg")) //触发命令 (上升沿)
{
flag = 1; //脉冲有效
}
if(flag)
{
if(++count <= n)
{
SetTagBit("Pout", (short)1);
}
else
{
SetTagBit("Pout", (short)1);
flag = 0;
}
}
tmp = GetTagBit("Trig"));
3. 平均值
double GetAverage(double v, double lv, int n)
{
// v: 当前元素, lv:平均值保存, n:第n个元素
double sum = lv * (n - 1);
return (sum + v) / n;
}
此方法可避免v和n都比较大是造成的数据溢出;
4.画面循环, 如果放在全局脚本, 就是定时循环
char *pdl[5] = {"画面1.pdl", "画面2.pdl", "画面3.pdl", "画面4.pdl", "画面5.pdl"};
static int n = 0;
OpenPicture(pdl[n++ % 5]);
未完待续,