Araña con servos

Hola gente de Arduino
Creamos una araña robot con 8 servos mas un detector de distancia en los ojos y no logramos que el código que obtuvimos la haga mover, No sabemos si es un problema de energía o de código o que pero necesitamos ayuda
Alguien realizo este tipo de proyecto para que nos pueda ayudar
Gracais

Sube esquema de montaje y código, sin algún dato más solo se pueden echar las cartas del tarot.
Empieza por el esquema y sin olvidar la alimentación.
Saludos.

A mi se me rompió la bola de cristal y además tengo fobia a las arañas así que paso. :grin:

Supongo habras buscado porque hace 2 dias con un amigo que arma robots justamente hablábamos de algo parecido, pero está siemplemente buscándolo.

Moderador:
No has cometido ninguna falta pero por favor, lee las Normas del foro.

COMPONENTES UTILIZADOS
• ARDUINO UNO
• MODULO SERVO SHIELD ARDUINO COMPATIBLE 16 CANALES PWM 12BITS
• 8 servos (2 por patas) SG90
• 1 Servo en cuello y un Sensor Ultrasónico HC-SR04
• Fuente 5v 5a

No me deja adjuntar fotos ni el archivo ino por ser usuario nuevo

Aqui va el codigo
// -------- --------
// | D9 | | D7 |
// | joint9 | | joint7 |
// ----- -------- --------- -----
// | D8 | | D6 |
// | joint8 | | joint6 |
// -------- --------
// | D2 | | D4 |
// | joint2 | | joint4 |
// ----- -------- --------- -----
// | D3 | | D5 |
// | joint3 | | joint5 |
// -------- --------
// Front

#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver servo = Adafruit_PWMServoDriver (0x40);

//Declaración de servos
Servo joint2; // cadera delantera derecha
Servo joint3; // pata delantera derecha
Servo joint4; // cadera delantera izquierda
Servo joint5; // pata delantera izquierda
Servo joint6; // cadera trasera izquierda
Servo joint7; // pata trasera izquierda
Servo joint8; // cadera trasera derecha
Servo joint9; // pata trasera derecha
Servo neck_servo; // servo de cuello

//posición de la casa
int home_joint2 = 120;
int home_joint3 = 15;
int home_joint4 = 60;
int home_joint5 = 165;
int home_joint6 = 100;
int home_joint7 = 15;
int home_joint8 = 70;
int home_joint9 = 165;

//servo de cuello
#define neck_survoPin 10
#define trigPin 11
#define echoPin 12

float Dulation = 0;
float Distance = 0;
int angle = 90;
int sum = 0;

void setup(){

joint2.attach(2);
joint3.attach(3);
joint4.attach(4);
joint5.attach(5);
joint6.attach(6);
joint7.attach(7);
joint8.attach(8);
joint9.attach(9);

neck_servo.attach(neck_survoPin, 500, 2400);
neck_servo.write(90);

pinMode(echoPin,INPUT);
pinMode(trigPin,OUTPUT);

joint2.write(home_joint2);
joint3.write(home_joint3);
joint4.write(home_joint4);
joint5.write(home_joint5);
joint6.write(home_joint6);
joint7.write(home_joint7);
joint8.write(home_joint8);
joint9.write(home_joint9);

delay(3000);
Serial.begin(9600);
}

void loop(){

standhome();
forward(1);

//Uso de sensores ultrasónicos
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
Dulation = pulseIn(echoPin,HIGH);

if(Dulation>0){
int Distance = Dulation340100/2/1000000;

if(Distance < 10){
  int right = 0;
  int left = 0;
  int sumright = 0;
  int sumleft = 0;
  
  int i = 170;
  delay(10);
  while(i >= 120){
    neck_servo.write(i);
    i=i-2;
    digitalWrite(trigPin,LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin,HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin,LOW);
    Dulation = pulseIn(echoPin,HIGH);
    int Distance = Dulation*340*100/2/1000000;
    
    if(Distance <15){
      left = 1;
      sumleft++;
    }else {
        left = 0;
      }
      delay(10);           
  }
  
 i =10;
 delay(10);
 while(i <= 60){
    neck_servo.write(i);
    i=i+2;
    digitalWrite(trigPin,LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin,HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin,LOW);
    Dulation = pulseIn(echoPin,HIGH);
    int Distance = Dulation*340*100/2/1000000;

    if(Distance <15){
      right = 1;
      sumright++;
    }else {
      right = 0;
    }
      delay(10);       
 }


 neck_servo.write(90);
 delay(10);

  if(sumright > sumleft){
  leftturn(3);     
 } else {
  rightturn(3);
 }

 if(sumright >= 20){
  backward(3);
  leftturn(3);
 } else if(sumleft >= 20){
  backward(3);
  rightturn(3);
 }  

}
}
delay(10);

}

// tiempo de inactividad
void idle(){
delay(100);
}

//Posición inicial de pie
void standhome(){
joint2.write(home_joint2);
joint3.write(home_joint3);
joint4.write(home_joint4);
joint5.write(home_joint5);
joint6.write(home_joint6);
joint7.write(home_joint7);
joint8.write(home_joint8);
joint9.write(home_joint9);

}

//Extiende tus brazos y toca el suelo
void sithome(){
joint2.write(135);
joint3.write(65);
joint4.write(45);
joint5.write(110);
joint6.write(135);
joint7.write(80);
joint8.write(45);
joint9.write(110);
}

//Acción de levantarse 1
void stand1(){
sithome();
joint2.write(170);
delay(300);
joint2.write(home_joint2);
delay(300);
joint4.write(10);
delay(300);
joint4.write(home_joint4);
delay(300);
joint6.write(170);
delay(300);
joint6.write(home_joint6);
delay(300);
joint8.write(10);
delay(300);
joint8.write(home_joint8);
delay(300);

joint3.write(home_joint3);
joint5.write(home_joint5);
joint7.write(home_joint7);
joint9.write(home_joint9);
}

// Acción de levantarse 2
void stand2(){
sithome();
joint2.write(175);
joint4.write(5);
joint6.write(175);
joint8.write(5);
delay(600);

joint2.write(home_joint2);
joint4.write(home_joint4);
joint6.write(home_joint6);
joint8.write(home_joint8);
delay(600);

joint3.write(home_joint3);
joint5.write(home_joint5);
joint7.write(home_joint7);
joint9.write(home_joint9);
}

// Acción de levantarse 3
void stand3(){
sithome();
int i;
int j = 90;
int k = 90;
joint2.write(home_joint2);
joint4.write(home_joint4);
joint6.write(home_joint6);
joint8.write(home_joint8);
for(i = 90; i < 165; i++)
{
joint5.write(i);
j = j - 1;
joint3.write(j);
delay(20);
}

for(i = 115; i < 165; i++)
{
joint9.write(i);
k = k - 1;
joint7.write(k);
delay(20);
}
}

// arriba y abajo rápidamente
void downaction(unsigned int step){
while (step-- > 0){
sithome();
delay(100);
standhome();
delay(100);
}
}

//agitar las manos
void wink(unsigned int step){
standhome();
joint9.write(home_joint9-30);

while (step-- > 0){
joint5.write(30);
joint4.write(home_joint4 + 60);
delay(300);
joint4.write(home_joint4 - 60);
delay(300);
}
}

// mover el cuerpo
void twist(){
joint3.write(home_joint3);
joint5.write(home_joint5);
joint7.write(home_joint7);
joint9.write(home_joint9);

for(int right=90;right<170;right++){
joint2.write(right);
joint6.write(right);
joint4.write(right-90);
joint8.write(right-90);
delay(10);
}

for(int right=170;right>90;right--){
joint2.write(right);
joint6.write(right);
joint4.write(right-90);
joint8.write(right-90);
delay(10);
}

}

// Adelante (número de pasos)
void forward(unsigned int step){
while (step-- > 0){

joint3.write(home_joint3+30);
joint7.write(home_joint7+30);
delay(100);
joint2.write(home_joint2+30);
joint8.write(home_joint8-30);
joint4.write(home_joint4);
joint6.write(home_joint6);
delay(100);
joint3.write(home_joint3);
joint7.write(home_joint7);
idle();

joint5.write(home_joint5-30);
joint9.write(home_joint9-30);
delay(100);
joint2.write(home_joint2);
joint8.write(home_joint8);
joint4.write(home_joint4-30);
joint6.write(home_joint6+30);
delay(100);
joint5.write(home_joint5);
joint9.write(home_joint9);
idle();

}
}

// Hacia atrás (número de pasos)
void backward(unsigned int step){
while (step-- > 0){
joint3.write(home_joint3+30);
joint7.write(home_joint7+30);
delay(100);
joint2.write(home_joint2);
joint8.write(home_joint8);
joint4.write(home_joint4-30);
joint6.write(home_joint6+30);
delay(100);
joint3.write(home_joint3);
joint7.write(home_joint7);
idle();

joint5.write(home_joint5-30);
joint9.write(home_joint9-30);
delay(100);
joint2.write(home_joint2+30);
joint8.write(home_joint8-30);
joint4.write(home_joint4);
joint6.write(home_joint6);
delay(100);
joint5.write(home_joint5);
joint9.write(home_joint9);
idle();
}
}

// en el sentido de las agujas del reloj (número de pasos)
void rightturn(unsigned int step){
neck_rightrotate();
while (step-- > 0){
joint5.write(home_joint5-30);
joint9.write(home_joint9-30);
delay(100);
joint2.write(home_joint2+30);
joint8.write(home_joint8-30);
joint4.write(home_joint4-30);
joint6.write(home_joint6+30);
delay(100);
joint5.write(home_joint5);
joint9.write(home_joint9);
idle();

joint3.write(home_joint3+30);
joint7.write(home_joint7+30);
delay(100);
joint2.write(home_joint2);
joint8.write(home_joint8);
joint4.write(home_joint4);
joint6.write(home_joint6);
delay(100);
joint3.write(home_joint3);
joint7.write(home_joint7);
idle();
}
neck_home();
}

// en sentido contrario a las agujas del reloj (número de pasos)
void leftturn(unsigned int step){
neck_leftrotate();
while (step-- > 0){
joint3.write(home_joint3+30);
joint7.write(home_joint7+30);
delay(100);
joint2.write(home_joint2+30);
joint8.write(home_joint8-30);
joint4.write(home_joint4-30);
joint6.write(home_joint6+30);
delay(100);
joint3.write(home_joint3);
joint7.write(home_joint7);
idle();

joint5.write(home_joint5-30);
joint9.write(home_joint9-30);
delay(100);
joint2.write(home_joint2);
joint8.write(home_joint8);
joint4.write(home_joint4);
joint6.write(home_joint6);
delay(100);
joint5.write(home_joint5);
joint9.write(home_joint9);
idle();
}
neck_home();
}

// Mueva el cuello hacia la izquierda y hacia la derecha (el sensor está apagado)
void neckrotate(){
int i=90;
while(i < 150){
neck_servo.write(i);
i++;
delay(5);
}
while(i > 30){
neck_servo.write(i);
i--;
delay(5);
}
while(i <= 90){
neck_servo.write(i);
i++;
delay(5);
}
}

// gira la cabeza hacia la izquierda
void neck_leftrotate(){
int i=90;
while(i < 150){
neck_servo.write(i);
i++;
delay(5);
}
}

// girar la cabeza a la derecha
void neck_rightrotate(){
int i=90;
while(i > 30){
neck_servo.write(i);
i--;
delay(5);
}
}

// posición inicial del cuello
void neck_home(){
neck_servo.write(90);
}

Por favor, no has mirado otros hilos para comprender como se postea un código?
Los códigos se pegan usando etiquetas.
Edita. Punto 7 de las normas.

No suelo responder ni aconsejar cuando el código no esta bien posteado, pero solo te diré que hacer una robot araña y usar delay() no tienen futuro.
Y es peor cuando los anidas o sea los sumas el delay dentro de un loop (while) como acá.

void neck_rightrotate(){
   int i=90;
   while(i > 30){
       neck_servo.write(i);
       i--;
       delay(5);
   }
}

5 x 30 mseg = 150 mseg no es gran cosa. Pero suma esos retardos y comprometes todo.

Por cierto, usando tu IDE agrega formato al código, es muy incomodo entender el código de alguien que esta todo pegado al margen.

NOTA: Observa como se ve el código y además debidamente formateado.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.