24-06-2024, 03:45 AM
Buenas noches
Alguien me podria ayudar con este codigo por favor, me sale EXIT STATUS 3
#include <Servo.h>
long Distancia;
long Distancia_Frontal;
long Distancia_Inferior=0;
char Obstaculo[3];
int PWM_MAXIMA = 100;
int PWM_MINIMA = 80;
Servo servoSonar;
// definimos los pines del Sonar. Frontal
const int Trig_Frontal= 12;
const int Echo_Frontal= 18;
// definimos los pines del Sonar. Inferior
const int Trig_Inferior= 42;
const int Echo_Inferior= 40;
void setup() {
Serial.begin(9600);
// definimos salida y entrada del sonar Frontal
pinMode(11, OUTPUT);
pinMode(10, INPUT);
pinMode(13, OUTPUT);
digitalWrite(11, HIGH); // alimentación.
pinMode(Echo_Frontal, INPUT);
pinMode(Trig_Frontal, OUTPUT);
digitalWrite(Trig_Frontal, LOW);
pinMode(Echo_Inferior, INPUT);
pinMode(Trig_Inferior, OUTPUT);
digitalWrite(Trig_Inferior, LOW);
// Salidas PWM para el PuenteH
pinMode(2, OUTPUT); // UP MotorL
pinMode(3, OUTPUT); // DOWN MotorL
pinMode(4, OUTPUT); // DOWN MotorR
pinMode(5, OUTPUT); // UP MotorR
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(13, HIGH);
servoSonar.attach(6);
delay(1000);
digitalWrite(13, LOW);
DetectarObstaculo();
delay(2000);
digitalWrite(13, HIGH);
servoSonar.write(90);
delay(1000);
digitalWrite(13, LOW);
}
void loop() {
Sonar(Trig_Inferior, Echo_Inferior);
Distancia_Inferior = Distancia;
if (Distancia_Inferior <=4){
// si no hay borde *********
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
// Serial.println(Distancia_Frontal);
if (Distancia_Frontal > 50){
MOVE_UP();
} else { if (Distancia_Frontal > 20 && Distancia_Frontal <= 50){
analogWrite(2, 0);
analogWrite(3, map(Distancia_Frontal, 20, 50, PWM_MINIMA, PWM_MAXIMA));
analogWrite(4, 0);
analogWrite(5, map(Distancia_Frontal, 20, 50, PWM_MINIMA, PWM_MAXIMA));
} else {
// *************
digitalWrite(13, HIGH);
// prueba
MOVE_REV();
delay(500);
STOP();
delay(500);
MOVE_180();
//
STOP();
DetectarObstaculo();
delay(1000);
if (Obstaculo[0]=='0' && Obstaculo[1]=='0' && Obstaculo[2]=='0'){ //
MOVE_UP();
}
if (Obstaculo[0]=='0' && Obstaculo[1]=='1' && Obstaculo[2]=='0'){ //
STOP();
delay(500);
MOVE_RIGHT();
STOP();
delay(1000);
}
if (Obstaculo[0]=='0' && Obstaculo[2]=='1'){ // obst Izquierda
MOVE_RIGHT();
STOP();
delay(1000);
}
if (Obstaculo[0]=='1' && Obstaculo[2]=='0'){ // obst Derecha
MOVE_LEFT();
STOP();
delay(1000);
}
if (Obstaculo[0]=='1' && Obstaculo[2]=='1'){ // obst Derecha
STOP();
delay(1000);
while(Obstaculo[0]=='1' && Obstaculo[2]=='1'){
MOVE_REV();
delay(500);
STOP();
DetectarObstaculo();
delay(1000);
}
if (Obstaculo[0]=='0'){
MOVE_RIGHT(); } else {
MOVE_LEFT();
}
delay(1000);
}
digitalWrite(13, LOW);
//**************
}
}
//******************************
} else {
digitalWrite(13, HIGH);
MOVE_FRENO();
//delay(100);
STOP();
delay(1000);
MOVE_REV();
delay(500);
STOP();
delay(1000);
MOVE_180();
STOP();
delay(1000);
digitalWrite(13, LOW);
}
} // fin loop
// Serial.println(Distancia_Frontal);
// Serial.println(Distancia_Inferior);
//DetectarObstaculo();
// funcion Calcular distancia *****************
void Sonar(int Trig, int Echo){
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
// retorna tiempo en microseg.
long tiempoEcho = pulseIn(Echo, HIGH,200000);
Distancia = tiempoEcho *0.017;
delay(20);
}
// Movimientos del Robot.
void MOVE_UP(){
analogWrite(2, 0);
analogWrite(3, PWM_MAXIMA);
analogWrite(4, 0);
analogWrite(5, PWM_MAXIMA);
}
void STOP(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void MOVE_LEFT(){
analogWrite(2, 0);
analogWrite(3, PWM_MAXIMA);
analogWrite(4, PWM_MAXIMA);
analogWrite(5, 0);
delay(250);
}
void MOVE_RIGHT(){
analogWrite(2, PWM_MAXIMA);
analogWrite(3, 0);
analogWrite(4, 0);
analogWrite(5, PWM_MAXIMA);
delay(250);
}
void MOVE_180(){
analogWrite(2, PWM_MAXIMA);
analogWrite(3, 0);
analogWrite(4, 0);
analogWrite(5, PWM_MAXIMA);
delay(500);
}
void MOVE_REV(){
analogWrite(2, PWM_MAXIMA);
analogWrite(3, 0);
analogWrite(4, PWM_MAXIMA);
analogWrite(5, 0);
}
void MOVE_FRENO(){
analogWrite(2, 255);
analogWrite(3, 0);
analogWrite(4, 255);
analogWrite(5, 0);
delay(100);
STOP();
}
// Deteccion de obstaculos ***************
void DetectarObstaculo(){
servoSonar.write(0);
delay(500);
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
if (Distancia_Frontal <= 30){
Obstaculo[0]='1';
} else {
Obstaculo[0]='0';
}
servoSonar.write(90);
delay(500);
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
if (Distancia_Frontal <= 20){
Obstaculo[1]='1';
} else {
Obstaculo[1]='0';
}
servoSonar.write(180);
delay(500);
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
if (Distancia_Frontal <= 30){
Obstaculo[2]='1';
} else {
Obstaculo[2]='0';
}
servoSonar.write(90);
}
Alguien me podria ayudar con este codigo por favor, me sale EXIT STATUS 3
#include <Servo.h>
long Distancia;
long Distancia_Frontal;
long Distancia_Inferior=0;
char Obstaculo[3];
int PWM_MAXIMA = 100;
int PWM_MINIMA = 80;
Servo servoSonar;
// definimos los pines del Sonar. Frontal
const int Trig_Frontal= 12;
const int Echo_Frontal= 18;
// definimos los pines del Sonar. Inferior
const int Trig_Inferior= 42;
const int Echo_Inferior= 40;
void setup() {
Serial.begin(9600);
// definimos salida y entrada del sonar Frontal
pinMode(11, OUTPUT);
pinMode(10, INPUT);
pinMode(13, OUTPUT);
digitalWrite(11, HIGH); // alimentación.
pinMode(Echo_Frontal, INPUT);
pinMode(Trig_Frontal, OUTPUT);
digitalWrite(Trig_Frontal, LOW);
pinMode(Echo_Inferior, INPUT);
pinMode(Trig_Inferior, OUTPUT);
digitalWrite(Trig_Inferior, LOW);
// Salidas PWM para el PuenteH
pinMode(2, OUTPUT); // UP MotorL
pinMode(3, OUTPUT); // DOWN MotorL
pinMode(4, OUTPUT); // DOWN MotorR
pinMode(5, OUTPUT); // UP MotorR
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(13, HIGH);
servoSonar.attach(6);
delay(1000);
digitalWrite(13, LOW);
DetectarObstaculo();
delay(2000);
digitalWrite(13, HIGH);
servoSonar.write(90);
delay(1000);
digitalWrite(13, LOW);
}
void loop() {
Sonar(Trig_Inferior, Echo_Inferior);
Distancia_Inferior = Distancia;
if (Distancia_Inferior <=4){
// si no hay borde *********
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
// Serial.println(Distancia_Frontal);
if (Distancia_Frontal > 50){
MOVE_UP();
} else { if (Distancia_Frontal > 20 && Distancia_Frontal <= 50){
analogWrite(2, 0);
analogWrite(3, map(Distancia_Frontal, 20, 50, PWM_MINIMA, PWM_MAXIMA));
analogWrite(4, 0);
analogWrite(5, map(Distancia_Frontal, 20, 50, PWM_MINIMA, PWM_MAXIMA));
} else {
// *************
digitalWrite(13, HIGH);
// prueba
MOVE_REV();
delay(500);
STOP();
delay(500);
MOVE_180();
//
STOP();
DetectarObstaculo();
delay(1000);
if (Obstaculo[0]=='0' && Obstaculo[1]=='0' && Obstaculo[2]=='0'){ //
MOVE_UP();
}
if (Obstaculo[0]=='0' && Obstaculo[1]=='1' && Obstaculo[2]=='0'){ //
STOP();
delay(500);
MOVE_RIGHT();
STOP();
delay(1000);
}
if (Obstaculo[0]=='0' && Obstaculo[2]=='1'){ // obst Izquierda
MOVE_RIGHT();
STOP();
delay(1000);
}
if (Obstaculo[0]=='1' && Obstaculo[2]=='0'){ // obst Derecha
MOVE_LEFT();
STOP();
delay(1000);
}
if (Obstaculo[0]=='1' && Obstaculo[2]=='1'){ // obst Derecha
STOP();
delay(1000);
while(Obstaculo[0]=='1' && Obstaculo[2]=='1'){
MOVE_REV();
delay(500);
STOP();
DetectarObstaculo();
delay(1000);
}
if (Obstaculo[0]=='0'){
MOVE_RIGHT(); } else {
MOVE_LEFT();
}
delay(1000);
}
digitalWrite(13, LOW);
//**************
}
}
//******************************
} else {
digitalWrite(13, HIGH);
MOVE_FRENO();
//delay(100);
STOP();
delay(1000);
MOVE_REV();
delay(500);
STOP();
delay(1000);
MOVE_180();
STOP();
delay(1000);
digitalWrite(13, LOW);
}
} // fin loop
// Serial.println(Distancia_Frontal);
// Serial.println(Distancia_Inferior);
//DetectarObstaculo();
// funcion Calcular distancia *****************
void Sonar(int Trig, int Echo){
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
// retorna tiempo en microseg.
long tiempoEcho = pulseIn(Echo, HIGH,200000);
Distancia = tiempoEcho *0.017;
delay(20);
}
// Movimientos del Robot.
void MOVE_UP(){
analogWrite(2, 0);
analogWrite(3, PWM_MAXIMA);
analogWrite(4, 0);
analogWrite(5, PWM_MAXIMA);
}
void STOP(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void MOVE_LEFT(){
analogWrite(2, 0);
analogWrite(3, PWM_MAXIMA);
analogWrite(4, PWM_MAXIMA);
analogWrite(5, 0);
delay(250);
}
void MOVE_RIGHT(){
analogWrite(2, PWM_MAXIMA);
analogWrite(3, 0);
analogWrite(4, 0);
analogWrite(5, PWM_MAXIMA);
delay(250);
}
void MOVE_180(){
analogWrite(2, PWM_MAXIMA);
analogWrite(3, 0);
analogWrite(4, 0);
analogWrite(5, PWM_MAXIMA);
delay(500);
}
void MOVE_REV(){
analogWrite(2, PWM_MAXIMA);
analogWrite(3, 0);
analogWrite(4, PWM_MAXIMA);
analogWrite(5, 0);
}
void MOVE_FRENO(){
analogWrite(2, 255);
analogWrite(3, 0);
analogWrite(4, 255);
analogWrite(5, 0);
delay(100);
STOP();
}
// Deteccion de obstaculos ***************
void DetectarObstaculo(){
servoSonar.write(0);
delay(500);
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
if (Distancia_Frontal <= 30){
Obstaculo[0]='1';
} else {
Obstaculo[0]='0';
}
servoSonar.write(90);
delay(500);
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
if (Distancia_Frontal <= 20){
Obstaculo[1]='1';
} else {
Obstaculo[1]='0';
}
servoSonar.write(180);
delay(500);
Sonar(Trig_Frontal, Echo_Frontal);
Distancia_Frontal = Distancia;
if (Distancia_Frontal <= 30){
Obstaculo[2]='1';
} else {
Obstaculo[2]='0';
}
servoSonar.write(90);
}