Brazo robótico con paso a paso bipolar (6 / 6 paso)

Paso 6: El maestro completo control de código

Código completo para brazo robótico que se incluyen a continuación.

Tuvimos algunos problemas con el código que hemos usado, pero puesto que también tuvimos algunos problemas con el voltaje, como se explica en el paso 5, tuvimos un tiempo difícil clasificar a través la mayor parte de todo. Cabe señalar que esta sección del código no contiene el código para el sensor.

 <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) } } 

Artículos Relacionados

El control de un brazo robótico con el Kinect de Microsoft!

El control de un brazo robótico con el Kinect de Microsoft!

Rápidamente los robots son cada vez más integrado en nuestras vidas día a día. Limpiar nuestros suelos, nuestro café y se utilizan incluso para telepresencia. Ya que se están convirtiendo en tan vitales para la sociedad, ¿por qué no regalar a nuestro
Construcción del brazo robótico con 3DP +Arduino(用3DP+Arduino製作機械手臂)

Construcción del brazo robótico con 3DP +Arduino(用3DP+Arduino製作機械手臂)

Se trata de un brazo robot de 5 ejes, que hice con Arduino y la impresora 3D.Puede seguir pasos de abajo para descargar el recurso y hacerlo.Preparación de material:1.MG995 servo x 52. SONY Joystick x13. Arduino x1.Paso 1: Ver la película de demostra
BRAZO robótico con interfaz de PC USB (además de Cómo ensamblar)

BRAZO robótico con interfaz de PC USB (además de Cómo ensamblar)

aquí hay un video del brazo robótico con interfaz de PC USB y cómo montar...
Brazo robótico con control remoto

Brazo robótico con control remoto

Esta es una guía para hacer un control remoto robótica brazo (6DOF) o simplemente para controlar algunos servos en algo.Puede usar un TV normal de IR remoto para controlar los servos en un brazo robótico mecánico. hay 17 botones del mando a distancia
Controla brazo robótico con gestos con las manos

Controla brazo robótico con gestos con las manos

Este uso del brazo robótico para Arduino con acelerómetro ADXL 345.Paso 1: materialesmateriales:dos arduino (no importa modelo)dos adxl345 triaxis acelerómetrocinco servos 9grpaneles de plexiglás (dos zonas de papel A4)batería lipoPaso 2: Construcció
Brazo robótico con el transportador, capaces de trabajos de montaje de piezas en curso

Brazo robótico con el transportador, capaces de trabajos de montaje de piezas en curso

Hola a todos,Este es un proyecto donde diseñó y construyó una estación de trabajo a un grado seis de brazo robótico de la libertad. Es un ejemplo común de una línea de producción, que la pieza de trabajo es viajar en una transportadora o paleta a la
Construcción de brazo robótico con partes Makeblock

Construcción de brazo robótico con partes Makeblock

A construir un brazo robot con piezas de Makeblock, lo anterior es el aspecto acabado y el video de trabajo.Paso 1: Lista de materialesLista de piezas mecánicas:Beam0808-136 x 3Beam0808-184 x 11Beam0824-016 V2.1 x 2Beam0824-032 V2.1 x 3Beam0824-096 V
Escultura de Robot (parte 5 de 9): hacer un brazo robótico con motosierra y hacha sierra sable

Escultura de Robot (parte 5 de 9): hacer un brazo robótico con motosierra y hacha sierra sable

Yo he sido la construcción de escultura durante más de diez años y he observado la evolución de la tecnología de mecanizado ir de fresado CNC a impresión de objeto 3D de escritorio. Estas 'Máquinas de hacer' han formado un espacio físico entre mis ma
Brazo robótico con Micro Servos

Brazo robótico con Micro Servos

Este es un proyecto simple que usted puede hacer por sí mismo y no requiere de partes costosas.Paso 1: Las piezas requeridas1) Arduino Nano2) escudo Nano3) cuatro potenciómetros4) cuatro Servos5) fuente de alimentación de 12 voltios6) protoboard7) ju
Brazo robótico para personas con discapacidad

Brazo robótico para personas con discapacidad

brazo robótico en las estadísticasUn brazo mecánico es robótica, generalmente programable, con funciones similares a un brazo humano. Los enlaces de un manipulador de tal están conectados por uniones permitiendo el movimiento de rotación (tal como en
Hacer cableada brazo robótico borde a "Wireless" con DIY Arduino + XBee

Hacer cableada brazo robótico borde a "Wireless" con DIY Arduino + XBee

Actualización: añadido esquema, parte superior capa PCB, fondo capa PCB y ambos arriba, imágenes de PCB inferiorAl terminar el "RevIO" - un clon de Arduino que tiene la diferente manera de exponer el uso de pernos. Decidí ir más lejos el próximo
Brazo robótico hecho en casa con piezas estándar utilizando Arduino y un GUI de procesamiento

Brazo robótico hecho en casa con piezas estándar utilizando Arduino y un GUI de procesamiento

Me jubilé hace poco y una de las cosas que me prometí fue que cuando me retiro que iba a completar todos los proyectos que tenía corriendo dentro de mi cabeza desde que era adolescente. Es cerca de 50 años o tan de los proyectos. En aquellos días no
Brazo robótico de control con guantes, teléfono Android y Arduino

Brazo robótico de control con guantes, teléfono Android y Arduino

Hoy, tenemos casi 2 técnicas para jugar con el brazo robótico, ya sea por los botones por ejemplo como en el escudo de juego o el uso de guantes que incluyan sensores. Sin embargo, hoy voy a mostrarles una nueva técnica usando solamente su teléfono A
Brazo robótico controlado por el mando NES

Brazo robótico controlado por el mando NES

En este instructable voy a tratar de describir cómo hacer un brazo robótico con partes de una impresora y controlarlo con un mando NES.Puede parecer un trabajo duro pero he preparado plantillas para todas las partes y tratar de tomar fotos de todos l