Professional Documents
Culture Documents
Like Page Learn More
Be the first of your friends to like this
robimek
Tweets de @robimek
Robimek @robimek
Boğaziçi Üniversitesi RoboticSummit Etkinliği
1112 Mart'ta! @ Buecieee @ UniBogazici
# RoboticSummit # BUEC # robimek
Arduino Auto Balanceador Robot Robimek.com/bogaziciunive ...
Sección electrónica:
Diagrama de circuito:
http://make.robimek.com/arduinoselfbalancingrobot/ 1/9
15/1/2017 Arduino Auto Balanceador Robot
Software Parte:
Arduino Software:
1 #include <PID_v1.h>
2 #include <LMotorController.h>
3 #include "I2Cdev.h"
4
5 #include "MPU6050_6Axis_MotionApps20.h"
6
7 #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
8 #include "Wire.h"
9 #endif
10
11
12 #define LOG_INPUT 0
13 #define MANUAL_TUNING 0
14 #define LOG_PID_CONSTANTS 0 //MANUAL_TUNING must be 1
15 #define MOVE_BACK_FORTH 0
dieciséis
17 #define MIN_ABS_SPEED 30
18
19 //MPU
20
CASA
21
22 MPU6050 mpu;
23
ACERCA DE
24 // MPU control/status vars
25 bool dmpReady = false; // set true if DMP init was successful
CONTACTO
26 uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
27 uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
28 uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
29 uint16_t fifoCount; // count of all bytes currently in FIFO
30 uint8_t fifoBuffer[64]; // FIFO storage buffer
31
32 // orientation/motion vars
33 Quaternion q; // [w, x, y, z] quaternion container
34 VectorFloat gravity; // [x, y, z] gravity vector
35 float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
36
37
38 //PID
39
40
41 #if MANUAL_TUNING
42 double kp , ki, kd;
43 double prevKp, prevKi, prevKd;
44 #endif
45 double originalSetpoint = 174.29;
46 double setpoint = originalSetpoint;
47 double movingAngleOffset = 0.3;
48 double input, output;
49 int moveState=0; //0 = balance; 1 = back; 2 = forth
50
51 #if MANUAL_TUNING
52 PID pid(&input, &output, &setpoint, 0, 0, 0, DIRECT);
53
54
#else
CASA PROYECTOS APLICADOS HACER ROBOT
PID pid(&input, &output, &setpoint, 70, 240, 1.9, DIRECT); 15 DE ENERO DE
2017
55 #endif
56
57
58 //MOTOR CONTROLLER
59
60
61 int ENA = 3;
http://make.robimek.com/arduinoselfbalancingrobot/ 2/9
15/1/2017 Arduino Auto Balanceador Robot
61 int ENA = 3;
62 int IN1 = 4;
63 int IN2 = 8;
64 int IN3 = 5;
sesenta y cinco int IN4 = 7;
66 int ENB = 6;
67
68
69 LMotorController motorController(ENA, IN1, IN2, ENB, IN3, IN4, 0.6, 1);
70
71
72 //timers
73
74
75 long time1Hz = 0;
76 long time5Hz = 0;
77
78
79 volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high
80 void dmpDataReady()
81 {
82 mpuInterrupt = true;
83 }
84
85
86 void setup()
87 {
88 // join I2C bus (I2Cdev library doesn't do this automatically)
89 #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
90 Wire.begin();
91 TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
92 #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
93 Fastwire::setup(400, true);
94 #endif
95
96 // initialize serial communication
97 // (115200 chosen because it is required for Teapot Demo output, but it's
98 // really up to you depending on your project)
99 Serial.begin(115200);
100 while (!Serial); // wait for Leonardo enumeration, others continue immediately
101
102 // initialize device
103 Serial.println(F("Initializing I2C devices..."));
104 mpu.initialize();
105
106 // verify connection
107 Serial.println(F("Testing device connections..."));
108 Serial.println(mpu.testConnection() ? F("MPU6050 connection successful"
109
110 // load and configure the DMP
111 Serial.println(F("Initializing DMP..."));
112 devStatus = mpu.dmpInitialize();
113
114 // supply your own gyro offsets here, scaled for min sensitivity
115 mpu.setXGyroOffset(220);
116 mpu.setYGyroOffset(76);
117 mpu.setZGyroOffset(‐85);
118 mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
119
120 // make sure it worked (returns 0 if so)
121 if (devStatus == 0)
122 {
123 // turn on the DMP, now that it's ready
124
CASA
Serial.println(F("Enabling DMP..."));
125 mpu.setDMPEnabled(true);
126
127 // enable Arduino interrupt detection
ACERCA DE
128 Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."
129 attachInterrupt(0, dmpDataReady, RISING);
130 mpuIntStatus = mpu.getIntStatus();
CONTACTO
131
132 // set our DMP Ready flag so the main loop() function knows it's okay to use it
133 Serial.println(F("DMP ready! Waiting for first interrupt..."
134 dmpReady = true;
135
136 // get expected DMP packet size for later comparison
137 packetSize = mpu.dmpGetFIFOPacketSize();
138
139 //setup PID
140
141 pid.SetMode(AUTOMATIC);
142 pid.SetSampleTime(10);
143 pid.SetOutputLimits(‐255, 255);
144 }
145 else
146 {
147 // ERROR!
148 // 1 = initial memory load failed
149 // 2 = DMP configuration updates failed
150 // (if it's going to break, usually the code will be 1)
151 Serial.print(F("DMP Initialization failed (code "));
152 Serial.print(devStatus);
153 Serial.println(F(")"));
154 }
155 }
156
157
158
CASA
void loop() PROYECTOS APLICADOS HACER ROBOT 15 DE ENERO DE
2017
159 {
160 // if programming failed, don't try to do anything
161 if (!dmpReady) return;
162
163 // wait for MPU interrupt or extra packet(s) available
164 while (!mpuInterrupt && fifoCount < packetSize)
165 {
166 //no mpu data ‐ performing PID calculations and output to motors
167
168 pid.Compute();
169 motorController.move(output, MIN_ABS_SPEED);
170
171 unsigned long currentMillis = millis();
172
173 if (currentMillis ‐ time1Hz >= 1000)
174 {
175 loopAt1Hz();
176 time1Hz = currentMillis;
177 }
178
http://make.robimek.com/arduinoselfbalancingrobot/ 3/9
15/1/2017 Arduino Auto Balanceador Robot
177 }
178
179 if (currentMillis ‐ time5Hz >= 5000)
180 {
181 loopAt5Hz();
182 time5Hz = currentMillis;
183 }
184 }
185
186 // reset interrupt flag and get INT_STATUS byte
187 mpuInterrupt = false;
188 mpuIntStatus = mpu.getIntStatus();
189
190 // get current FIFO count
191 fifoCount = mpu.getFIFOCount();
192
193 // check for overflow (this should never happen unless our code is too inefficient)
194 if ((mpuIntStatus & 0x10) || fifoCount == 1024)
195 {
196 // reset so we can continue cleanly
197 mpu.resetFIFO();
198 Serial.println(F("FIFO overflow!"));
199
200 // otherwise, check for DMP data ready interrupt (this should happen frequently)
201 }
202 else if (mpuIntStatus & 0x02)
203 {
204 // wait for correct available data length, should be a VERY short wait
205 while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
206
207 // read a packet from FIFO
208 mpu.getFIFOBytes(fifoBuffer, packetSize);
209
210 // track FIFO count here in case there is > 1 packet available
211 // (this lets us immediately read more without waiting for an interrupt)
212 fifoCount ‐= packetSize;
213
214 mpu.dmpGetQuaternion(&q, fifoBuffer);
215 mpu.dmpGetGravity(&gravity, &q);
216 mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
217 #if LOG_INPUT
218 Serial.print("ypr\t");
219 Serial.print(ypr[0] * 180/M_PI);
220 Serial.print("\t");
221 Serial.print(ypr[1] * 180/M_PI);
222 Serial.print("\t");
223 Serial.println(ypr[2] * 180/M_PI);
224 #endif
225 input = ypr[1] * 180/M_PI + 180;
226 }
227 }
228
CASA
229
230 void loopAt1Hz()
231 {
ACERCA DE
232 #if MANUAL_TUNING
233 setPIDTuningValues();
234 #endif
CONTACTO
235 }
236
237
238 void loopAt5Hz()
239 {
240 #if MOVE_BACK_FORTH
241 moveBackForth();
242 #endif
243 }
244
245
246 //move back and forth
247
248
249 void moveBackForth()
250 {
251 moveState++;
252 if (moveState > 2) moveState = 0;
253
254 if (moveState == 0)
255 setpoint = originalSetpoint;
256 else if (moveState == 1)
257 setpoint = originalSetpoint ‐ movingAngleOffset;
258 else
259 setpoint = originalSetpoint + movingAngleOffset;
260 }
261
262
CASA PROYECTOS APLICADOS HACER ROBOT 15 DE ENERO DE
2017
263 //PID Tuning (3 potentiometers)
264
265 #if MANUAL_TUNING
266 void setPIDTuningValues()
267 {
268 readPIDTuningValues();
269
270 if (kp != prevKp || ki != prevKi || kd != prevKd)
271 {
272 #if LOG_PID_CONSTANTS
273 Serial.print(kp);Serial.print(", ");Serial.print(ki);Serial.print(
274 #endif
275
276 pid.SetTunings(kp, ki, kd);
277 prevKp = kp; prevKi = ki; prevKd = kd;
278 }
279 }
280
281
282 void readPIDTuningValues()
283 {
284 int potKp = analogRead(A0);
285 int potKi = analogRead(A1);
286 int potKd = analogRead(A2);
287
288 kp = map(potKp, 0, 1023, 0, 25000) / 100.0; //0 ‐ 250
289 ki = map(potKi, 0, 1023, 0, 100000) / 100.0; //0 ‐ 1000
290 kd = map(potKd, 0, 1023, 0, 500) / 100.0; //0 ‐ 5
291 }
292 #endif
http://make.robimek.com/arduinoselfbalancingrobot/ 4/9
15/1/2017 Arduino Auto Balanceador Robot
CASA
ACERCA DE
CONTACTO
'Haga su propio robot' en equilibrio con el Arduino en esta parte de nuestro proyecto
hemos completado nuestro robot de pie. Hacer sus robots para discutir nuestro
próximo proyecto .. buen trabajo ...
http://make.robimek.com/arduinoselfbalancingrobot/ 5/9
15/1/2017 Arduino Auto Balanceador Robot
próximo proyecto .. buen trabajo ...
Http://www.robimek.com/arduino-ile-kendini-dengeleyen-robot-yapimi/
CONTACTO
, De todas las opciones posibles estoy de acuerdo que Centacare es uno de los menos malos.
Pero después de haber seguido de cerca la investigación del Senado, lo hago, y creo que las
preocupaciones que se plantean son injustas.
Respuesta
Hola buenos dias. Soy estudiante de escuela técnica, tengo 16 años, tengo un diseño
cientí䈦�co de un péndulo invertido para usuarios de personas de la silla de ruedas. Estoy en
el ensamblaje del prototipo, y estoy utilizando casi todos sus componentes, como el
Arduino, estoy usando MPU6050, y el puente h L298d, sin embargo este puente h no es el
keyes, este código será Funcionan normalmente ?? Estoy muy agradecido de poder
responderme y darme algunos consejos para que estoy un poco confundido en esta parte!
Gracias por la atención.
Respuesta
CASA PROYECTOS APLICADOS HACER ROBOT 15 DE ENERO DE
2017
Debe establecer el valor pid con tres potenciómetros. A0, A1 y A2 utilizando la conꝝguración de
valores kp, kd y ki
Gracias por la información, sin embargo mi puente es diferente ... h tiene el mismo chi sólo
que es menor. Usted también podría decirme por qué los chicos utiliza Habilita el puente
h? Gracias, que tenga un buen día.
Respuesta
También puede utilizar otro puente hi. Pero esta unidad está trabajando estable, es una ventaja.
Comprobación de los errores que utilizan la biblioteca. Si utiliza otro controlador tiene que
cambiar el código.
¡Hola!
¿Dónde coloca y conecta el potenciómetro de 3 piezas? (En detalle por favor!)
¿Cuál es la resistencia del potenciómetro? B10K?
¿Cuál es el voltaje de la batería LiPo?
Si se agrega peso a la parte superior del robot tratará de equilibrar el trabajo fuera?
Respuesta
Hola,
El potenciómetro de 3 piezas son pines de señal Analog 0, Analog 1, Analog 2 wear. Uso de la
batería Lipo 7.2 v 1050 mah. El motor puede poner el peso suꝝciente para cumplir con el par.
http://make.robimek.com/arduinoselfbalancingrobot/ 6/9
15/1/2017 Arduino Auto Balanceador Robot
Responder Post Autor
gracias.
¿De dónde se conectan las otras patas del potenciómetro?
Respuesta
Hola, soy students.i tengo 14 años old.i tengo una competición para month.i siguiente
CASA
necesidad de crear mi propio project.i tengo plan para hacer robot.because de equilibrio
de sí adecuado para mi tema "automotriz" .so que necesito Usted ayuda a hacer este
ACERCA DE
proyecto. ¿Puede usted demostrarme 1 por 1 cómo hacer este project.i'm aprecio tan si
CONTACTO
usted puede help.i quiere realmente mi proyecto sea success.Or si usted tiene problema
para mostrarme los esquemas que usted puede Muéstrame enviando un video.
Respuesta
Respuesta
Respuesta
#incluir
Compilación terminada.
Estado de salida 1
Error al compilar para la tarjeta Arduino / Genuino Uno.
Respuesta
Respuesta
Nope. 14 historias es todavía mucho. Te doy prolí䈦�co. (No puedo conseguir más de unos 10
en un momento dado, aunque incluyendo reciente prisa de も�ash prtdcuoivity, podría ser
en torno a 14.)
Respuesta
Estoy hecho con todas las conexiones, pero estoy atascado en "
http://make.robimek.com/arduinoselfbalancingrobot/ 7/9
15/1/2017 Arduino Auto Balanceador Robot
Habilitar la detección de interrupción (Arduino interrupción externa 0) ...
CASA
DMP listo! Esperando la primera interrupción ...
" ACERCA DE
Respuesta
Respuesta
Hola estoy recibiendo error en mpu 6050 qué hacer, puede ayudarme por favor
Inicialización de dispositivos I2C ...
Prueba de conexiones de dispositivos ...
Error de conexión de
MPU6050 Inicialización de DMP ... Error de inicialización de DMP
(código 1)
Respuesta
activa en las ruedas girar sin parar. Sin embargo cuando se prueban los out puts del
arduino al motor stepper están funcionando bien y reaccionan a la posición del
girocompás. ¿Alguna idea?
Respuesta
#include "I2Cdev.h"
Compilación terminada.
Exit status 1
Error de compilación.
"
Respuesta
Deja Un Comentario
Su dirección de correo electrónico no será publicada. Los campos obligatorios están marcados *
Nombre *
Correo Electrónico *
Sitio Web
CASA
ACERCA DE
Enviar Comentario
CONTACTO
http://make.robimek.com/arduinoselfbalancingrobot/ 8/9
15/1/2017 Arduino Auto Balanceador Robot
ROBIMEK
COPYRİGHT © 2015 ROBİMEK, TODOS LOS DERECHOS RESERVADOS
CASA O PROYECTOS APLICADOS O HACER ROBOT
CASA
ACERCA DE
CONTACTO
http://make.robimek.com/arduinoselfbalancingrobot/ 9/9