Accelstepper 库中的参数计算公式

这篇博客详细介绍了Accelstepper库中步进电机加速参数的计算公式和原理,引用了David Austin的文章,探讨了如何在实时环境中生成步进电机的加速和减速速度曲线。文章提供了基本的数学公式和近似算法,讨论了定时器频率的选择、加速度的计算以及如何处理步进延迟的精度问题。此外,还提到了在不同速度和加速度变化下,如何通过改变步数在加速过程中调整加速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要完全调试电机的各个参数,例如最大速度,加速度等,就需要了解其计算公式和原理。

以下是代码注释:

/// This code uses speed calculations as described in 
/// "Generate stepper-motor speed profiles in real time" by David Austin 
/// http://fab.cba.mit.edu/classes/MIT/961.09/projects/i0/Stepper_Motor_Speed_Profile.pdf or
/// http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time or
/// http://web.archive.org/web/20140705143928/http://fab.cba.mit.edu/classes/MIT/961.09/projects/i0/Stepper_Motor_Speed_Profile.pdf

/// with the exception that AccelStepper uses steps per second rather than radians per second
/// (because we dont know the step angle of the motor)
/// An initial step interval is calculated for the first step, based on the desired acceleration
/// On subsequent steps, shorter step intervals are calculated based 
/// on the previous step until max speed is achieved.

红色部分内容可以从云盘下载:

链接:https://pan.baidu.com/s/16pFTsVpk6bxtFFilVpFYjw 
提取码:7wgc 
 

其原理来自于

A new algorithm for stepper-motor acceleration allows speed profiles to be parameterized and calculated in real time. This algorithm can run on a low-end microcontroller using only simple fixed-point arithmetic operations and no data tables. It develops an accurate approximation for the timing of a linear ramp with constant acceleration and deceleration.

一种新的步进电机加速算法允许速度分布参数化和实时计算。该算法只需要简单的定点算术运算,不需要数据表,就可以在低端微控制器上运行。它是一个精确的近似恒定速度的线性加速与减速时序。

It's commonly thought that the timing of a linear speed ramp for a stepper motor is too complex to be calculated in real time. The exact formula for the step delay is in Equation 8. The solution has been to store the ramp data in precompiled arrays, but this method is inflexible and wastes memory. The alternative has been to use a more powerful and expensive processor than otherwise needed or a high-level stepper-control IC. This article develops an accurate approximation that has been implemented in C using 24.8 fixed-point arithmetic on a mid-range PIC microcontroller.

人们普遍认为步进电机的线性速度加速的时序太过复杂,无法实时计算。步进延迟的精确公式如式8所示。解决方案是将加速数据存储在预编译的数组中,但是这种方法不灵活,而且会浪费内存。另一种选择是使用更强大、更昂贵的处理器或高级的步进控制芯片。本文开发了一种精确的近似方法,在C语言中,在中程PIC微控制器上使用了24.8的定点算法。

Motor step signals can be generated by a 16-bit timer-comparator module as commonly integrated in microcontrollers. On the PIC, the CCP (capture/compare/pwm) performs this function. It allows steps to be timed to the resolution of one timer period. Each step advances the motor by a constant increment, typically 1.8 degrees on a hybrid stepper motor.

电机步进信号可以由一个16位的时间比较器模块产生,通常集成在微控制器中。在PIC上,CCP(捕获/比较/pwm)执行这个功能。它允许将步数计时到一个计时器周期的分辨率。每一次步进都使电机前进一个恒定的增量,在混合步进电机上通常是1.8度。

The timer frequency should be as high as possible while still allowing long delays as the motor is accelerated from stop. A timer frequency of 1MHz has been used. A maximum motor speed of 300rpm is then equivalent to a delay count of 1,000. It's necessary to have high timer resolution to give smooth acceleration at high speed.

定时器频率应该尽可能高,当电机从停止开始加速时应仍然允许长时间的延迟。定时器的频率为1MHz。最大电机转速为300rpm时,相当于延迟计数为1000。要在高速运转时,以提供平稳的加速度,需要高分辨率定时器。

Notation and basic formulas  符号和基本公式
Delay (sec) programmed by timer count c :

定时器计数c计算延时(秒)

 Equation 1

f = timer frequency (Hz). 定时器频率
Motor speed ω (rad/sec) at fixed timer count c :

定时器计数c一定时计算电机的速度ω(rad/sec) (弧度每秒)(电机的每步走过的弧度/每步时间间隔(延时)=弧度每秒)

 Equation 2

α = motor step angle (radian).电机的步进角
1rad = 180/π = 57.3deg. 1rad/sec = 30/π = 9.55rpm.

Acceleration ω ' (rad/sec2 ) from adjacent timer counts c 1 and c 2:

相邻的定时器计数c c 1和c 2计算加速度ω”(rad / sec2):(加速度=(V1-V2)  /t)

 Equation 3

Equation 3 assumes fixed-count speed (Equation 2) at the midpoint of each step interval (Equation 1), as on a linear ramp, Figure 1. Note that ω ' resolution is inversely proportional to the cube of the speed.

方程3假设在每个步进间隔(方程1)的中点处具有固定计数的速度(方程2),就像在线性加速一样,如图1所示。注意,加速度ω”分辨率与速度围成的巨型大小成反比。(分的越细分辨率越高)对速度求导就是加速度,线性速度对应恒定加速度。


Figure 1: Ramp geometry: move of m =12 steps

速度曲线,12步的速度曲线

Linear speed ramp—exact 线性速度渐变


On a linear ramp, acceleration ω ' is constant, and speed ω

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值