Vraag over AccelStepper + Nieuwe Robot

Projecten die niet passen in bovenstaande onderwerpen
Berichten: 59
Geregistreerd: 19 Mrt 2015, 01:17

Vraag over AccelStepper + Nieuwe Robot

Berichtdoor hazanovo » 15 Dec 2015, 01:55

Hallo,

Het is een tijdje geleden dat ik dit forum bezocht heb. Inmiddels heb ik een nieuwe robotarm gemaakt dit maal met 6 motoren. Nu loop ik steeds tegen dezelfde probleem aan,
namelijk wanneer de array uitgevoerd word de motoren vaak niet allemaal tegelijk klaar zijn met de array, bijv 4 motoren zijn al op positie maar de andere 2 zijn nog aan het draaien.
Nu weet ik dat je dit met snelheid kunt regelen, maar om nu voor iedere motor een aparte snelheid te maken + elke array is anders, schiet niet op.
Is er een mogelijkheid om arduino de speed en de accel te laten bereken bijv. dat alle motoren precies om 3 seconden op positie zijn etc.
Kan iemand me een stap in de richting geven?


Link robot arm https://www.youtube.com/watch?v=QNA4icYO7cw

Advertisement

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Vraag over AccelStepper + Nieuwe Robot

Berichtdoor shooter » 15 Dec 2015, 10:51

en hier is je antwoord.
http://www.airspayce.com/mikem/arduino/AccelStepper/classMultiStepper.html
ik had hier reeds accelstepper aanbevolen en multi is daar een uitbreiding op.
die regelt zelf de snelheden van de andere motoren, om allemaal op hetzelfde moment te stoppen.
wel een opmerking is dat de runspeedtoposition een blockende is dus dan stopt je programma tot deze regel is voldaan.
paul deelen
shooter@home.nl

Berichten: 59
Geregistreerd: 19 Mrt 2015, 01:17

Re: Vraag over AccelStepper + Nieuwe Robot

Berichtdoor hazanovo » 18 Dec 2015, 09:48

Heb de site bezocht, kon de Multistepper.h library alleen nergens downloaden, heel vreemd allemaal. De site herhaald zich telkens. Heb je een link naar een download ?

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Vraag over AccelStepper + Nieuwe Robot

Berichtdoor shooter » 18 Dec 2015, 11:06

cpp code
/*
Stepper.cpp - - Stepper library for Wiring/Arduino - Version 0.4

Original library (0.1) by Tom Igoe.
Two-wire modifications (0.2) by Sebastian Gassner
Combination version (0.3) by Tom Igoe and David Mellis
Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley
Enable support for multiple motors (0.5) by Daan Middendorp
Drives multiple unipolar or bipolar stepper motor using 2 wires or 4 wires
When wiring multiple stepper motors to a microcontroller,
you quickly run out of output pins, with each motor requiring 4 connections.
By making use of the fact that at any time two of the four motor
coils are the inverse of the other two, the number of
control connections can be reduced from 4 to 2.
A slightly modified circuit around a Darlington transistor array or an L293 H-bridge
connects to only 2 microcontroler pins, inverts the signals received,
and delivers the 4 (2 plus 2 inverted ones) output signals required
for driving a stepper motor.
The sequence of control signals for 4 control wires is as follows:
Step C0 C1 C2 C3
1 1 0 1 0
2 0 1 1 0
3 0 1 0 1
4 1 0 0 1
The sequence of controls signals for 2 control wires is as follows
(columns C1 and C2 from above):
Step C0 C1
1 0 1
2 1 1
3 1 0
4 0 0
The circuits can be found at

http://www.arduino.cc/en/Tutorial/Stepper

*/

#include "MultiStepper.h"
#include "Arduino.h"

/*
* Creates arrays with length equal to the amount of motors.
*/
MultiStepper::MultiStepper(int number_of_motors)
{
this->step_number = new int[number_of_motors]; // which step the motor is on
this->speed = new int[number_of_motors]; // the motor speed, in revolutions per minute
this->direction = new int[number_of_motors]; // motor direction
this->last_step_time = new long[number_of_motors]; // time stamp in ms of the last step taken
this->number_of_steps = new int[number_of_motors]; // total number of steps for this motor
this->step_delay = new unsigned long[number_of_motors];

this->motor_pin_1 = new int[number_of_motors];
this->motor_pin_2 = new int[number_of_motors];
this->motor_pin_3 = new int[number_of_motors];
this->motor_pin_4 = new int[number_of_motors];

this->pin_count = new int[number_of_motors];
this->motor_count = 0;
}

/*
* Two-wire constructor.
* Sets which wires should control the motor.
*/
void MultiStepper::addMotor(int number_of_steps, int motor_pin_1, int motor_pin_2)
{
int i = this->motor_count;
this->step_number[i] = 0; // which step the motor is on
this->speed[i] = 0; // the motor speed, in revolutions per minute
this->direction[i] = 0; // motor direction
this->last_step_time[i] = 0; // time stamp in ms of the last step taken
this->number_of_steps[i] = number_of_steps; // total number of steps for this motor

// Arduino pins for the motor control connection:
this->motor_pin_1[i] = motor_pin_1;
this->motor_pin_2[i] = motor_pin_2;

// setup the pins on the microcontroller:
pinMode(this->motor_pin_1[i], OUTPUT);
pinMode(this->motor_pin_2[i], OUTPUT);

// When there are only 2 pins, set the other two to 0:
this->motor_pin_3[i] = 0;
this->motor_pin_4[i] = 0;

// pin_count is used by the stepMotor() method:
this->pin_count[i] = 2;

this->motor_count++;
}

/*
* Constructor for four-pin version
* Sets which wires should control the motor.
*/
void MultiStepper::addMotor(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4)
{
int i = this->motor_count;
this->step_number[i] = 0; // which step the motor is on
this->speed[i] = 0; // the motor speed, in revolutions per minute
this->direction[i] = 0; // motor direction
this->last_step_time[i] = 0; // time stamp in ms of the last step taken
this->number_of_steps[i] = number_of_steps; // total number of steps for this motor

// Arduino pins for the motor control connection:
this->motor_pin_1[i] = motor_pin_1;
this->motor_pin_2[i] = motor_pin_2;
this->motor_pin_3[i] = motor_pin_3;
this->motor_pin_4[i] = motor_pin_4;

// setup the pins on the microcontroller:
pinMode(this->motor_pin_1[i], OUTPUT);
pinMode(this->motor_pin_2[i], OUTPUT);
pinMode(this->motor_pin_3[i], OUTPUT);
pinMode(this->motor_pin_4[i], OUTPUT);

// pin_count is used by the stepMotor() method:
this->pin_count[i] = 4;

this->motor_count++;
}

/*
* Sets the speed in revs per minute
*/
void MultiStepper::setSpeed(long whatSpeed, int motor)
{
this->step_delay[motor] = 60L * 1000L / this->number_of_steps[motor] / whatSpeed;
}

/*
* Determines if at least one of the motors has to continue spinning.
*/
int MultiStepper::stepsLeft(void)
{
int max_steps_left = 0;
for (int i = 0; i < sizeof(this->steps_left) / sizeof(*this->steps_left); ++i) {
if (this->steps_left[i] > max_steps_left) { max_steps_left = this->steps_left[i]; }
}
return max_steps_left;
}

/*
* Moves the motors steps_to_move steps. If the number is negative,
* the motor moves in the reverse direction.
*/
void MultiStepper::step(int steps_to_move[])
{
this->steps_left = new int[this->motor_count];
int max_steps_left = 0; // Used to determine if we have to keep looping

for (int i = 0; i < sizeof(steps_to_move) / sizeof(*steps_to_move); ++i) {
int steps = steps_to_move[i];
this->steps_left[i] = abs(steps); // how many steps to take

// determine direction based on whether steps_to_mode is + or -:
if (steps > 0) {this->direction[i] = 1;}
if (steps < 0) {this->direction[i] = 0;}

if (steps > max_steps_left) {max_steps_left = steps;}
}

// decrement the number of max steps, moving one step each time:
while (stepsLeft() > 0) {
for (int i = 0; i < this->motor_count; ++i) {
if (millis() - this->last_step_time[i] >= this->step_delay[i]) {
this->last_step_time[i] = millis();

if (this->direction[i] == 1) {
this->step_number[i]++;
if (this->step_number[i] == this->number_of_steps[i]) {
this->step_number[i] = 0;
}
} else {
if (this->step_number[i] == 0) {
this->step_number[i] = this->number_of_steps[i];
}
this->step_number[i]--;
}
stepMotor(this->step_number[i] % 4, i);
this->steps_left[i]--;
}
}
}
}

/*
* Moves the motor forward or backwards.
*/
void MultiStepper::stepMotor(int thisStep, int motor)
{
if (this->pin_count[motor] == 2) {
switch (thisStep) {
case 0: /* 01 */
digitalWrite(motor_pin_1[motor], LOW);
digitalWrite(motor_pin_2[motor], HIGH);
break;
case 1: /* 11 */
digitalWrite(motor_pin_1[motor], HIGH);
digitalWrite(motor_pin_2[motor], HIGH);
break;
case 2: /* 10 */
digitalWrite(motor_pin_1[motor], HIGH);
digitalWrite(motor_pin_2[motor], LOW);
break;
case 3: /* 00 */
digitalWrite(motor_pin_1[motor], LOW);
digitalWrite(motor_pin_2[motor], LOW);
break;
}
}
if (this->pin_count[motor] == 4) {
switch (thisStep) {
case 0: // 1010
digitalWrite(motor_pin_1[motor], HIGH);
digitalWrite(motor_pin_2[motor], LOW);
digitalWrite(motor_pin_3[motor], HIGH);
digitalWrite(motor_pin_4[motor], LOW);
break;
case 1: // 0110
digitalWrite(motor_pin_1[motor], LOW);
digitalWrite(motor_pin_2[motor], HIGH);
digitalWrite(motor_pin_3[motor], HIGH);
digitalWrite(motor_pin_4[motor], LOW);
break;
case 2: //0101
digitalWrite(motor_pin_1[motor], LOW);
digitalWrite(motor_pin_2[motor], HIGH);
digitalWrite(motor_pin_3[motor], LOW);
digitalWrite(motor_pin_4[motor], HIGH);
break;
case 3: //1001
digitalWrite(motor_pin_1[motor], HIGH);
digitalWrite(motor_pin_2[motor], LOW);
digitalWrite(motor_pin_3[motor], LOW);
digitalWrite(motor_pin_4[motor], HIGH);
break;
}
}
}

/*
* version() returns the version of the library:
*/
int MultiStepper::version(void)
{
return 5;
}


cpp code
// MultiStepper.h
2
3 #ifndef MultiStepper_h
4 #define MultiStepper_h
5
6 #include <stdlib.h>
7 #if ARDUINO >= 100
8 #include <Arduino.h>
9 #else
10 #include <WProgram.h>
11 #include <wiring.h>
12 #endif
13
14 #define MULTISTEPPER_MAX_STEPPERS 10
15
16 class AccelStepper;
17
18 /////////////////////////////////////////////////////////////////////
19 /// \class MultiStepper MultiStepper.h <MultiStepper.h>
20 /// \brief Operate multiple AccelSteppers in a co-ordinated fashion
21 ///
22 /// This class can manage multiple AccelSteppers (up to MULTISTEPPER_MAX_STEPPERS = 10),
23 /// and cause them all to move
24 /// to selected positions at such a (constant) speed that they all arrive at their
25 /// target position at the same time. This can be used to support devices with multiple steppers
26 /// on say multiple axes to cause linear diagonal motion. Suitable for use with X-Y plotters, flatbeds etc
27 /// to get linear straight line movement between arbitrary 2d (or 3d or ...) positions.
28 ///
29 /// Caution: only constant speed stepper motion is supported: acceleration and deceleration is not supported
30 /// All the steppers managed by MultiStepper will step at a constant speed to their
31 /// target (albeit perhaps different speeds for each stepper).
32 class MultiStepper
33 {
34 public:
35 /// Constructor
36 MultiStepper();
37
38 /// Add a stepper to the set of managed steppers
39 /// There is an upper limit of MULTISTEPPER_MAX_STEPPERS = 10 to the number of steppers that can be managed
40 /// \param[in] stepper Reference to a stepper to add to the managed list
41 /// \return true if successful. false if the number of managed steppers would exceed MULTISTEPPER_MAX_STEPPERS
42 boolean addStepper(AccelStepper& stepper);
43
44 /// Set the target positions of all managed steppers
45 /// according to a coordinate array.
46 /// New speeds will be computed for each stepper so they will all arrive at their
47 /// respective targets at very close to the same time.
48 /// \param[in] absolute An array of desired absolute stepper positions. absolute[0] will be used to set
49 /// the absolute position of the first stepper added by addStepper() etc.
50 void moveTo(long absolute[]);
51
52 /// Calls runSpeed() on all the managed steppers
53 /// that have not acheived their target position.
54 /// \return true if any stepper is still in the process of running to its target position.
55 boolean run();
56
57 /// Runs all managed steppers until they acheived their target position.
58 /// Blocks until all that position is acheived.
59 void runSpeedToPosition();
60
61 private:
62 // Array of pointers to the steppers we are controlling.
63 // Fills from 0 onwards
64 AccelStepper* _steppers[MULTISTEPPER_MAX_STEPPERS];
65
66 // Number of steppers we are controlling and the number
67 // of steppers in _steppers[]
68 uint8_t _num_steppers;
69 };
70
71 /// @example MultiStepper.pde
72 /// Use MultiStepper class to manage multiple steppers and make them all move to
73 /// the same position at the same time for linear 2d (or 3d) motion.
74
75 #endif
paul deelen
shooter@home.nl

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 38 gasten