一种步进电机加速曲线的实现方式
本帖最后由 qaya 于 2018-4-24 08:44 编辑在论坛学习了这么久,无以回报,把自己的一个雕虫小技发上来给大家参考,做成PDF方便下载。
补充一下,楼下有朋友问到S曲线,这里加上一段求S曲线的代码。代码是从其他地方拷贝来的,已经不记得来源了,这里对作者表示感谢。
/*calculate the Period and Freq array value, fill the Period value into the Period register during the timer interrupt.
*calculate the acceleration procedure , a totally 1000 elements array.
* parameter fre[]: point to the array that keeps the freq value.
* period[]: point to the array that keeps the timer period value.
* len: the procedure of acceleration length.it is best thing to set the float number, some compile software maybe transfer error if set it as a int
* fre_max: maximum speed, frequency vale.
* fre_min: start minimum speed, frequency vale.mind : 10000000/65535 = 152, so fre_min can't less than 152.
* flexible:flexible value. adjust the S curves
*/
void CalculateSModelLine(float fre[],unsigned short period[], floatlen,float fre_max,float fre_min, float flexible)
{
int i=0;
float deno ;
float melo ;
float delt = fre_max-fre_min;
for(; i<len; i++)
{
melo = flexible * (i-len/2) / (len/2);
deno = 1.0 / (1 + expf(-melo)); //expf is a library function of exponential(e)
fre = delt * deno + fre_min;
period = (unsigned short)(10000000.0 / fre); // 10000000 is the timer driver frequency
}
return ;
}
不错,多谢! 不错,写得挺详细的 很详细, 谢谢LZ无私分享
谢谢分享 可以,学习了,谢谢! 帮你把首页截下来,先睹为快,再决定下载与否。 谢谢,写得挺详细的 谢谢分享 谢谢分享 就冲分享精神也要顶 谢谢LZ无私分享 楼主辛苦了 谢谢分享 学习了,谢谢分享! 谢谢楼主的分享,进来学习一下 步进电机 顶一下 学习了,以前都是用inderect指令,没想到有更简单方便的 楼主的方法和我的很像哦,但是我的限定值是为时间,比如从2K升到20K,限定0.1s,也是通过EXCEL得出的,貌似现在也只能用于直线加减速,S的还没有找到和是的公式 不过最近搞了STM32F4(有浮点指令),准备直接在MCU里面运算出相应的数据了,这样也灵活得多了 MARK!!!!!! 谢谢分享 又占空间又占时间,直接上STM32 DMA传送,省时又省力 楼主,棒棒的,谢谢分享! 顶楼主,十分感谢 谢谢分享! 本帖最后由 XTXB 于 2018-7-21 10:15 编辑
amxx 发表于 2018-4-23 20:47
楼主的方法和我的很像哦,但是我的限定值是为时间,比如从2K升到20K,限定0.1s,也是通过EXCEL得出的,貌似 ...
楼主的计算方法高明!楼主以距离为加速度曲线的横坐标,个人觉得以时间为横坐标才是加速度的本意。 感谢分享 向楼主学习一下 学习 用了自然对数?不如把这个对数改成一个表?应该问题也不大吧。 谢谢LZ无私分享
页:
[1]