Robot con pinzas e infrarrojos

Durante el pasado curso escolar pusimos en marcha un robot dotado de pinzas y controlado con Arduino UNO y una Shield Imagina Arduino.

Programa para el robot con pinzas y bluetooth

#include <Servo.h>

Servo mano;

Servo pinza;

void setup(){

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

pinMode(12,OUTPUT);

pinMode(13,OUTPUT);

pinza.attach(6);

mano.attach(5);

Serial.begin(9600);

}

void loop(){

char dato = Serial.read();

//Mover hacia adelante

if(dato == 'U'){

//Rueda derecha

digitalWrite(7,HIGH);

digitalWrite(8,LOW);

//Rueda izquierda

digitalWrite(12,LOW);

digitalWrite(13,HIGH);

}

//Mover hacia atras

if(dato == 'D'){

//Rueda derecha

digitalWrite(7,LOW);

digitalWrite(8,HIGH);

//Rueda izquierda

digitalWrite(12,HIGH);

digitalWrite(13,LOW);

}

//Girar a la derecha

if(dato == 'R'){

//Rueda derecha

digitalWrite(7,LOW);

digitalWrite(8,HIGH);

//Rueda izquierda

digitalWrite(12,LOW);

digitalWrite(13,HIGH);

}

//Girar a la izquierda

if(dato == 'L'){

//Rueda derecha

digitalWrite(7,HIGH);

digitalWrite(8,LOW);

//Rueda izquierda

digitalWrite(12,HIGH);

digitalWrite(13,LOW);

}

//Parar las dos ruedas

if(dato == 'C'){

//Rueda derecha

digitalWrite(7,LOW);

digitalWrite(8,LOW);

//Rueda izquierda

digitalWrite(12,LOW);

digitalWrite(13,LOW);

}

//Abrir la pinza

if(dato == 'a'){

pinza.write(10);

}

//Cerrar la pinza

if(dato == 'b'){

pinza.write(180);

}

//Girar la mano vertical

if(dato == 'c'){

mano.write(0);

}

//Girar la mano horizontal

if(dato == 'd'){

mano.write(90);

}

}

Programa para el robot con pinzas y mando de infrarrojos

la librería <IRremote.h> es incompatible con la librería <Servo.h>, por lo que no utilizaremos esta última.

#include <IRremote.h>

IRrecv receptorinfra(11); //Se crea un receptor de infrarrojos de nombre "receptorinfra", conectado al pin 11

decode_results valor; //En la variable "valor" se guardan los valores enviados por el mando a distancia

int tecla; //En esta variable se guardan los valores asignados a cada tecla del mando a distancia

void setup()

{

Serial.begin(9600);

receptorinfra.enableIRIn(); // Se reinicia el receptor de infrarojos

pinMode(5,OUTPUT);

pinMode(6,OUTPUT);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

pinMode(12,OUTPUT);

pinMode(13,OUTPUT);

}

void loop() {

if (receptorinfra.decode(&valor)) { //Si se recibe algun dato del mando a distancia

tecla=valor.value;

Serial.println(tecla);

if (tecla==752){ // Código de la tecla fleha adelante Mover hacia adelante

digitalWrite(7,HIGH);//Rueda derecha

digitalWrite(8,LOW);

digitalWrite(12,LOW); //Rueda izquierda

digitalWrite(13,HIGH);

}

if (tecla==2800){ // Código de la tecla flecha atras Mover hacia atras

digitalWrite(7,LOW);//Rueda derecha

digitalWrite(8,HIGH);

digitalWrite(12,HIGH);//Rueda izquierda

digitalWrite(13,LOW);

}

if (tecla==720){ // Código de la tecla flecha izquierda Mover hacia la izquierda

digitalWrite(7,HIGH);//Rueda derecha

digitalWrite(8,LOW);

digitalWrite(12,HIGH);//Rueda izquierda

digitalWrite(13,LOW);

}

if (tecla==3280){ // Código de la tecla flecha derecha Mover hacia la derecha

digitalWrite(7,LOW);//Rueda derecha

digitalWrite(8,HIGH);

digitalWrite(12,LOW);//Rueda izquierda

digitalWrite(13,HIGH);

}

if (tecla==2672){ // Código de la tecla aceptar (Centro de las flechas) Parar las ruedas

digitalWrite(7,LOW);//Rueda derecha

digitalWrite(8,LOW);

digitalWrite(12,LOW);//Rueda izquierda

digitalWrite(13,LOW);

}

if (tecla==144){ // Código de la tecla subir canal (Girar muneca)

int lenMicroSecondsOfPeriod = 25 * 1000; // 25 milliseconds (ms)

int lenMicroSecondsOfPulse = 1 * 1000; // 1 ms is 0 degrees

int first = 0.7 * 1000; //0.5ms is 0 degrees in HS-422 servo (0.7)

int end = 0.71 * 1000;//3.7

int increment = 0.01 * 1000;

int current = 0;

for(current = first; current <end; current+=increment){

// Servos work by sending a 25 ms pulse.

// 0.7 ms at the start of the pulse will turn the servo to the 0 degree position

// 2.2 ms at the start of the pulse will turn the servo to the 90 degree position

// 3.7 ms at the start of the pulse will turn the servo to the 180 degree position

// Turn voltage high to start the period and pulse

digitalWrite(5, HIGH);

// Delay for the length of the pulse

delayMicroseconds(current);

// Turn the voltage low for the remainder of the pulse

digitalWrite(5, LOW);

// Delay this loop for the remainder of the period so we don't

// send the next signal too soon or too late

delayMicroseconds(lenMicroSecondsOfPeriod - current);

}

}

if (tecla==2192){ // Código de la tecla bajar canal (Girar muneca)

int lenMicroSecondsOfPeriod = 25 * 1000; // 25 milliseconds (ms)

int lenMicroSecondsOfPulse = 1 * 1000; // 1 ms is 0 degrees

int first = 1.7 * 1000; //0.5ms is 0 degrees in HS-422 servo (0.7)

int end = 1.71 * 1000;//3.7

int increment = 0.01 * 1000;

int current = 0;

for(current = first; current <end; current+=increment){

// Servos work by sending a 25 ms pulse.

// 0.7 ms at the start of the pulse will turn the servo to the 0 degree position

// 2.2 ms at the start of the pulse will turn the servo to the 90 degree position

// 3.7 ms at the start of the pulse will turn the servo to the 180 degree position

// Turn voltage high to start the period and pulse

digitalWrite(5, HIGH);

// Delay for the length of the pulse

delayMicroseconds(current);

// Turn the voltage low for the remainder of the pulse

digitalWrite(5, LOW);

// Delay this loop for the remainder of the period so we don't

// send the next signal too soon or too late

delayMicroseconds(lenMicroSecondsOfPeriod - current);

}

}

if (tecla==1168){ // Código de la tecla subir volumen Abrir pinza

int lenMicroSecondsOfPeriod = 25 * 1000; // 25 milliseconds (ms)

int lenMicroSecondsOfPulse = 1 * 1000; // 1 ms is 0 degrees

int first = 0.7 * 1000; //0.5ms is 0 degrees in HS-422 servo (0.7)

int end = 0.71 * 1000;//3.7

int increment = 0.01 * 1000;

int current = 0;

for(current = end; current >first; current-=increment){

// Servos work by sending a 20 ms pulse.

// 0.7 ms at the start of the pulse will turn the servo to the 0 degree position

// 2.2 ms at the start of the pulse will turn the servo to the 90 degree position

// 3.7 ms at the start of the pulse will turn the servo to the 180 degree position

// Turn voltage high to start the period and pulse

digitalWrite(6, HIGH);

// Delay for the length of the pulse

delayMicroseconds(current);

// Turn the voltage low for the remainder of the pulse

digitalWrite(6, LOW);

// Delay this loop for the remainder of the period so we don't

// send the next signal too soon or too late

delayMicroseconds(lenMicroSecondsOfPeriod - current);

}

}

if (tecla==3216){ // Código de la tecla bajar volumen Cerrar pinza

int lenMicroSecondsOfPeriod = 25 * 1000; // 25 milliseconds (ms)

int lenMicroSecondsOfPulse = 1 * 1000; // 1 ms is 0 degrees

int first = 1.7 * 1000; //0.5ms is 0 degrees in HS-422 servo (0.7)

int end = 1.71 * 1000;//3.7

int increment = 0.01 * 1000;

int current = 0;

for(current = end; current >first; current-=increment){

// Servos work by sending a 20 ms pulse.

// 0.7 ms at the start of the pulse will turn the servo to the 0 degree position

// 2.2 ms at the start of the pulse will turn the servo to the 90 degree position

// 3.7 ms at the start of the pulse will turn the servo to the 180 degree position

// Turn voltage high to start the period and pulse

digitalWrite(6, HIGH);

// Delay for the length of the pulse

delayMicroseconds(current);

// Turn the voltage low for the remainder of the pulse

digitalWrite(6, LOW);

// Delay this loop for the remainder of the period so we don't

// send the next signal too soon or too late

delayMicroseconds(lenMicroSecondsOfPeriod - current);

}

}

receptorinfra.resume(); // Recibe el siguiente valor

}

delay(100); //Espera 100 milisegundos

}

A continuación se pueden ver otras imágenes del vehículo.

La plataforma inicial era esta.