Hi friends, I want to show some Arduino-based projects I did.
An Arduino Mega controlled hexapod robot, with 18 Dynamixel AX-12 motors:
This uses the Arduino Dynamixel library:
Some Arduino DMX lighting:
And finally, an Artificial Neural Network based voice recognition system, running completely in the Wiring board (that is almost identical to Arduino), without the aid of an external PC:
Hi Federico, thank you very much for your comment.
Yes, of course, I can paste the code here. By the way: you speak Spanish? Because the code comments are all in Spanish, and I speak very bad English.
First, there are some definitions and pre-computed constants to speed up calculations.
// tipos
typedef struct {float x; float z;} COORD2D;
typedef struct {float x; float y; float z;} COORD3D;
typedef struct {COORD3D patas[6];} POSICION;
typedef struct {int gama; int alfa; int beta;} ANGULOS;
// propiedades del robot
#define BAUDRATE 1000000 // velocidad de comunicación de los AX12
#define DIST 5.0 // distancia entre el eje del primer motor y el segundo (en cm)
#define MUSLO 8.2 // longitud del "muslo" (en cm)
#define TIBIA 11.7 // longitud de la "tibia" (en cm)
#define SEPARA 8.75 // separación entre las inserciones de las patas (en cm)
#define ORIGEN 9.6 // distancia entre el origen de la x y el centro del tronco (en cm)
#define ANG_SCALE 614 // unidades angulares, equivalente a PI o 180º
#define ANG_ZERO 518 // offset angular (teóricamente tendría que ser 512, pero ya ves...)
#define TICK .004 // duración del tick en segundos
#define VEL_MAX 684 /* velocidad máxima de la escala en grados/segundo. (Nota: 119rpm según la info actualizada de Dynamixel, lo que equivale a 684º/s. No obstante, el motor no pasa de los 300º/s, por lo que adquiere su velocidad máxima por la mitad de la escala. */
// constantes para acelerar el cálculo
float const doublea = 2 * MUSLO;
float const doubleab = 2 * MUSLO * TIBIA;
float const sqaplussqb = sq (MUSLO) + sq (TIBIA);
float const sqaminussqb = sq (MUSLO) - sq (TIBIA);
float const vel_scale = 184200.0 / (TICK*VEL_MAX*ANG_SCALE); /* velocidad(AX12) = unidades_angulares*vel_scale/ticks */
byte const overflow = 256 - (TICK*14000); // valor inicial del contador para el timer2
Then there is a pair of routines, one that converts Cartesian coordinates to angles, and the other does the reverse:
ANGULOS alfabetagama (COORD3D P) {
// convierte las coordenadas cartesianas en los ángulos correspondientes
// recibe: xn, y, z; devuelve giro (gama), cadera (alfa), rodilla (beta)
// fundamento: teorema de pitágoras + teorema del coseno (ver figura)
P.x = abs (P.x); // pequeño truco para abarajar la simetría del eje x
ANGULOS A;
// fase 1, calculamos "x" y el ángulo "gama"
// DIST es la distancia entre el eje del primer motor y el segundo
float x = hypot (P.z, P.x+DIST) - DIST; // P.x = xn
A.gama = ANG_SCALE*(atan(P.z/(P.x+DIST)))/PI;
// fase 2, calculamos alfa y beta
// ver constantes definidas al principio
float sqx = sq(x); float sqy = sq(P.y);
float cosalfa = (sqx + sqy + sqaminussqb) / (doublea*sqrt(sqx + sqy)); // coseno del angulo que forman el "muslo" y la hipotenusa
float cosbeta = (sqaplussqb - sqx - sqy) / doubleab; // coseno del angulo que forman "muslo" y "tibia"
A.alfa = ANG_SCALE*(acos(cosalfa) + atan(P.y/x))/PI;
A.beta = ANG_SCALE/2 - ANG_SCALE*acos(cosbeta)/PI;
return A;
}
COORD3D xyz (int angulos[]) { // "cinemática directa"
float rad [3];
for (byte i=0; i<3; i++) {
rad[i] = PI * angulos[i] / ANG_SCALE; // convierte a radianes
}
// rad[0] = gama; rad[1] = alfa; rad[2] = beta
float sqc = sqaplussqb - (doubleab * cos(rad[2]-PI/2));
float c = sqrt(sqc);
float cosalfa = (sqc + sqaminussqb) / (doublea*c);
float delta = rad[1] - acos(cosalfa);
float x = c * cos(delta);
return (COORD3D) {(x+DIST)*cos(rad[0]) - DIST, c*sin(delta), (x+DIST)*sin(rad[0])};
}
pabloxid:
Hi Federico, thank you very much for your comment.
Yes, of course, I can paste the code here. By the way: you speak Spanish? Because the code comments are all in Spanish, and I speak very bad English.
Personally, your english seems fine to me; certainly better than my spanish! Your comments and such, even in spanish, are fairly clear, and I can make out what most of them are; I imagine that google translate could take care of the rest...
I am Italian and I studied spanish for few years, so I think it's fine. Now that I think about it, did you previously released part of this work? I am pretty sure that I have already seen the "voice command" part...
I am really interested in building a robot like this, but I have never started because of the price of the servos :-/