Paso 48: Añadido MoveHead() para el resto del código de serie de la prueba
Creo que tenemos suficientes movimientos para empezar a trabajar en otra cosa.comandos serie añadidos:
'h' - a mover la cabeza - corre a través de barrido completo
de '-girar una forma (función ya estaba allí, pero no tenía un caso)
había '-spin al revés (función ya estaba allí, pero no tenía un caso)
Este código se hagan más corto, pero aquí está:
video
[allMoves
//////////////////////////////// ARDUINO CODE//////////////////////////////////
Robot de prueba con rutinas poco en funciones / /
añadido cabeza móvil / / /
motor VARIABLES / / /
Dirección baja hacia el cuerpo o delante
Dirección = alto del cuerpo o al revés
int RightArmDir = 2;
int RightArmSpeed = 3;
int LeftArmDir = 4;
int LeftArmSpeed = 5;
int WaistDir = 7;
int WaistSpeed = 6;
int RightWheelDir = 8;
int RightWheelSpeed = 9;
int LeftWheelDir = 12;
int LeftWheelSpeed = 10;
int lenta = 100;
int rápido = 200;
int t1 = 200; tiempo en baja velocidad
int t2 = 1000; tiempo en velocidad rápida
tBreak int = 100; tiempo para detener el motor mediante la inversión de dir
int WheelSpeed = 75;
breakSpeed int = 10;
int bendSpeed = 255;
int incomingByte;
variables principales
#include < Servo.h >
Servo myservo; crear objeto servo para controlar un servo
int pos = 80;
int posFront = 80;
///////// SETUP /////////
void setup() {}
pinMode (RightArmDir, salida);
pinMode (RightArmSpeed, salida);
pinMode (LeftArmDir, salida);
pinMode (LeftArmSpeed, salida);
pinMode (WaistDir, salida);
pinMode (WaistSpeed, salida);
pinMode (RightWheelDir, salida);
pinMode (RightWheelSpeed, salida);
pinMode (LeftWheelDir, salida);
pinMode (LeftWheelSpeed, salida);
myservo.Attach(11); se fija el servo en el pin 11 al objeto servo
Serial.Begin(9600);
}
PRINCIPAL LAZO / / /
void loop() {}
Serial.println("...");
Delay(400);
if(serial.Available() > 0) {}
incomingByte = Serial.read();
{Switch(incomingByte)}
caso 'f':
Foward();
rotura;
caso 'b':
Backward();
rotura;
caso 'r':
RightArmUp();
rotura;
caso ' t ':
RightArmDown();
rotura;
caso 'w':
LeftArmUp();
rotura;
caso 'e':
LeftArmDown();
rotura;
caso 'z':
WaistBendDown();
rotura;
caso 'x':
WaistBendUp();
rotura;
caso 'h':
MoveHead();
rotura;
de caso ':
Spin();
rotura;
caso sería ':
Spin2();
rotura;
}
}
}
///////////////////////////////////////////////
FUNCIONES BÁSICAS / / /
///////////////////////////////////////////////
void RightArmUp() {}
Brazo derecho de prueba
Serial.println ("brazo derecho");
Brazo derecho hacia arriba
Serial.println("up");
digitalWrite (RightArmDir, alto);
analogWrite (RightArmSpeed, lento);
retardo (t1);
analogWrite(RightArmSpeed,Fast);
retardo (1.8 * t2);
analogWrite(RightArmSpeed,Slow);
Delay(T1);
analogWrite (RightArmSpeed, 0);
Delay(T1);
}
void RightArmDown() {}
Brazo derecho abajo
Serial.println "(brazo derecho del abajo");
digitalWrite (RightArmDir, bajo);
analogWrite (RightArmSpeed, lento);
retardo (t1);
analogWrite (RightArmSpeed, rápido);
retardo (1.8 * t2);
analogWrite (RightArmSpeed, lento);
Delay(T1);
analogWrite (RightArmSpeed, 0);
Delay(2*T1);
}
void LeftArmUp() {}
Prueba de brazo izquierdo
Serial.println ("izquierdo-brazo");
Brazo izquierdo arriba
digitalWrite (LeftArmDir, alto);
analogWrite (LeftArmSpeed, lento);
retardo (t1);
analogWrite (LeftArmSpeed, rápido);
demora (2 * t2);
analogWrite (LeftArmSpeed, lento);
retardo (t1);
analogWrite (LeftArmSpeed, 0);
Delay(T1);
}
void LeftArmDown() {}
Brazo izquierdo hacia abajo
Serial.println "(brazo izquierdo del abajo");
digitalWrite (LeftArmDir, bajo);
analogWrite (LeftArmSpeed, lento);
retardo (t1);
analogWrite (LeftArmSpeed, rápido);
demora (2 * t2);
analogWrite(LeftArmSpeed,Slow);
Delay(T1);
analogWrite (LeftArmSpeed, 0);
Delay(2*T1);
}
void WaistBendDown() {}
Cintura de prueba
Serial.println ("cintura curva hacia abajo");
digitalWrite (WaistDir, alto);
analogWrite (WaistSpeed, lento);
retardo (t1);
analogWrite (WaistSpeed, bendSpeed);
demora (2 * t2);
analogWrite (WaistSpeed, lento);
Delay(T1);
analogWrite (WaistSpeed, 0);
Delay(T1);
}
void WaistBendUp() {}
Doble hacia arriba
Serial.println("up");
digitalWrite (WaistDir, bajo);
analogWrite (WaistSpeed, lento);
retardo (t1);
analogWrite (WaistSpeed, bendSpeed);
demora (2 * t2);
analogWrite (WaistSpeed, lento);
Delay(T1);
analogWrite (WaistSpeed, 0);
Delay(2*T1);
}
void Spin() {}
Serial.println("Spin");
digitalWrite (LeftWheelDir, bajo);
digitalWrite(RightWheelDir,HIGH);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
retardo (t1);
analogWrite (RightWheelSpeed, WheelSpeed);
analogWrite (LeftWheelSpeed, WheelSpeed);
retardo (t2);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
Delay(T1);
analogWrite (LeftWheelSpeed, 0);
analogWrite (RightWheelSpeed, 0);
Delay(T1);
digitalWrite (LeftWheelDir, alto);
digitalWrite(RightWheelDir,LOW);
analogWrite (LeftWheelSpeed, breakSpeed);
analogWrite (RightWheelSpeed, breakSpeed);
Delay(tBreak);
analogWrite (LeftWheelSpeed, 0);
analogWrite(RightWheelSpeed,0);
}
void Spin2() {}
Serial.println("SPIN2");
digitalWrite (LeftWheelDir, alto);
digitalWrite(RightWheelDir,LOW);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
retardo (t1);
analogWrite (RightWheelSpeed, WheelSpeed);
analogWrite (LeftWheelSpeed, WheelSpeed);
retardo (t2);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
Delay(T1);
analogWrite (LeftWheelSpeed, 0);
analogWrite (RightWheelSpeed, 0);
Delay(T1);
digitalWrite (LeftWheelDir, bajo);
digitalWrite(RightWheelDir,HIGH);
analogWrite (LeftWheelSpeed, breakSpeed);
analogWrite(RightWheelSpeed,breakSpeed);
Delay(tBreak);
analogWrite (LeftWheelSpeed, 0);
analogWrite(RightWheelSpeed,0);
}
void Foward() {}
Serial.println ("ir delante");
digitalWrite (LeftWheelDir, alto);
digitalWrite(RightWheelDir,HIGH);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
retardo (t1);
analogWrite (RightWheelSpeed, WheelSpeed);
analogWrite (LeftWheelSpeed, WheelSpeed);
retardo (t2);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
Delay(T1);
analogWrite (LeftWheelSpeed, 0);
analogWrite (RightWheelSpeed, 0);
Delay(T1);
digitalWrite (LeftWheelDir, bajo);
digitalWrite(RightWheelDir,LOW);
analogWrite (LeftWheelSpeed, breakSpeed);
analogWrite(RightWheelSpeed,breakSpeed);
Delay(tBreak);
analogWrite (LeftWheelSpeed, 0);
analogWrite(RightWheelSpeed,0);
}
void Backward() {}
Serial.println ("ir hacia atrás");
digitalWrite (LeftWheelDir, bajo);
digitalWrite(RightWheelDir,LOW);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
retardo (t1);
analogWrite (RightWheelSpeed, WheelSpeed);
analogWrite (LeftWheelSpeed, WheelSpeed);
retardo (t2);
analogWrite (RightWheelSpeed, WheelSpeed/2);
analogWrite (LeftWheelSpeed, WheelSpeed/2);
Delay(T1);
analogWrite (LeftWheelSpeed, 0);
analogWrite (RightWheelSpeed, 0);
Delay(T1);
digitalWrite (LeftWheelDir, alto);
digitalWrite(RightWheelDir,HIGH);
analogWrite (LeftWheelSpeed, breakSpeed);
analogWrite(RightWheelSpeed,breakSpeed);
Delay(tBreak);
analogWrite (LeftWheelSpeed, 0);
analogWrite(RightWheelSpeed,0);
}
mover cabeza / / /
void MoveHead() {//create función mover cabeza / cabeza van hacia adelante y hacia atrás
para (pos = 5; pos < 145; pos += 1) //goes de 5 a 145degrees
{/ / en pasos de 1 grado
myservo.Write(POS); Dile el servo a la posición en la variable 'pos'
Serial.println(POS);
Delay(15); espera 15ms para el servo a la posición
if(pos == posFront) {}
Delay(600);
}
}
para (pos = 145; pos > = posFront; pos-= 1) / / va de 145 grados al frente
{
myservo.Write(POS); Dile el servo a la posición en la variable 'pos'
Delay(15); espera 15ms para el servo a la posición
if(pos == posFront) {}
Delay(600);
}
}
}