极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18629|回复: 4

蛋疼的机翻 AccelStepper Class Reference 【步进电机库】

[复制链接]
发表于 2015-2-13 19:27:58 | 显示全部楼层 |阅读模式
  1. [url]http://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#a73bdecf1273d98d8c5fbcb764cabeea5ac3523e4cf6763ba518d16fec3708ef23[/url]

  2. 支持对步进电机加速等等。更多…
  3. 公共类型
  4. 枚举
  5. MotorInterfaceType {  //电机接口类型
  6.   FUNCTION = 0, DRIVER = 1, FULL2WIRE = 2, FULL3WIRE = 3,
  7.   FULL4WIRE = 4, HALF3WIRE = 6, HALF4WIRE = 8
  8. }
  9. 符号名为pin的数量。使用这个在AccelStepper针参数构造函数提供一个符号名的别针。
  10. FUNCTION        
  11. 使用功能接口,实现你自己的驱动程序功能(仅内部使用)
  12. DRIVER        
  13. 步进驱动,2线驱动。
  14. FULL2WIRE        
  15. 2线整步
  16. FULL3WIRE        
  17. 3线整步
  18. FULL4WIRE        
  19. 4线整步
  20. HALF3WIRE        
  21. 3线半步
  22. HALF4WIRE        
  23. 4线半步

  24. Public Member Functions//公共成员函数



  25. AccelStepper (uint8_t interface=AccelStepper::FULL4WIRE, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5, bool enable=true)

  26. 参数
  27. [in]        interface
  28. 引脚数接口。1,2,4或8个都支持,但它是优选使用 MotorInterfaceType  符号名
  29. AccelStepper::DRIVER (1) 指步进驱动器(与步骤和方向引脚)。如果还需要一个能线,调用 setEnablePin()  施工后。您也可以使用反转引脚setPinsInverted().
  30. AccelStepper::FULL2WIRE (2)指2线步进(需要2个引脚)。
  31. AccelStepper::FULL3WIRE(3)指3线步进,如HDD主轴(需要3引脚)。
  32. AccelStepper::FULL4WIRE (4)意味着一个4线步进(4引脚 需要)。
  33. AccelStepper::HALF3WIRE (6) means a 3 wire half stepper, such as HDD spindle (3 pins required)
  34. AccelStepper::HALF4WIRE (8)指4线半步进(4引脚需要)默认为 AccelStepper::FULL4WIRE   (4) pins.

  35. [in]        pin1(步)
  36. Arduino的数字引脚数电机引脚1.默认为引脚2.对于 AccelStepper::DRIVER  (interface==1), 这是步骤输入到驱动器。从低到高的转变意味step)
  37. [in]        pin2(驱动方向)
  38. Arduino的数字引脚数电机引脚2.默认为引脚3.对于 AccelStepper::DRIVER  (interface==1), 这是方向输入的驱动程序。高意味着前进。

  39. [in]        pin3
  40. Arduino的数字引脚数电机引脚3.默认为引脚4.

  41. in]        pin4
  42. Arduino的数字引脚数电机引脚4.默认为引脚5.

  43. [in]        enable
  44. 如果这是1(默认), enableOutputs()  将被调用,以使输出引脚的施工时间。

  45. References DIRECTION_CCW, enableOutputs(), and setAcceleration().

  46. AccelStepper (void(*forward)(), void(*backward)())
  47. 可选的构造,将调用自己的功能向前和向后的步骤。 你可以有多个同时步进,所有运动以不同的速度和加速度,只要你调用它们的run() 在足够频繁的时间间隔功能。
  48. 当前位置被设置为0,目标位置被设定为0。
  49. MaxSpeed and Acceleration 默认为1.0。
  50. 任何运动初始化应 发生前,  无引脚使用或初始化。

  51. 参数
  52. [in]        forward
  53. 空隙返回程序,这将使向前一步
  54. [in]        backward
  55. 空隙返回程序,这将使倒退
  56. References DIRECTION_CCW, and setAcceleration().

  57. void         moveTo (long absolute)
  58. 设置目标位置. run() 函数将试图将电动机(每次调用最多一步)从当前位置到目标位置的最近调用这个函数。注意:moveTo 也会重新计算速度对下一步骤。如果你要使用恒速运动,应该调用setSpeed() 后调用moveTo().

  59. 参数
  60. [in]        absolute
  61. 所需的绝对位置。负为0的位置逆时针。
  62. Examples:
  63. Bounce.pde, MultiStepper.pde, Overshoot.pde, ProportionalControl.pde, Quickstop.pde, and Random.pde.
  64. References computeNewSpeed().
  65. Referenced by move(), and runToNewPosition().

  66. void         move (long relative)
  67. 设置目标位置相对于当前位置
  68. 参数

  69. [in]        relative
  70. 所需的位置相对于当前位置。负是从当前位置逆时针。
  71. References moveTo().
  72. Referenced by stop().


  73. boolean         run ()
  74. 投票电机和步骤,如果一步是因为,实施加速度
  75. 和减速到acheive目标位置。必须以最小的步骤的时间间隔称之为尽可能频繁地,但至少一次,最好是在主回路。请注意,每个调用 run() 将至多一个步,然后,只有当一个步是由于,基于当前速度和自最后步骤的时间。

  76. 返回
  77. 真 , 如果电机仍在运行到目标位置。

  78. Examples:
  79. Bounce.pde, MultiStepper.pde, Overshoot.pde, Quickstop.pde, and Random.pde.
  80. References computeNewSpeed(), distanceToGo(), and runSpeed().
  81. Referenced by runToPosition().

  82. boolean         runSpeed ()
  83. 轮询电机,并加强它 如果一个步骤是因为,实施恒定的速度通过最近一次调用的设置为setSpeed().必须每步的时间间隔称此尽可能频繁地,但至少一次,
  84. 返回
  85. 真的,如果电机得到进一步加强。

  86. Examples:
  87. ConstantSpeed.pde.
  88. References DIRECTION_CW, and step().
  89. Referenced by run(), and runSpeedToPosition().


  90. void         setMaxSpeed (float speed)
  91. 设置允许的最大速度。在 run() 函数将加速上升的速度通过该功能设定。注意:最高速度可达到取决于你的处理器和时钟速度。
  92. 参数
  93. [in]        speed
  94. 所需的最大速度在每秒步骤。
  95. 必须>0。注意事项:速度超过了处理器所支持的最高速度在非线性加速和减速可能会导致。
  96. void         setAcceleration (float acceleration)
  97. 设定加速/减速速率。
  98. Parameters
  99. [in]        acceleration
  100. 所需的加速的步/秒秒,acceleration>0.0。这是一种昂贵的调用,因为它需要一个平方根来计算的。尽量少用
  101. Examples:
  102. Blocking.pde, Bounce.pde, MultiStepper.pde, Overshoot.pde, Quickstop.pde, and Random.pde.
  103. References computeNewSpeed().
  104. Referenced by AccelStepper().

  105. void         setSpeed (float speed)
  106. 设置所需的恒定速度与使用 runSpeed().
  107. 参数
  108. [in]        speed
  109. 所需的恒定速度在每秒步骤。正为顺时针。每秒超过1000步的速度是不可靠的。非常慢的速度可以设置(如0.00027777对每小时一次,大约。速度精度取决于Arduino的结晶。抖动取决于你如何频繁调用 runSpeed()函数。
  110. float         speed ()
  111. 最近设置的速度
  112. 返回
  113. 最近的速度在每秒步
  114. Referenced by setMaxSpeed(), and setSpeed().
  115. long         distanceToGo ()
  116. 从当前位置到目标位置的距离。
  117. 返回
  118. 从当前位置到在步骤目标位置的距离。正为顺时针从当前位置。
  119. Examples:
  120. Bounce.pde, MultiStepper.pde, and Random.pde.
  121. Referenced by computeNewSpeed(), and run().


  122. long         targetPosition ()
  123. 最近设置的目标位置。
  124. 返回
  125. 在步骤目标位置。正为顺时针方向从0位置。
  126. long         currentPosition ()
  127. 当前电动机位置。
  128. 返回
  129. 在步骤的当前电动机位置。正为顺时针方向从0位置。
  130. 例如:
  131. Bounce.pde, MultiStepper.pde, Overshoot.pde, and Quickstop.pde.
  132. void         setCurrentPosition (long position)
  133. 重置马达的当前位置,使得无论电动机恰好是正确的,现在被认为是新的0位置。可用来设定一个初始的硬件定位运动后步进零位。具有当前马达速度设置为0的副作用。
  134. [in]        position
  135. 设置步进电机现在的位置
  136. void         runToPosition ()
  137. 使电机的当前选定的恒定速度(前进或后退)到目标位置和阻塞,直到它在位置上。不使用此事件循环,因为它会阻止。
  138. Examples:
  139. Quickstop.pde.
  140. References run().
  141. Referenced by runToNewPosition().

  142. boolean         runSpeedToPosition ()
  143. 运行在当前选择的速度,直到到达目标位置不执行加速度。
  144. 返回
  145. 1,如果它在运行?//true if it stepped
  146. void         runToNewPosition (long position)
  147. 移动电机到新的目标位置和阻塞,直到它在位置上。不使用此事件循环,因为它会阻止。
  148. [in]        position
  149. 新的目标位置。
  150. Examples:
  151. Blocking.pde, and Overshoot.pde.
  152. References moveTo(), and runToPosition().

  153. void         stop ()
  154. 设置一个新的目标位置,导致步进停止尽可能快,使用当前的速度和加速度的参数。
  155. Examples:
  156. Quickstop.pde.
  157. References move().

  158. virtual void         disableOutputs ()
  159. 通过设置他们都LOW根据您的电子产品的设计,这可能在电源关闭的电机线圈,省电禁用电机引脚输出。这是非常有用的支持Arduino的低功耗模式:睡眠,然后重新启用期间禁用输出 withenableOutputs()  前再次加强。
  160. virtual void         enableOutputs ()
  161. 通过设置电机引脚输出模式使电机引脚输出。由构造自动调用。
  162. References FULL3WIRE, FULL4WIRE, HALF3WIRE, and HALF4WIRE.
  163. Referenced by AccelStepper().

  164. void         setMinPulseWidth (unsigned int minWidth)
  165. 设置由步进驱动所允许的最小脉冲宽度。最小实际脉冲宽度为大约20微秒。时间小于20微秒,通常会导致在20微秒左右。
  166. [in]        minWidth
  167. 的最小脉冲宽度为微秒。

  168. void         setEnablePin (uint8_t enablePin=0xff)
  169. 设置步进驱动器的使能引脚数量。 0xFF的指示未使用(默认)。否则,如果一个引脚设置,引脚将在何时开启enableOutputs() 调用并关机的时候disableOutputs() 调用
  170. Parameters
  171. [in]        enablePin
  172. 电机使Arduino的数字引脚数
  173. See Also
  174. setPinsInverted

  175. void         setPinsInverted (bool directionInvert=false, bool stepInvert=false, bool enableInvert=false)
  176. 设置反转步进驱动器引脚
  177. 参数
  178. [in]        directionInvert        为True变换方向针,假的非反转
  179. [in]        stepInvert        为True反转步销,假的非反转
  180. [in]        enableInvert        为True反转使能引脚,假(默认值)的非反转

  181. void         setPinsInverted (bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert)
  182. 设置反转2,3和4线步进针脚
  183. 参数
  184. [in]        pin1Invert        为True反转PIN1,假的非反转
  185. [in]        pin2Invert        为True反转PIN2码,假的非反转
  186. [in]        pin3Invert        为True反转PIN3,假的非反转
  187. [in]        pin4Invert        为True反转PIN4,假的非反转
  188. [in]        enableInvert        为True反转使能引脚,假(默认值)的非反转


  189. Protected Types//保护类型

  190. Direction { DIRECTION_CCW = 0, DIRECTION_CW = 1 }
  191. 转向指示器符号名马达转动的方向。
  192. 枚举
  193. DIRECTION_CCW
  194. 顺时针方向。
  195. DIRECTION_CW
  196. 逆时针方向。

  197. Protected Member Functions

  198. //受保护的成员函数
  199. void         computeNewSpeed ()
  200. 强制库来计算一个新的瞬时速度,并设置为当前的速度。这就是所谓的库:
  201. ~在每一步之后
  202. ~在通过setMaxSpeed() 改变setMaxSpeed之后
  203. ~在通过setAcceleration()改变setAcceleration之后
  204. ~在通过move() or moveTo() 改变目标位置(相对或绝对)之后
  205. virtual void         setOutputPins (uint8_t mask)
  206. 低电平函数来设置电机输出引脚位0掩码对应_pin[0]位掩码1对应_pin[1]您可以覆盖这impment,例如串行芯片输出insted的直接使用输出引脚
  207. Examples:
  208. MotorShield.pde.
  209. References FULL3WIRE, FULL4WIRE, HALF3WIRE, and HALF4WIRE.
  210. Referenced by disableOutputs(), step1(), step2(), step3(), step4(), step6(), and step8().

  211. virtual void         step (long step)
  212. 所谓以执行步骤。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。缺省调用step1(), step2(), step4() or step8() ,这取决于对步进定义的管脚数。
  213. Parameters
  214. [in]        step        当前步相位数(0到7)
  215. virtual void         step0 (long step)
  216. 所谓执行使用步进功能(pins = 0),只有当需要的新的一步称为步。调用_forward() or _backward() 来执行步
  217. [in]        step        当前步相位数(0到7)
  218. virtual void         step1 (long step)
  219. 叫上执行步进驱动器的步骤(例如那里pins == 1)。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。
  220. 默认设置或清除步骤的pin1步骤的输出,  并设置_pin2向所希望的方向的输出。 步骤引脚(_pin1)是脉冲1微秒 这是最低STEP脉冲宽度为3967的驱动程序。
  221. [in]        step        当前步相位数(0到7)
  222. References setOutputPins().
  223. Referenced by step().

  224. virtual void         step2 (long step)
  225. 所谓的执行上2针电机的一个步骤。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。默认设置或清除PIN1和PIN2的输出
  226. virtual void         step3 (long step)
  227. 所谓的执行上3针电机,如HDD主轴的一步。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。默认设置或清除的PIN1,PIN2,Pin3输出
  228. virtual void         step4 (long step)
  229. 所谓执行一个4针电机的一个步骤。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。默认设置或清除PIN1,PIN2,PIN3,PIN4的输出。
  230. virtual void         step6 (long step)
  231. 所谓的执行上3针电机,如HDD主轴的一步。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。默认设置或清除的PIN1,PIN2,3脚输出
  232. virtual void         step8 (long step)
  233. 所谓执行一个4针半步r电机的一个步骤。只有当需要的新的一步调用。子类可以重写,以实现新的步进接口。默认设置或清除PIN1,PIN2,PIN3,PIN4的输出。


  234. 详细说明
  235. 支持步进电机加速等等。
  236. 这定义了单个2或4引脚的步进电机,或具有fdriver芯片步进启动子,可选的加速,减速,绝对定位命令等多个同时步进机都支持,都以不同的速度和加速度移动。
  237. =================
  238. 运算
  239. 此模块通过计算在微秒的步的时间。由调用者被改变后的各步与速度和加速度参数之后的步的时间被重新计算。每个步骤的时间被记录在微秒。在run()函数步骤电机一次,如果的新的一步到期。该run()函数必须被频繁调用直到电机是在所需的位置,在这之后时间运行()什么也不做。
  240. =============
  241. 定位
  242. 位置由一个符号长整型指定。在施工时,马达的当前位置被认为是0正的位置是沿顺时针方向从初始位置;负位置是逆时针。当前位置可以初始化定位之后被改变对于实例。
  243. ===============
  244. 警告
  245. 这是一个开环控制器:如果电机摊位或oversped,AccelStepper不会有当电机确实是一个正确的想法(因为电机的实际位置的任何反馈。我们只知道,我们认为这是相对的。到初始开始点)。
  246. ===============
  247. 性能
  248. 可以可靠地支撑最快电机速度是每秒约4000步在16兆赫上的Arduino如乌诺等更快的处理器的时钟频率可以支持更快步进速度。然而,比下降到非常低的速度(远小于1每秒)也支持的任何速度更小,所提供的run()函数被调用足够频繁到步骤电动机每当需要的速度设定。调用setAcceleration()是昂贵的,因为它需要一个平方根来计算的。
复制代码
回复

使用道具 举报

 楼主| 发表于 2015-2-13 20:19:28 | 显示全部楼层
本帖最后由 hi55234 于 2015-2-13 20:21 编辑

Basic Usage

You can create multiple AccelStepper objects, giving a unique name to each motor. AccelStepper can manage any number of motors, as long as you repetitively call their "run" functions.

您可以创建多个AccelStepper对象,每个电机提供一个唯一的名称。 AccelStepper可以管理任何数量的电动机,只要你反复地叫他们“跑”的功能。
Defining & Configuring Motors

定义和配置电动机

AccelStepper mystepper(1, pinStep, pinDirection);
A stepper motor controlled by a dedicated driver board.
由专门的驱动板控制的步进电机。

AccelStepper mystepper(2, pinA, pinB);
A bipolar stepper motor controlled by an H-Bridge circuit.
由H桥circuit.n控制的双极步进电机。

AccelStepper mystepper(4, pinA1, pinA2, pinB1, pinB2);
A unipolar stepper motor, controlled by 4 transistors.
单极步进电机,由4个晶体管控制。

mystepper.setMaxSpeed(stepsPerSecond);
Sets the maximum speed. The default is very slow, so this must be configured. When controlled by setting position, the stepper will accelerate to move at this maximum speed, and decelerate as it reaches the destination.
设置的最大速度。缺省值是很慢的,因此必须进行配置。当通过设定位置控制时,步进将加快移动至在该最大速度,减速,因为它到达目的地。

mystepper.setAcceleration(stepsPerSecondSquared);
Sets the acceleration to be used, in steps per second per second.
设置要使用的加速,在每秒每第二步骤。

========================================================
Position Based Control
基于位置控制

mystepper.moveTo(targetPosition);
Move the motor to a new absolute position. This returns immediately. Actual movement is caused by the run() function.
移动电机到一个新的绝对位置。这立即返回。实际运动由run()函数引起的。


mystepper.move(distance);
Move the motor (either positive or negative) relative to its current position. This returns immediately. Actual movement is caused by the run() function.
动马达(或正或负)相对于它的当前位置。这立即返回。实际运动由run()函数引起的。


mystepper.currentPosition();
Read the motor's current absolution position.
读取电机的绝对位置。


mystepper.distanceToGo();
Read the distance the motor is from its destination position. This can be used to check if the motor has reached its final position.
读取距离电机从目标位置。可如果电机已到达其最终位置用来检查。


mystepper.run();
Update the motor. This must be called repetitively to make the motor move.
更新电机。这必须调用反复,使电机的举动。


mystepper.runToPosition();
Update the motor, and wait for it to reach its destination. This function does not return until the motor is stopped, so it is only useful if no other motors are moving.
更新电机,并等待它到达目的地。此函数不返回,直到电机停止,所以它是只有在没有其他电机正在有用。

=================================================

Speed Based Control
基于速度控制

mystepper.setSpeed(stepsPerSecond);
Set the speed, in steps per second. This function returns immediately. Actual motion is caused by called runSpeed().
设定速度,以每秒的步骤。该函数立即返回。实际运动是由称为runSpeed()。

mystepper.runSpeed();
Update the motor. This must be called repetitively to make the motor move.
更新电机。这必须调用反复,使电机的举动。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-13 21:16:26 | 显示全部楼层
本帖最后由 hi55234 于 2015-2-13 21:21 编辑

1、梯形加速,应该是等价于最开始启动用的频率
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. LiquidCrystal_I2C lcd(0x26,16,2);  // I2C 1602转接板的地址


  4. int ACS712PinPin=0;//A0读取ACS712Pin 5A的电压的针脚
  5. int ACS712PinVal=0;//A0读取ACS712Pin 5A的电压值(0-1023)
  6. float ACS712PinValx=0;//A0读取ACS712Pin 5A的电压(换算为mV)
  7. int mySensVals [4];//四次取均值,待平均的值暂存数组中
  8. int jsq1=0;//四次取均值,取到第几次的计数器

  9. long quantime=0;

  10. long maichongpinlv = 0;//脉冲频率
  11. float lilunquanshu=0;//理论圈数

  12. /////////////////////////////////////

  13. #include <AccelStepper.h>

  14. AccelStepper Xaxis(1, 9, 8); // pin 9 = step, pin 8 = direction
  15. int pps=600;
  16. unsigned long time1=millis();

  17. void setup() {
  18.   Serial.begin(9600);

  19.   lcd.init();   
  20.   lcd.backlight();
  21.   //////////////////////////////////////
  22.   Xaxis.setMaxSpeed(2200);
  23.   Xaxis.setSpeed(pps);

  24. }

  25. void loop() {  
  26.    //电流读取部分
  27. ACS712PinVal=analogRead(ACS712PinPin);
  28. mySensVals [jsq1]=ACS712PinVal;
  29. jsq1++;

  30. if(jsq1==4){
  31. jsq1=0;
  32. ACS712PinValx=(mySensVals [0]+mySensVals [1]+mySensVals [2]+mySensVals [3])*0.25;
  33. ACS712PinValx=(ACS712PinValx*4.8-2433)*1000/185;
  34. }
  35.   /////////////////////////////////
  36.    Xaxis.runSpeed();
  37.    
  38.    if (millis() - time1 > 1000 && pps<2000){
  39.      
  40.      
  41. lcd.setCursor(0, 0);
  42. lcd.print(ACS712PinValx);
  43. lcd.print("mA p:");
  44. lcd.println(pps);//每秒脉冲数
  45. lcd.println("      ");//
  46.      ////////////////////////
  47.      pps=pps+30;
  48.      Xaxis.setSpeed(pps);
  49.      time1=millis();
  50.    }
  51. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2015-2-15 08:03:57 | 显示全部楼层
可联系下管理员,申请权限更新到wiki
http://wiki.geek-workshop.com/do ... o:libraries:stepper
回复 支持 反对

使用道具 举报

发表于 2015-2-26 21:14:08 来自手机 | 显示全部楼层
谢谢谢谢谢谢分享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-23 23:13 , Processed in 0.044340 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表