文章目录

  • Accelstepper 库中的参数计算公式
  • ACCELSTEPPER库函数解析(一)
    • moveTo
    • runToNewPosition
    • runSpeed
    • runToPosition
    • stop
    • runToPosition()和runSpeedToPosition():
  • ACCELSTEPPER库实例分析
    • 1. AFMotor_ConstantSpeed
    • 2. AFMotor_MultiStepper
    • 3. Blocking
    • 4. Bounce
    • 5. ConstantSpeed
    • 6. DualMotorShield
    • 7. AFMotor_ConstantSpeed
    • 8. MultiStepper
    • 9. MultiStepper
    • 10. Overshoot
    • 11. ProportionalControl
    • 12. Quickstop
    • 13. Random
  • ACCELSTEPPER库函数解析(二)
    • AccelStepper类引用
    • 1. [Public Types 公共类型](https://blog.csdn.net/wenguitao/article/details/104858382)
    • 2. [Member Function Documentation 成员函数](https://blog.csdn.net/wenguitao/article/details/104864118)
    • 3. [可以设定进入和停止位置的滑轨代码参考](https://blog.csdn.net/wenguitao/article/details/104623889?spm=1001.2014.3001.5501)

Accelstepper 库中的参数计算公式

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

ACCELSTEPPER库函数解析(一)

moveTo

设置最大速度setMaxSpeed和加速度后setAcceleration,电机将以这个加速度开始转动,直到速度到达最大速度。这个过程中会用到加减速。run()必须不断调用。注释:The run() function steps the motor once if a new step is due. The run() function must be called frequently until the motor is in the desired position, after which time run() will do nothing.

void setup()
{  usb.start();stepper1.setMaxSpeed(2000);   // 设置电机最大速度为2000//stepper1.setSpeed(50);      // 在这个应用中速度不需要设置stepper1.setAcceleration(200);stepper1.moveTo(1024);}void loop()
{  stepper1.run();
}

runToNewPosition

输入需要移动的脉冲后,电机就会以加减速移动到设定的位置。不需要循环run();

void setup()
{  usb.start();stepper1.setMaxSpeed(2000);   // 设置电机最大速度为2000//stepper1.setSpeed(50);      // 在这个应用中速度不需要设置stepper1.setAcceleration(200);}void loop()
{  //usb.println(stepper1.targetPosition());stepper1.runToNewPosition(1024);stepper1.runToNewPosition(2048);stepper1.runToNewPosition(0);
}

runSpeed

这个函数需要在循环中反复调用,可以让电机一直连续旋转。没有用到加减速,因此设置的速度不能太快。

void setup()
{  usb.start();stepper1.setMaxSpeed(2000);   stepper1.setAcceleration(200);//可以放在这里,但是连续旋转没有用到加速的设定//因此不要这条语句也可以。stepper1.setSpeed(500);      //stepper1.setAcceleration(200);这个加速度的设置,不能放在setSpeed的后面。}
void loop(){  //usb.println(stepper1.targetPosition());stepper1.runSpeed();
}

runToPosition

使用move或者moveTo设定需要移动的位置,再使用runToPosition,不需要run()循环

void setup()
{  usb.start();stepper1.setMaxSpeed(2000);   // 设置电机最大速度为2000stepper1.setAcceleration(200);}void loop()
{  //usb.println(stepper1.targetPosition());stepper1.move(1024);stepper1.runToPosition();stepper1.move(1024);stepper1.runToPosition();
}

让电机连续旋转,并且有加速度,这个方法很奇怪,但是实验结果就是有加速度的启动,这样可以让电机到达最快的转速。把move()放到loop中,而且里面的值对速度有影响,越大越快,单不会在设定的值后停下来,会一直转。

void setup()
{  usb.start();stepper1.setMaxSpeed(1200);   // 在这里设定连续旋转速度stepper1.setAcceleration(600);  //设置加速度//stepper1.setSpeed(2000); 不要在这里设置速度}void loop()
{  stepper1.move(4096);//旋转的方向在这里用过正负号来设置//stepper1.moveTo(4096);//换成这个moveTo就可以在指定位置停下来stepper1.run();}

stop

如果直接用stop,电机会立马停下来,所以需要提前设定一个开始减速的地方,再慢慢停下来,结合runToPosition来使用

void setup()
{  stepper1.setMaxSpeed(2000);
stepper1.setAcceleration(200);
}void loop()
{  stepper1.moveTo(2048);//目标位置是半圈,2048的位置while (stepper1.currentPosition() != 2000)  //设定提前减速的地方,这个值不好喝目标值相 //太远,比如设置成500stepper1.run();//while的含义是,只要没到2000,就一直run()。stepper1.stop(); //在2000的地方停止后,在慢慢移动到目标位置//整体感觉就是缓慢停下来。stepper1.runToPosition();
}

runToPosition()和runSpeedToPosition():

这两个不能单独使用,不像runToNewPosition()指哪里跑哪里,目前观察到的用法是在stop后,可以用他们一不同的方式到达目标位置,一个有加减速,一个没有

void setup()
{  stepper1.setMaxSpeed(2000);   // 设置电机最大速度为2000stepper1.setAcceleration(500);  stepper1.setSpeed(500);}void loop()
{  stepper1.moveTo(2048);//目标位置是半圈,2048的位置while (stepper1.currentPosition() != 2000)  //设定提前减速的地方,这个值不要和目标值相太远,比如设置成500stepper1.run();//while的含义是,只要没到2000,就一直run()。stepper1.stop(); //在2000的地方停止后,在慢慢移动到目标位置//整体感觉就是缓慢停下来。stepper1.runSpeedToPosition(); //到了500接着跑没有加减速//stepper1.runToPosition(); //有加减速
}

ACCELSTEPPER库实例分析

1. AFMotor_ConstantSpeed

演示如何非常简单的运行AccelStepper
固定速度模式没有加速度
需要AFMotor库
注意:Adafruit电机shield V2不兼容
浏览 https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
来获取如何在Adafruit电机shield V2运行的实例

// AFMotor_ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
// Requires the AFMotor library
// (https://github.com/adafruit/Adafruit-Motor-Shield-library)
// Caution, does not work with Adafruit Motor Shield V2
// See https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
// for examples that work with Adafruit Motor Shield V2.#include <AccelStepper.h>
#include <AFMotor.h>AF_Stepper motor1(200, 1);// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep() {  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep() {  motor1.onestep(BACKWARD, SINGLE);
}AccelStepper stepper(forwardstep, backwardstep); // use functions to stepvoid setup()
{  Serial.begin(9600);           // set up Serial library at 9600 bpsSerial.println("Stepper test!");stepper.setMaxSpeed(50); stepper.setSpeed(50);
}void loop()
{  stepper.runSpeed();
}

2. AFMotor_MultiStepper

控制两个电机以不同的速度和加速度同时运动

// AFMotor_MultiStepper.pde
// -*- mode: C++ -*-
//
// Control both Stepper motors at the same time with different speeds
// and accelerations.
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)
// Caution, does not work with Adafruit Motor Shield V2
// See https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
// for examples that work with Adafruit Motor Shield V2.#include <AccelStepper.h>
#include <AFMotor.h>// two stepper motors one on each port
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() {  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep1() {  motor1.onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {  motor2.onestep(FORWARD, SINGLE);
}
void backwardstep2() {  motor2.onestep(BACKWARD, SINGLE);
}// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);void setup()
{  stepper1.setMaxSpeed(200.0);stepper1.setAcceleration(100.0);stepper1.moveTo(24);stepper2.setMaxSpeed(300.0);stepper2.setAcceleration(100.0);stepper2.moveTo(1000000);}void loop()
{// Change direction at the limitsif (stepper1.distanceToGo() == 0)stepper1.moveTo(-stepper1.currentPosition());stepper1.run();stepper2.run();
}

3. Blocking

演示如何使用阻塞调用runToNewPosition,该调用设置一个新目标位置,然后等待,直到步进电机运行到指定位置。

// Blocking.pde
// -*- mode: C++ -*-
//
// Shows how to use the blocking call runToNewPosition
// Which sets a new target position and then waits until the stepper has
// achieved it.
//
// Copyright (C) 2009 Mike McCauley
// $Id: Blocking.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5void setup()
{  stepper.setMaxSpeed(200.0);stepper.setAcceleration(100.0);
}void loop()
{    stepper.runToNewPosition(0);stepper.runToNewPosition(500);stepper.runToNewPosition(100);stepper.runToNewPosition(120);
}

4. Bounce

从一个限位跳跃到另一个限位

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5void setup()
{  // Change these to suit your stepper if you wantstepper.setMaxSpeed(100);stepper.setAcceleration(20);stepper.moveTo(500);
}void loop()
{// If at the end of travel go to the other endif (stepper.distanceToGo() == 0)stepper.moveTo(-stepper.currentPosition());stepper.run();
}

5. ConstantSpeed

演示如何固定速度模式没有加速度方式非常简单的运行AccelStepper

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author  Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5void setup()
{  stepper.setMaxSpeed(1000);stepper.setSpeed(50);
}void loop()
{  stepper.runSpeed();
}

6. DualMotorShield

使用Itead Studio 双电机驱动板同时运行两个步进电机 实现两个电机同时来回移动

// DualMotorShield.pde
// -*- mode: C++ -*-
//
// Shows how to run 2 simultaneous steppers
// using the Itead Studio Arduino Dual Stepper Motor Driver Shield
// model IM120417015
// This shield is capable of driving 2 steppers at
// currents of up to 750mA
// and voltages up to 30V
// Runs both steppers forwards and backwards, accelerating and decelerating
// at the limits.
//
// Copyright (C) 2014 Mike McCauley
// $Id:  $#include <AccelStepper.h>// The X Stepper pins
#define STEPPER1_DIR_PIN 3
#define STEPPER1_STEP_PIN 2
// The Y stepper pins
#define STEPPER2_DIR_PIN 7
#define STEPPER2_STEP_PIN 6// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);void setup()
{  stepper1.setMaxSpeed(200.0);stepper1.setAcceleration(200.0);stepper1.moveTo(100);stepper2.setMaxSpeed(100.0);stepper2.setAcceleration(100.0);stepper2.moveTo(100);
}void loop()
{// Change direction at the limitsif (stepper1.distanceToGo() == 0)stepper1.moveTo(-stepper1.currentPosition());if (stepper2.distanceToGo() == 0)stepper2.moveTo(-stepper2.currentPosition());stepper1.run();stepper2.run();
}

7. AFMotor_ConstantSpeed

控制三相电机,例如硬盘主轴电机

// AFMotor_ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to use AccelStepper to control a 3-phase motor, such as a HDD spindle motor
// using the Adafruit Motor Shield
// http://www.ladyada.net/make/mshield/index.html.
// Create a subclass of AccelStepper which controls the motor  pins via the
// Motor Shield serial-to-parallel interface#include <AccelStepper.h>// Arduino pin names for interface to 74HCT595 latch
// on Adafruit Motor Shield
#define MOTORLATCH   12
#define MOTORCLK     4
#define MOTORENABLE  7
#define MOTORDATA    8// PWM pins, also used to enable motor outputs
#define PWM0A        5
#define PWM0B        6
#define PWM1A        9
#define PWM1B        10
#define PWM2A        11
#define PWM2B        3// The main purpose of this class is to override setOutputPins to work with Adafruit Motor Shield
class AFMotorShield : public AccelStepper
{public:AFMotorShield(uint8_t interface = AccelStepper::FULL4WIRE, uint8_t pin1 = 2, uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5); virtual void   setOutputPins(uint8_t mask);
};AFMotorShield::AFMotorShield(uint8_t interface, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4): AccelStepper(interface, pin1, pin2, pin3, pin4)
{// Enable motor control serial to parallel latchpinMode(MOTORLATCH, OUTPUT);pinMode(MOTORENABLE, OUTPUT);pinMode(MOTORDATA, OUTPUT);pinMode(MOTORCLK, OUTPUT);digitalWrite(MOTORENABLE, LOW);// enable both H bridges on motor 1pinMode(PWM2A, OUTPUT);pinMode(PWM2B, OUTPUT);pinMode(PWM0A, OUTPUT);pinMode(PWM0B, OUTPUT);digitalWrite(PWM2A, HIGH);digitalWrite(PWM2B, HIGH);digitalWrite(PWM0A, HIGH);digitalWrite(PWM0B, HIGH);setOutputPins(0); // Reset
};// Use the AF Motor Shield serial-to-parallel to set the state of the motor pins
// Caution: the mapping of AccelStepper pins to AF motor outputs is not
// obvious:
// AccelStepper     Motor Shield output
// pin1                M4A
// pin2                M1A
// pin3                M2A
// pin4                M3A
// Caution this is pretty slow and limits the max speed of the motor to about 500/3 rpm
void AFMotorShield::setOutputPins(uint8_t mask)
{uint8_t i;digitalWrite(MOTORLATCH, LOW);digitalWrite(MOTORDATA, LOW);for (i=0; i<8; i++) {digitalWrite(MOTORCLK, LOW);if (mask & _BV(7-i))digitalWrite(MOTORDATA, HIGH);elsedigitalWrite(MOTORDATA, LOW);digitalWrite(MOTORCLK, HIGH);}digitalWrite(MOTORLATCH, HIGH);
}AFMotorShield stepper(AccelStepper::HALF3WIRE, 0, 0, 0, 0); // 3 phase HDD spindle drivevoid setup()
{  stepper.setMaxSpeed(500);    // divide by 3 to get rpmstepper.setAcceleration(80);stepper.moveTo(10000000);
}void loop()
{  stepper.run();
}

8. MultiStepper

演示多电机同时控制

// MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>// Define some steppers and the pins the will use
AccelStepper stepper1; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);
AccelStepper stepper3(AccelStepper::FULL2WIRE, 10, 11);void setup()
{  stepper1.setMaxSpeed(200.0);stepper1.setAcceleration(100.0);stepper1.moveTo(24);stepper2.setMaxSpeed(300.0);stepper2.setAcceleration(100.0);stepper2.moveTo(1000000);stepper3.setMaxSpeed(300.0);stepper3.setAcceleration(100.0);stepper3.moveTo(1000000);
}void loop()
{// Change direction at the limitsif (stepper1.distanceToGo() == 0)stepper1.moveTo(-stepper1.currentPosition());stepper1.run();stepper2.run();stepper3.run();
}

9. MultiStepper

使用 MultiStepper类管理多个电机,使它们移动到相同的位置在相同的时间,达到二维或三维的运动

// MultiStepper.pde
// -*- mode: C++ -*-
// Use MultiStepper class to manage multiple steppers and make them all move to
// the same position at the same time for linear 2d (or 3d) motion.#include <AccelStepper.h>
#include <MultiStepper.h>// EG X-Y position bed driven by 2 steppers
// Alas its not possible to build an array of these with different pins for each :-(
AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 3, 4, 5);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 8, 9, 10, 11);// Up to 10 steppers can be handled as a group by MultiStepper
MultiStepper steppers;void setup() {Serial.begin(9600);// Configure each stepperstepper1.setMaxSpeed(100);stepper2.setMaxSpeed(100);// Then give them to MultiStepper to managesteppers.addStepper(stepper1);steppers.addStepper(stepper2);
}void loop() {long positions[2]; // Array of desired stepper positionspositions[0] = 1000;positions[1] = 50;steppers.moveTo(positions);steppers.runSpeedToPosition(); // Blocks until all are in positiondelay(1000);// Move to a different coordinatepositions[0] = -100;positions[1] = 100;steppers.moveTo(positions);steppers.runSpeedToPosition(); // Blocks until all are in positiondelay(1000);
}

10. Overshoot

检查超调处理,它设置一个新的目标位置,然后等待,直到步进电机实现它。这用于测试超调的处理(overshoot 过冲,超调?)

// Overshoot.pde
// -*- mode: C++ -*-
//
// Check overshoot handling
// which sets a new target position and then waits until the stepper has
// achieved it. This is used for testing the handling of overshoots
//
// Copyright (C) 2009 Mike McCauley
// $Id: Overshoot.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5void setup()
{  stepper.setMaxSpeed(150);stepper.setAcceleration(100);
}void loop()
{    stepper.moveTo(500);while (stepper.currentPosition() != 300) // Full speed up to 300stepper.run();stepper.runToNewPosition(0); // Cause an overshoot then back to 0
}

11. ProportionalControl

让一个步进电机跟随从一个旋钮中读取的模拟值,或者步进电机将根据旋钮中的值以恒定的速度移动到每个新设置的位置。

// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton,
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0void setup()
{  stepper.setMaxSpeed(1000);
}void loop()
{// Read new positionint analog_in = analogRead(ANALOG_IN);stepper.moveTo(analog_in);stepper.setSpeed(100);stepper.runSpeedToPosition();
}

12. Quickstop

查看停止处理。当步进电机全速运行时调用stop(),使步进电机在当前加速度的约束下尽可能快地停止。

// Quickstop.pde
// -*- mode: C++ -*-
//
// Check stop handling.
// Calls stop() while the stepper is travelling at full speed, causing
// the stepper to stop as quickly as possible, within the constraints of the
// current acceleration.
//
// Copyright (C) 2012 Mike McCauley
// $Id:  $#include <AccelStepper.h>// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5void setup()
{  stepper.setMaxSpeed(150);stepper.setAcceleration(100);
}void loop()
{    stepper.moveTo(500);while (stepper.currentPosition() != 300) // Full speed up to 300stepper.run();stepper.stop(); // Stop as fast as possible: sets new targetstepper.runToPosition(); // Now stopped after quickstop// Now go backwardsstepper.moveTo(-500);while (stepper.currentPosition() != 0) // Full speed basck to 0stepper.run();stepper.stop(); // Stop as fast as possible: sets new targetstepper.runToPosition(); // Now stopped after quickstop}

13. Random

使单个步进电机执行速度、位置和加速度的随机变化

// Random.pde
// -*- mode: C++ -*-
//
// Make a single stepper perform random changes in speed, position and acceleration
//
// Copyright (C) 2009 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $#include <AccelStepper.h>// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5void setup()
{
}void loop()
{if (stepper.distanceToGo() == 0){// Random change to speed, position and acceleration// Make sure we dont get 0 speed or accelerationsdelay(1000);stepper.moveTo(rand() % 200);stepper.setMaxSpeed((rand() % 200) + 1);stepper.setAcceleration((rand() % 200) + 1);}stepper.run();
}

————————————————

ACCELSTEPPER库函数解析(二)

博主地址:https://blog.csdn.net/wenguitao

AccelStepper类引用

  • Detailed Description 详细说明
    Support for stepper motors with acceleration etc.
    支持步进电机加速运行等

  • This defines a single 2 or 4 pin stepper motor, or stepper moter with fdriver chip, with optional acceleration, deceleration, absolute positioning commands etc. Multiple simultaneous steppers are supported, all moving at different speeds and accelerations.
    这定义了一个2或4针单个步进电机,或驱动芯片驱动的步进电机,这些电机可定义加速,减速,绝对定位命令等。支持多个同步步进电机同时运行,所有步进电机都可以不同的速度和加速度运行。

  • Operation 运行

This module operates by computing a step time in microseconds. The step time is recomputed after each step and after speed and acceleration parameters are changed by the caller. The time of each step is recorded in microseconds. The run() function steps the motor once if a new step is due. The run() function must be called frequently until the motor is in the desired position, after which time run() will do nothing.

此模块通过计算步长(以微秒为单位)进行运行。在每一步之后,在调用函数更改速度和加速度参数之后,将重新计算步长时间。每一步的时间以微秒计。如果要执行新步骤,则run()函数将对电机执行一次步进。必须频繁地调用run()函数,直到电机处于需要的位置,在此之后,run()将不执行任何操作。

  • Positioning 位置

Positions are specified by a signed long integer. At construction time, the current position of the motor is consider to be 0. Positive positions are clockwise from the initial position; negative positions are anticlockwise. The current position can be altered for instance after initialization positioning.

位置由带符号的长整型定义。在运行时,电机的当前位置被认为是0。初始位置顺时针反向为正;逆时针为负。当前位置可以在初始化定位后更改。

  • Caveats 警告

This is an open loop controller: If the motor stalls or is oversped, AccelStepper will not have a correct idea of where the motor really is (since there is no feedback of the motor’s real position. We only know where we think it is, relative to the initial starting point).

这是一个开环控制器:如果电机失速或超速,AccelStepper将不会识别电机的真正物理位置(因为没有反馈的电机的真正位置。我们只默认我们认为它在相对于最初的起点的计算位置)。

  • Performance 执行

The fastest motor speed that can be reliably supported is about 4000 steps per second at a clock frequency of 16 MHz on Arduino such as Uno etc. Faster processors can support faster stepping speeds. However, any speed less than that down to very slow speeds (much less than one per second) are also supported, provided the run() function is called frequently enough to step the motor whenever required for the speed set. Calling setAcceleration() is expensive, since it requires a square root to be calculated.

在Arduino如Uno等的时钟频率为16mhz的情况下,能够可靠支持的最快电机速度约为每秒4000步。更快的处理器可以支持更快的步进速度。然而,任何微小速度(远低于一个每秒)也支持,提供了足够频繁run()函数调用以实现所需的速度。调用setAcceleration()是非常耗CPU资源,因为它需要计算平方根。

Gregor Christandl reports that with an Arduino Due and a simple test program, he measured 43163 steps per second using runSpeed(), and 16214 steps per second using run();

Gregor Christandl报告说,用同一个Arduino Due和一个简单的测试程序,他使用runSpeed()可达到每秒43163步,使用run()仅达到每秒16214步;

(按此来说,我使用的是1:120的减速电机,16细分,使用Run()函数,那实际最大速度为16214/360/7.5/16=0.38圈每秒。且在循环内没有多余代码执行的情况下)

原文链接:https://blog.csdn.net/wenguitao/article/details/104857586

1. Public Types 公共类型

2. Member Function Documentation 成员函数

3. 可以设定进入和停止位置的滑轨代码参考

AccelStepper库相关推荐

  1. ACCELSTEPPER库实例分析

    以下代码来自Accelstepper库的examples ,就是想弄清各个函数怎么实际应用. 实例清单如下: 1 AFMotor_ConstantSpeed 演示如何非常简单的运行AccelStepp ...

  2. Accelstepper 库中的参数计算公式

    要完全调试电机的各个参数,例如最大速度,加速度等,就需要了解其计算公式和原理. 以下是代码注释: /// This code uses speed calculations as described ...

  3. accelstepper 获取方向_AccelStepper库

    /* Arduino通过AccelStepper库控制28BYJ-48步进电机示例程序-2 by 太极创客(www.taichi-maker.com) 可通过Arduino IDE 串口监视器输入电机 ...

  4. l298n电机驱动模块_带DRV8825驱动器模块和Arduino的控制步进电机

    如果您打算建造自己的3D打印机或CNC机器,则需要控制一堆步进电机.而且,由一个arduino控制所有这些,可能会占用大量的处理时间,并且不会给它留下很多做其他事情的空间.除非您使用独立的专用步进电机 ...

  5. ARDUINO:控制两台步进电机同步运转

    要控制两台步进电机同步进行运转,即同时起步,同时加速,同时到达最大速度,同时减速,最后同时停止. 这是要有一定的算法的: 假如B1电机所走的路程是B2的n倍,在同时起步的前提下,v1=n*v2,a1= ...

  6. Arduino简单实现两自由度Scara机器人

    1.描述 两自由度Scara机器人有两个旋转关节,机器人的控制主要就是电机和末端执行器的控制.在学习marlin固件控制机器人时,由于marlin代码过于繁杂且许多代码都是关于3D打印,与机器人相关的 ...

  7. 最全Arduino控制电机教程说明和资料分享

    1.电机介绍 1.1 作用 电机-->电磁感应---电能转化为动能 1.2 电机分类 工作电源:直流电机(DC).交流电机(AC)和交直流两用电机 直流电机分类:有刷直流电机和无刷直流电机 1. ...

  8. python葡萄酒数据_用python进行葡萄酒质量预测

    python葡萄酒数据 Warning: This is long article for those who seek only machine learning code, please just ...

  9. A4988电机驱动简单使用

    作为一款常用的步进电机驱动芯片,A4988在3D打印.数控机床等领域得到了广泛应用.在本文中,我们将会深入探讨A4988芯片的特点.使用方法和注意事项. 一.A4988芯片的特点 A4988芯片是Al ...

最新文章

  1. 代币转账_手把手教你从源代码开始搭建多节点以太坊私链(五)部署智能合约及代币发行...
  2. CUDA学习(三)之使用GPU进行两个数组相加
  3. ie8下修改input的type属性报错
  4. AT3950-[AGC022E]Median Replace【贪心,dp】
  5. DB Reindex
  6. java selenium click_按钮单击selenium java
  7. Linux工作笔记022---查看Centos 内核版本号
  8. 字符串数组最长公共前缀
  9. 访问器中谨慎返回引用类型对象
  10. php编写一个学生类_0063 PHP编程编写学生分数信息编辑和删除功能网页
  11. Visual C++ 6.0的三个问题---尚未完成安装 MSDEV.EXE 应用程序错误 缺少动态链接库文件
  12. java有关物流管理的简历_Java开发实习生大学生简历模板
  13. 如何卸载ultraedit_卸载不掉的软件怎么办(彻底卸载软件方法介绍)
  14. Archlinux的灵魂──PKGBUILD、AUR 和 ABS
  15. 不确定中找到确定性, IBM开出哪些疫后企业数字化新处方?
  16. 《符文冲突》unity塔防类游戏试做,经验源码分享-2
  17. wxpython后台如何更新界面信息_wxpython后台线程更新界面控件方法
  18. Spacy分词php,Spacy简单入门
  19. SCX-4521F一体机MAC驱动
  20. TigerGraph首将模式匹配与高效图计算相结合,为欺诈检测、网络安全保护、人工智能等应用增砖加瓦!

热门文章

  1. mongodb的学习之旅一
  2. (附源码)计算机毕业设计java视频点播系统
  3. 2022年9月电子学会Python等级考试试卷(三级)答案解析
  4. 曲线快捷键,色阶快捷键,曝光度,自然饱和度,色相饱和度,色彩平衡
  5. 入门学习-Python-小甲鱼学习资料-Day023-递归:这帮小兔崽子
  6. oracle访问控制策略查看,ORACLE 安全访问策略VPD与ORA-28132
  7. 51单片机定时器计数器原理以及应用(方波、pwm、脉冲计数、高电平脉宽测量)
  8. 中国最大的500家外商投资企业
  9. Ribbon懒加载第一次超时、异常问题
  10. RT-Thread学习笔记五——临界区与临界区保护