case7是消顶30%(可调)比如幅值A=2,f=5s,输出就是1.4,频率f不变;
case8是频率增加30%(可调)比如幅值A=2,f=5s,输出频率是6s,幅值不变
variables
{
float Curve_Type=0;
float Curve_Type1=0;
float Curve_A,Curve_T;
float amplitude ; //设置振幅为5
float frequency ; //设置频率为0.2Hz
float frequency1;
float frequency2;
float offset = 0;
float slope1 ; //计算斜率
float factor;
float factor1;
float count;
float count1;
float count2;
float count3;
int t;
}
on start
{
setTimer(Tcycle_APA,10);
}
on timer Tcycle_APA //循环
{
switch(Curve_Type)
{
case 0:
i=0;
l=0;
time=0;
break;
case 7: //消顶30%(可调)比如幅值A=2,f=5s,输出就是1.4,频率f不变;
amplitude=Curve_A; //设置振幅为*
frequency=Curve_T*25 ; //设置频率为*
frequency1 =frequency*0.3; //削掉三角波平顶百分比。
frequency2 =frequency-frequency1;
if(count< frequency)
{
if(count< frequency2)
{
count++;
t++;
slope1= amplitude/(frequency*100); //a*2f/1000
j =offset + slope1 * t*10; //输出信号
}
else
{
count++;
j =offset + slope1 * t*10; //输出信号
}
}
else if(count1<frequency2)
{
count1++;
t--;
slope1= amplitude/(frequency*100);
j =offset + slope1 * t*10; //输出信号
}
else if(count2 < frequency) //0以下
{
if(count2<frequency2)
{
count2++;
t--;
slope1= amplitude/(frequency*100);
j =offset + slope1 * t*10; //输出信号
}
else
{
count2++;
j =offset + slope1 * t*10; //输出信号
}
}
else if(count3<frequency2)
{
count3++;
t++;
slope1= amplitude/(frequency*100);
j =offset + slope1 * t*10; //输出信号
}
else
{
count1 = 0; //计数器清零
count = 0; //计数器清零
count2 = 0; //计数器清零
count3 = 0; //计数器清零
}
factor=j*10; //保留小数位后一位
_round(factor);
factor1=factor/10;
putValue(AD_Target_Angle,factor); //输出
break;
case 8: //频率增加30%(可调)比如幅值A=2,f=5s,输出频率是6s,幅值不变
amplitude=Curve_A; //设置振幅为*
frequency=Curve_T*25 ; //设置频率为*
frequency1 =frequency*0.3; //削掉三角波平定百分比。
frequency2 =frequency+frequency1;
if(count< frequency2)
{
if(count< frequency)
{
count++;
t++;
slope1= amplitude/(frequency*100); //a*2f/1000
j =offset + slope1 * t*10; //输出信号
}
else
{
count++;
write("q13");
j =offset + slope1 * t*10; //输出信号
}
write("q121");
}
else if(count1<frequency)
{
count1++;
t--;
slope1= amplitude/(frequency*100);
j =offset + slope1 * t*10; //输出信号
}
else if(count2 < frequency2) //0以下
{
if(count2<frequency)
{
count2++;
t--;
slope1= amplitude/(frequency*100);
j =offset + slope1 * t*10; //输出信号
}
else
{
count2++;
j =offset + slope1 * t*10; //输出信号
}
}
else if(count3<frequency)
{
count3++;
t++;
slope1= amplitude/(frequency*100);
j =offset + slope1 * t*10; //输出信号
write("count3=%f",count3);
write("q17");
write("j=%f",j);
}
else
{
write("q18");
count1 = 0; //计数器清零
count = 0; //计数器清零
count2 = 0; //计数器清零
count3 = 0; //计数器清零
}
factor=j*10; //保留小数位后一位
_round(factor);
factor1=factor/10;
putValue(AD_Target_Angle,factor);
break;
default:
break;
}
setTimer(Tcycle_APA,10);
}