|
Misol kodi - AccelStepper kutubxonasi bilan bir nechta step motorlarini boshqarish
|
bet | 9/13 | Sana | 09.02.2024 | Hajmi | 12,35 Mb. | | #153839 |
Bog'liq stepper word Misol kodi - AccelStepper kutubxonasi bilan bir nechta step motorlarini boshqarish
Men sizga AccelStepper kutubxonasidan foydalangan holda yana bir misolni ko'rsatmoqchiman va u bir nechta step motorlarini muvofiqlashtirilgan tarzda boshqaradi. Bu shuni anglatadiki, biz har bir qadam uchun maqsadli pozitsiyalarni belgilashimiz mumkin va ular turli masofani bosib o'tishlari kerak bo'lishidan qat'i nazar, bir vaqtning o'zida o'z pozitsiyalariga etib borishlari mumkin.
Buni AccelStepper kutubxonasi bilan birga kelgan MultiStepper klassi yordamida osonlik bilan amalga oshirish mumkin.
/*
Controlling multiple steppers with the AccelStepper and MultiStepper library
by Dejan, https://howtomechatronics.com
*/
#include
#include
// Define the stepper motor and the pins that is connected to
AccelStepper stepper1(1, 2, 5); // (Typeof driver: with 2 pins, STEP, DIR)
AccelStepper stepper2(1, 3, 6);
AccelStepper stepper3(1, 4, 7);
MultiStepper steppersControl; // Create instance of MultiStepper
long gotoposition[3]; // An array to store the target positions for each stepper motor
void setup() {
stepper1.setMaxSpeed(1000); // Set maximum speed value for the stepper
stepper2.setMaxSpeed(1000);
stepper3.setMaxSpeed(1000);
// Adding the 3 steppers to the steppersControl instance for multi stepper control
steppersControl.addStepper(stepper1);
steppersControl.addStepper(stepper2);
steppersControl.addStepper(stepper3);
}
void loop() {
// Store the target positions in the "gotopostion" array
gotoposition[0] = 800; // 800 steps - full rotation with quater-step resolution
gotoposition[1] = 1600;
gotoposition[2] = 3200;
steppersControl.moveTo(gotoposition); // Calculates the required speed for all motors
steppersControl.runSpeedToPosition(); // Blocks until all steppers are in position
delay(1000);
gotoposition[0] = 0;
gotoposition[1] = 0;
gotoposition[2] = 0;
steppersControl.moveTo(gotoposition);
steppersControl.runSpeedToPosition();
delay(1000);
}Kod tili: Arduino ( arduino )
|
| |