Bras robotisé avec moteur pas à pas bipolaire (6 / 6 étapes)

Étape 6: Le capitaine plein contrôle code

Code complet pour bras robotisé inclus ci-dessous.

Nous avons eu quelques problèmes avec le code que nous avons utilisé, mais puisque nous avons également eu quelques problèmes avec la tension qui, comme l’a expliqué à l’étape 5, nous avons eu un mal de tri à travers la plus grande partie de tout cela. Il est à noter que cette section de code ne contienne pas le code pour le capteur.

 <pre><pre>#ifndef _stepLib_h_<br>#define _stepLib_h_ #include "Arduino.h" // define our stepper class class stepMotor { public: stepMotor(byte stepPin, byte dirPin); // our stepper object with variables stepPin and dirPin void step(unsigned int stepFreq); // our stepping function which takes as an input our stepping frequency private: unsigned long _time; // current time unsigned long _lastStepTime; // time at which we last stepped unsigned long _stepPeriod; // time between a half period - this is the same as our delay(X) of part 1 byte _stepPin; byte _dirPin; boolean _stepCycle; // defines if we are on the HIGH or LOW side of our step cycle }; #endif #include "Arduino.h" #include "stepLib.h" // used for declaring our motor and initializing it stepMotor::stepMotor(byte stepPin, byte dirPin) { _stepPin = stepPin; _dirPin = dirPin; // define our digital pins as output pinMode(_stepPin, OUTPUT); pinMode(_dirPin, OUTPUT); // initialize our digital pins to LOW digitalWrite(_stepPin, LOW); digitalWrite(_dirPin, LOW); _stepCycle = false; // this keeps track of which end of the step cycle we are on: high or low } // function responsible for driving our digital pins high/low at the proper frequency // input is the stepping frequency void stepMotor::step(unsigned int stepFreq) { _time = micros(); // get the current time _stepPeriod = 1000000 / stepFreq; // get our step period (in micro-seconds) from the user given step frequency; we lose a bit of accuracy here since we've defined _stepPeriod as an unsigned long instead of a float, but that's ok... // if the proper amount of time has passed, let's go ahead and proceed to the next half of our step cycle if (_time >= _lastStepTime + _stepPeriod) { digitalWrite(_stepPin, _stepCycle == true); // a compact way of writing either HIGH/LOW to our step pin based on where we are on our step cycle _stepCycle = !_stepCycle; // this simply flips our Boolean _lastStepTime = _time; // update the time we last stepped } } #include "stepLib.h" // define a constant value named stepPin and assign the value 8 to it - this value will not change during our code // this assumes digital pin 8 of your Arduino is attached to the step input of your driver #define stepPin 9 // define a constant value named dirPin and assign the value 8 to it - this value will not change during our code // this assumes digital pin 9 of your Arduino is attached to the step input of your driver #define dirPin 8 // instantiate a new object in our stepMotor library named slider // we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin stepMotor slider(stepPin, dirPin); // setup() loop, the Arduino only runs through this once void setup() { } // loop() loop, the Arduino continuously cycles through this as fast as it can void loop() { slider.step(50); // step our motor at a given frequency (Hz) } #include "stepLib.h" // define our step pins # define sliderStep 9 # define panStep 11 # define tiltStep 7 // define our direction pins # define sliderDir 8 # define panDir 10 # define tiltDir 6 // instantiate a new object in our stepMotor library named slider // we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin stepMotor slider(sliderStep, sliderDir); stepMotor pan(panStep, panDir); stepMotor tilt(tiltStep, tiltDir); // setup() loop, the Arduino only runs through this once void setup() { } // loop() loop, the Arduino continuously cycles through this as fast as it can void loop() { slider.step(50); // step our motor at a given frequency (Hz) pan.step(10); // step our motor at a given frequency (Hz) tilt.step(100); // step our motor at a given frequency (Hz) } #ifndef _stepLib_h_ #define _stepLib_h_ #include "Arduino.h" // define our stepper class class stepMotor { public: stepMotor(byte stepPin, byte dirPin); // our stepper object with variables stepPin and dirPin void step(unsigned int stepFreq); // our stepping function which takes as an input our stepping frequency void setDir(boolean dir); // function that allows us to set our direction of rotation private: unsigned long _time; // current time unsigned long _lastStepTime; // time at which we last stepped unsigned long _stepPeriod; // time between a half period - this is the same as our delay(X) of part 1 byte _stepPin; byte _dirPin; boolean _stepCycle; // defines if we are on the HIGH or LOW side of our step cycle }; #endif #include "Arduino.h" #include "stepLib.h" // used for declaring our motor and initializing it stepMotor::stepMotor(byte stepPin, byte dirPin) { _stepPin = stepPin; _dirPin = dirPin; // define our digital pins as output pinMode(_stepPin, OUTPUT); pinMode(_dirPin, OUTPUT); // initialize our digital pins to LOW digitalWrite(_stepPin, LOW); digitalWrite(_dirPin, LOW); _stepCycle = false; // this keeps track of which end of the step cycle we are on: high or low } // function responsible for driving our digital pins high/low at the proper frequency // input is the stepping frequency void stepMotor::step(unsigned int stepFreq) { _time = micros(); // get the current time _stepPeriod = 1000000 / stepFreq; // get our step period (in micro-seconds) from the user given step frequency; we lose a bit of accuracy here since we've defined _stepPeriod as an unsigned long instead of a float, but that's ok... // if the proper amount of time has passed, let's go ahead and proceed to the next half of our step cycle if (_time >= _lastStepTime + _stepPeriod) { digitalWrite(_stepPin, _stepCycle == true); // a compact way of writing either HIGH/LOW to our step pin based on where we are on our step cycle _stepCycle = !_stepCycle; // this simply flips our Boolean _lastStepTime = _time; // update the time we last stepped } } // given a boolean user input, set our direction of travel to that input void stepMotor::setDir(boolean dir) { digitalWrite(_dirPin, dir); } #include "stepLib.h" // define our step pins # define sliderStep 9 # define panStep 11 # define tiltStep 7 // define our direction pins # define sliderDir 8 # define panDir 10 # define tiltDir 6 // define the pins on which we've put our N.O. buttons #define button1 2 #define button2 3 // our motor step frequencies int sliderFreq = 300; int panFreq = 10; int tiltFreq = 100; // instantiate a new object in our stepMotor library named slider // we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin stepMotor slider(sliderStep, sliderDir); stepMotor pan(panStep, panDir); stepMotor tilt(tiltStep, tiltDir); // setup() loop, the Arduino only runs through this once void setup() { // define our button pins as input pullup type - see http://arduino.cc/en/Tutorial/DigitalPins#.Uyphr4WN7q4 pinMode(button1, INPUT_PULLUP); pinMode(button2, INPUT_PULLUP); } // loop() loop, the Arduino continuously cycles through this as fast as it can void loop() { if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // if button1 is pressed and button2 is not pressed slider.setDir(true); pan.setDir(true); tilt.setDir(true); } else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // if btton1 is not pressed and button2 is pressed slider.setDir(false); pan.setDir(false); tilt.setDir(false); } if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // if either button is pressed slider.step(sliderFreq); // step our motor at a given frequency (Hz) pan.step(panFreq); // step our motor at a given frequency (Hz) tilt.step(tiltFreq); // step our motor at a given frequency (Hz) } if (digitalRead(button1) == LOW && digitalRead(button2) == LOW) { // if both buttons are pressed together sliderFreq += 10; panFreq += 10; tiltFreq += 10; delay(10); // delay just a short while otherwise the double button presses causes our frequency to increase too quickly (we need to allow for the user to release the buttons) } } #include "stepLib.h" // define our step pins # define sliderStep 9 # define panStep 11 # define tiltStep 7 // define our direction pins # define sliderDir 8 # define panDir 10 # define tiltDir 6 // define the pins on which we've put our N.O. buttons #define button1 2 #define button2 3 // define our joystick pins; NOTE we are using analog pins, not digital #define LRjoystickPin 27 // left-right joystick #define UDjoystickPin 28 // up-down joystick // our motor step frequencies int sliderFreq = 50; int panFreq = 300; int tiltFreq = 100; // other variables byte deadband = 50; // size of deadband, from joystick neutral position, in which we assume we are reading 0 unsigned int LRjoyValue = 0; unsigned int UDjoyValue = 0; // instantiate a new object in our stepMotor library named slider // we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin stepMotor slider(sliderStep, sliderDir); stepMotor pan(panStep, panDir); stepMotor tilt(tiltStep, tiltDir); // setup() loop, the Arduino only runs through this once void setup() { // define our button pins as input pullup type - see http://arduino.cc/en/Tutorial/DigitalPins#.Uyphr4WN7q4 pinMode(button1, INPUT_PULLUP); pinMode(button2, INPUT_PULLUP); pinMode(LRjoystickPin, INPUT); pinMode(UDjoystickPin, INPUT); } // loop() loop, the Arduino continuously cycles through this as fast as it can void loop() { // read our joystick values and store them LRjoyValue = analogRead(LRjoystickPin); // acts just like digitalRead, but for analog pins UDjoyValue = analogRead(UDjoystickPin); // acts just like digitalRead, but for analog pins // control our pan with the LR joystick if (LRjoyValue > 512+ deadband) { // joystick is outside of deadband, move right pan.setDir(true); pan.step(panFreq); } else if (LRjoyValue < 512- deadband) { // joystick is outside of deadband, move left pan.setDir(false); pan.step(panFreq); } // control our tilt with the UD joystick if (UDjoyValue > 512 + deadband) { // joystick is outside of deadband, move up tilt.setDir(true); tilt.step(panFreq); } else if (UDjoyValue < 512 - deadband) { // joystick is outside of deadband, move down tilt.setDir(false); tilt.step(panFreq); } // control our slider stepper with the two buttons, just like we did previously if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // if button1 is pressed and button2 is not pressed slider.setDir(true); } else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // if btton1 is not pressed and button2 is pressed slider.setDir(false); } if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // if either button is pressed slider.step(sliderFreq); // step our motor at a given frequency (Hz) } } 

Articles Liés

Contrôler un bras robotisé avec la Kinect de Microsoft !

Contrôler un bras robotisé avec la Kinect de Microsoft !

Les robots sont rapidement devenant plus intégré dans notre vie quotidienne. Ils nettoient nos planchers, faire notre café et sont même utilisés pour la téléprésence. Car ils deviennent si vitales pour la société, pourquoi ne pas donner nos compagnon
Bras robotique avec des gants, téléphone Android et Arduino

Bras robotique avec des gants, téléphone Android et Arduino

Aujourd'hui, nous avons presque 2 techniques pour jouer avec le bras robotisé, soit par les boutons , par exemple comme le bouclier de jeu ou en utilisant des gants qui incluent les capteurs. Pourtant, aujourd'hui je vais vous montrer une nouvelle te
BRAS robotisé avec Interface PC USB (plus comment assembler)

BRAS robotisé avec Interface PC USB (plus comment assembler)

Voici une vidéo du bras robotisé avec Interface PC USB et comment assembler...
Bras robotisé avec Servo-moteurs

Bras robotisé avec Servo-moteurs

une partie de ma recherche doctorale à NYU-Poly consiste à prédire la consommation d'énergie dans les systèmes robotisés, alors j'ai besoin d'un système robotisé de travailler avec une plate-forme de recherche pour valider les résultats.  Si j'ai con
BRICOLAGE table traçante avec moteurs pas à pas

BRICOLAGE table traçante avec moteurs pas à pas

Un traceur XY est une machine qui permet de contrôler un instrument de traçage (comme un stylo ou un outil de coupe comme une lame ou d'un laser) sur deux axes d'une manière exacte et précise. Machines à commande numérique (CNC) ordinateur sont très
Bras robotisé avec convoyeur, capable de travail d’assemblage des pièces en cours

Bras robotisé avec convoyeur, capable de travail d’assemblage des pièces en cours

Bonjour à tous,Il s'agit d'un projet où j'ai conçu et construit une station de travail pour un six degrés du bras robotique de la liberté. C'est un exemple courant d'une ligne de production, que la pièce se déplace sur un tapis roulant ou de la palet
Construire le bras robotisé avec 3DP +Arduino(用3DP+Arduino製作機械手臂)

Construire le bras robotisé avec 3DP +Arduino(用3DP+Arduino製作機械手臂)

Il s'agit d'un axe 5 bras robotisés, je l'ai fait avec 3D Printer & Arduino.Vous pouvez suivre les étapes ci-dessous pour télécharger la ressource et en faire.Comment préparer le Stuff :1.MG995 servo x 52. SONY Joystick x13. Arduino x1.Étape 1: Voir
Bras robotique avec des gants, téléphone Android et Intel Galileo (Updated)

Bras robotique avec des gants, téléphone Android et Intel Galileo (Updated)

En fait, ce projet basé sur un autre projet que j'ai construire avant. Pourtant, au lieu de construire le bras du robot en utilisant Arduino, j'ai utilisé mon bras du robot ami 6DDL et Intel Galileo.Étape 1: composants 1-Intel Galileo Gen 22 - 1Sheel
Commandé un bras robotique avec des gestes de la main

Commandé un bras robotique avec des gestes de la main

Cette utilisation de bras robotisé pour Arduino et 345 ADXL accéléromètre.Étape 1: matériauxmatériaux :deux arduino (modèle est indifférent)adxl345 deux triaxis accéléromètrecinq 9gr servospanneaux en plexiglas (deux zones de papier A4)Accu LiPoEtape
Maison Robot Scara bras traceur robotique tirage moteur pas à pas de bricolage cadre Aluminium 2

Maison Robot Scara bras traceur robotique tirage moteur pas à pas de bricolage cadre Aluminium 2

Maison Robot Scara bras traceur robotique tirage bricolage cadre Aluminium 2 commandé par moteurMatériaux :2 pièces 42 mm Nema Stepper moteur 1,8 degrés4 Pcs 20 GT2-6 GT2 poulie et 700 mm x 2 GT2 Belt KIT pour ceinture imprimante 3Dtaille de 2 pcs mo
Strawbots : Robots avec moteurs de téléavertisseur et de Strawbees

Strawbots : Robots avec moteurs de téléavertisseur et de Strawbees

Strawbees sont des connecteurs en plastique que vous pouvez utiliser pour faire des modèles de 6mm, pailles. Les modèles résultants sont légers et faire une bonne base pour un robot de bot simple buzz grâce à un moteur pager et pile de la pièce.Vous
Sculpture de Robot (partie 5 de 9): faire un bras robotisé avec tronçonneuse & Sawzall hache

Sculpture de Robot (partie 5 de 9): faire un bras robotisé avec tronçonneuse & Sawzall hache

J'ai construit la sculpture depuis plus de dix ans et j'ai vu l'évolution de la technologie d'usinage aller de fraisage CNC pour l'impression 3D objet bureau. Ces « machines à fabriquer » ont formé un espace physique entre mes mains et les matériaux,
Bras robotisé avec Micro Servos

Bras robotisé avec Micro Servos

Il s'agit d'un projet simple qui vous pouvez faire par vous-même et ne nécessite pas chers pièces.Etape 1: Eléments requis1) Arduino Nano2) bouclier de Nano3) quatre potentiomètres4) quatre Servos5) bloc d'alimentation 12 volts6) planche7) fils de ra
Robot Attiny2313 avec Bluetooth HC06 et moteurs pas à pas

Robot Attiny2313 avec Bluetooth HC06 et moteurs pas à pas

Ici, je voulais présenter une ébauche du robot véhicule. Le coeur du robot est le microcontrôleur ATtiny2313. Le robot en voiture sont les 2 moteurs pas à pas. Autres projets ont été l'inspiration pour la construction de mon robot. Dans la plupart de