This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
Robot con servos y ultrasonido
#1
Buenas. Estoy tratando de montar un robot con dos servos y un ultrasonido. Es mantisWalkerUltrasonicMk2.ino
El sketch lo compila bien, pero me da problemas al subirlo a arduino nano. Es el siguiente

#define STEP_DELAY 160
#define STOP_DISTANCE 10  //stop distance in cm

#include <Servo.h>
#include <NewPing.h>


//format: front leg position, back leg position
char walkingForward[] = {SERVO_BACK_DISTANCE, SERVO_FORWARD_DISTANCE,
                        SERVO_FORWARD_DISTANCE, SERVO_FORWARD_DISTANCE,
                        SERVO_FORWARD_DISTANCE, SERVO_BACK_DISTANCE,
                        SERVO_BACK_DISTANCE, SERVO_BACK_DISTANCE
                        };
NewPing sonarEyes(TRIGGER_PIN, ECHO_PIN, MAXIMUM_DISTANCE);
Servo servoBackLegs, servoFrontLegs;


void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
 
  //setup Pins to connect Servos To
  pinMode(BACK_LEGS_GND, OUTPUT);  //tie pin 8 to GND
  digitalWrite(BACK_LEGS_GND, LOW);
  pinMode(BACK_LEGS_VCC, OUTPUT);  //tie pin 9 to VCC
  digitalWrite(BACK_LEGS_VCC,HIGH);
  servoBackLegs.attach(BACK_LEGS_PIN);
 
  pinMode(FRONT_LEGS_VCC, OUTPUT);  //tie pin 2 to VCC
  digitalWrite(FRONT_LEGS_VCC, HIGH);
  servoFrontLegs.attach(FRONT_LEGS_PIN);

  servoBackLegs.write(SERVO_CENTRED);
  servoFrontLegs.write(SERVO_CENTRED);

  //setup Pins for Ultrasonic Sensor
  pinMode(US_GND, OUTPUT);
  digitalWrite(US_GND, LOW);
  pinMode(US_VCC, OUTPUT);
  digitalWrite(US_VCC,HIGH);
 
  delay(2000);
 
  digitalWrite(LED_BUILTIN, LOW); //turn off built in LED
}

void loop() {
  // put your main code here, to run repeatedly:
  while (checkForObstruction()) {  //returns true if obstruction, otherwise skip this loop
    digitalWrite(LED_BUILTIN, HIGH);  //turn on LED for visual indication of obstruction
    //step back and turn
    delay(2000);
    walkBackAndTurnLeft();
    digitalWrite(LED_BUILTIN, LOW);  //turn back off again
  }
  stepForward();
}

void stepForward() {
  for (int n = 0; n < 4; n++) {
    servoFrontLegs.write(walkingForward[n * 2]);
    servoBackLegs.write(walkingForward[(n * 2) + 1]);
    delay(STEP_DELAY);
  }
}

void walkBackAndTurnLeft()  {
  for (int n = 0; n < 14; n++) {
    servoFrontLegs.write(SERVO_CENTRED);
    servoBackLegs.write(SERVO_BACK_DISTANCE - 40);
    delay(200);
    servoFrontLegs.write(SERVO_FORWARD_DISTANCE);
    servoBackLegs.write(SERVO_FORWARD_DISTANCE + 20);
    delay(300);
  }
  servoFrontLegs.write(SERVO_CENTRED);
  servoBackLegs.write(SERVO_CENTRED);
  delay(300);
}

bool checkForObstruction() {
  int distance = sonarEyes.ping_cm();
  if (distance <= STOP_DISTANCE && distance != 0) {
    return true;
  } else {
    return false;
  }
}


El mensaje de error es Arduino:1.8.12 (Linux), Tarjeta:"Arduino Nano, ATmega328P"

El Sketch usa 3052 bytes (9%) del espacio de almacenamiento de programa. El máximo es 30720 bytes.
Las variables Globales usan 83 bytes (4%) de la memoria dinámica, dejando 1965 bytes para las variables locales. El máximo es 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problema subiendo a la placa. Visita http://www.arduino.cc/en/Guide/Troubleshooting#upload para sugerencias.

Este informe podría contener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.

Alguien puede ayudarme ?.
Un saludo
  Responder
#2
Buenos días.

En Linux no puedo ayudarte, pero supongo que el IDE funcionará de una manera parecida.

Código:
El mensaje de error es Arduino:1.8.12 (Linux), Tarjeta:"Arduino Nano, ATmega328P"

El Sketch usa 3052 bytes (9%) del espacio de almacenamiento de programa. El máximo es 30720 bytes.
Las variables Globales usan 83 bytes (4%) de la memoria dinámica, dejando 1965 bytes para las variables locales. El máximo es 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00


Con este mensaje de error, parece que el problema es que el IDE no puede comunicarse con el Arduino NANO, comprueba en la pestaña del IDE llamada "Herramientas", "placa", que tengas seleccionado "Arduino Nano", si no lo tienes seleccionado, tendrás que cambiar la placa que tengas seleccionada por el Arduino Nano.


De todas formas a mi me da otro error de compilación, dice que no están declarados todo lo que pones en estas líneas

Código:
//format: front leg position, back leg position
char walkingForward[] = {SERVO_BACK_DISTANCE, SERVO_FORWARD_DISTANCE,
                        SERVO_FORWARD_DISTANCE, SERVO_FORWARD_DISTANCE,
                        SERVO_FORWARD_DISTANCE, SERVO_BACK_DISTANCE,
                        SERVO_BACK_DISTANCE, SERVO_BACK_DISTANCE
                        };

porque no has declarado el objeto servo, ni las funciones que tiene que realizar, has copiado mal el programa, lo extraño es que a ti si te compila. Pero yo trabajo con Windows y tu trabajas con Linux.


Un saludo.
  Responder
#3
Buenos días.
Perdón por la tardanza. El problema estaba en la placa compatible. Funciona, aunque en vez de parar vuelca
Muchas gracias
  Responder
#4
Gracias por la información!
Aprende a invertir en criptos, fórex o materias primas con este bróker https://roboforex.com/es/beginners/info/...ex/gbpcad/ que ya lleva mucho tiempo en el mercado.
  Responder
#5
Buenas tardes.

Me alegro que ya funcione, un saludo.
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  Robot niños Robomaker Clementoni Pau Bassets 0 572 04-06-2020, 12:24 PM
Último mensaje: Pau Bassets
Dedo arriba Global Robot Expo Madrid samuelb 11 3,847 04-03-2016, 03:05 PM
Último mensaje: Milay