Download \dev\pwner - Plotter Lego
Document related concepts
no text concepts found
Transcript
\dev\pwner Grupo 11 Introducción Hardware \dev\pwner Plotter Lego Felipe Contreras Salinas Felipe Muñoz Hernández René Tapia Pincheira 24 de mayo de 2011 Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Objetivos \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Objetivos \dev\pwner Grupo 11 Introducción Hardware Software I Construir un robot que sea capaz de imprimir (dibujar/pintar). Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Objetivos \dev\pwner Grupo 11 Introducción Hardware Software I Construir un robot que sea capaz de imprimir (dibujar/pintar). I Escribir software para procesar imágenes. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Objetivos \dev\pwner Grupo 11 Introducción Hardware Software I Construir un robot que sea capaz de imprimir (dibujar/pintar). I Escribir software para procesar imágenes. I Comunicar el robot con el PC para transmitir imágenes pre-procesadas. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Grupo 11 Introducción Hardware La idea básica del robot es la siguiente: Software Brick USB/Bluetooth PC Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Display Sensor Motor Webcam Hardware \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Hardware \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Hardware \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Software Grupo 11 Introducción Inicia robot Inicia GUI Hardware Software Datos por defecto Interacción con el usuario Previsualización de impresión Recupera puntos de procesamiento Construye cola de mensajes 1 Inicia conección hacia el robot Procesar imagen 1 Espera conección entrante Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Pide un mensaje Problemas Envía siguiente mensaje ¿Recibe EOM? Sí ¿Quedan instrucciones? No Espera petición No Envía fin de mensajes (EOM) Ejecuta el mensaje Pide mas mensajes Por hacer Sí 1 2 /*Clase Sendable*/ package communications; \dev\pwner Grupo 11 3 4 5 6 import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; 7 8 9 10 11 12 13 14 15 16 17 18 19 public abstract class Sendable { public int getType() {} public static Sendable readSendable (DataInputStream dis) throws IOException {} public static void writeSendable (DataOutputStream dos, Sendable sen) throws IOException {} public abstract Object writeTo (DataOutputStream dos) throws IOException; public abstract Object readFrom (DataInputStream dis) throws IOException; } Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer 1 2 3 4 5 6 7 public int getType() { if (this instanceof Segment) return 0; if (this instanceof Config) return 1; return -1; } 8 9 10 11 12 13 14 15 16 17 18 public static Sendable readSendable (DataInputStream dis) throws IOException { int kind = dis.readInt(); if (kind == 0) return new Segment().readFrom(dis); if (kind == 1) return new Config().readFrom(dis); throw new IOException( "read unrecognized sendable" ); } \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Grupo 11 1 2 3 4 5 6 7 8 9 10 11 12 13 public static void writeSendable (DataOutputStream dos, Sendable sen) throws IOException { int kind = sen.getType(); if (kind >= 0) { dos.writeInt(kind); sen.writeTo(dos); dos.flush(); } else { throw new IOException( "write unrecognized sendable" ); } } Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner 1 2 /*Clase Actuator*/ package robot; 5 import lejos.nxt.*; import communications.*; 6 7 8 9 10 public class Actuator { /*variables NXT*/ /*variables de calibracion*/ /*variables del programa*/ 11 12 13 14 15 Introducción Hardware 3 4 Grupo 11 public Actuator() { /*aplica las variables de calibracion al robot*/ } Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Grupo 11 Introducción 1 2 3 4 5 6 public boolean process(Sendable sendable) throws Exception { if (sendable instanceof Segment) return processSegment((Segment) sendable); else if (sendable instanceof Config) return processConfig((Config) sendable); Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas 7 throw new Exception( "Sendable not recognized" ); 8 9 10 Hardware } Por hacer \dev\pwner Grupo 11 Introducción Hardware 1 2 3 4 5 6 7 8 9 private boolean processSegment (Segment segment) { setPencil(-1); gotoPosition(segment.getP1()); setPencil(+1); gotoPosition(segment.getP2()); setPencil(-1); return true; } Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Grupo 11 1 2 3 4 5 6 7 8 9 10 11 12 13 14 private boolean processConfig (Config config) { if (config.calibrate) calibrate(); if (config.resetPosition) resetPosition(); if (config.waitMaintenanceButton) waitMaintenanceButton(); if (config.gotoPosition) gotoPosition(config.position); if (config.kill) return false; return true; } Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer 1 2 3 4 5 6 7 8 9 private void stepX(int dir, int units) { int total = dir * units; int ncurrent = currentX + total; if (ncurrent>=0 && ncurrent<=maxWidth) { currentX = ncurrent; rail.rotate((int) (dir * units * degreesPerStepX * scaleX)); } } 10 11 12 13 14 15 16 17 18 19 \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas private void stepY(int dir, int units) { int total = dir * units; int ncurrent = currentY + total; if (ncurrent>=0 && ncurrent<=maxHeight) { currentY = ncurrent; chasis.rotate((int) (dir * units * degreesPerStepY * scaleY)); } } Por hacer \dev\pwner private void setPencil(int state) { if (state < 0) { pencil.rotateTo(upDegree); pencil.stop(); pencil.lock(100); } else if (state == 0) { pencil.stop(); pencil.flt(); } else { pencil.rotateTo(downDegree); pencil.stop(); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /*El resto de las funciones*/ 15 16 } Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Interfaz gráfica \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Procesamiento de imágenes \dev\pwner Grupo 11 1 2 3 4 5 6 7 8 9 /*Ejemplo OpenCV*/ #include <cv.h> #include <highgui.h> using namespace cv; int main(){ Mat img = imread( "foto.jpg" ,0), final; GaussianBlur(img,final,Size(5,5),0); Canny(final,final,20,40); bitwise_not(final,final); 10 imshow( "imagen" , imagen); imshow( "final" , final); waitKey(0); return 0; 11 12 13 14 15 } Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer \dev\pwner Grupo 11 Introducción Hardware Software Imagen original Desenfoque (GaussianBlur) Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Bordes detectados (Canny) Resultado (bitwise not) \dev\pwner Java Native Interface Grupo 11 Introducción Hardware Software Clase Java Código Java Foo.class Foo.java JVM Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Implementación nativa Código C++ bar.dll | libbar.so bar.cpp Comunicación PC/Robot \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Comunicación PC/Robot \dev\pwner Grupo 11 Introducción Hardware Software I La interfaz prepara una lista de Sendable (varios Segment y un Config al final). Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Comunicación PC/Robot \dev\pwner Grupo 11 Introducción Hardware Software I La interfaz prepara una lista de Sendable (varios Segment y un Config al final). I Mientras el robot pida Sendable, el PC envı́a el siguiente elemento de la cola. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Comunicación PC/Robot \dev\pwner Grupo 11 Introducción Hardware Software I La interfaz prepara una lista de Sendable (varios Segment y un Config al final). I Mientras el robot pida Sendable, el PC envı́a el siguiente elemento de la cola. I Luego de enviar todos los Segment del dibujo, envı́a un Config. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Comunicación PC/Robot \dev\pwner Grupo 11 Introducción Hardware Software I La interfaz prepara una lista de Sendable (varios Segment y un Config al final). I Mientras el robot pida Sendable, el PC envı́a el siguiente elemento de la cola. I Luego de enviar todos los Segment del dibujo, envı́a un Config. I La interfaz muestra el progreso actual de la impresión. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Comunicación PC/Robot \dev\pwner Grupo 11 Introducción Hardware Software I La interfaz prepara una lista de Sendable (varios Segment y un Config al final). I Mientras el robot pida Sendable, el PC envı́a el siguiente elemento de la cola. I Luego de enviar todos los Segment del dibujo, envı́a un Config. I La interfaz muestra el progreso actual de la impresión. I Luego de enviar la imagen completamente (toda la cola) se cierra la conexión. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Problemas \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Problemas \dev\pwner Grupo 11 Introducción Hardware Software I El agarre del lápiz no es muy firme. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Problemas \dev\pwner Grupo 11 Introducción Hardware Software I El agarre del lápiz no es muy firme. I A veces se desarma la estructura. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Por hacer \dev\pwner Grupo 11 Introducción Hardware Software Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Por hacer \dev\pwner Grupo 11 Introducción Hardware Software I Ajustar los parámetros para que el robot dibuje de verdad. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Por hacer \dev\pwner Grupo 11 Introducción Hardware Software I Ajustar los parámetros para que el robot dibuje de verdad. I Cambiar el mecanismo de agarre del lápiz. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Por hacer \dev\pwner Grupo 11 Introducción Hardware Software I Ajustar los parámetros para que el robot dibuje de verdad. I Cambiar el mecanismo de agarre del lápiz. I Reformular el algoritmo para obtener lı́neas a partir de la imagen original. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer Por hacer \dev\pwner Grupo 11 Introducción Hardware Software I Ajustar los parámetros para que el robot dibuje de verdad. I Cambiar el mecanismo de agarre del lápiz. I Reformular el algoritmo para obtener lı́neas a partir de la imagen original. I Hacer la estructura del robot más firme. Software del Robot Clase Sendable Clase Actuator Interfaz gráfica Procesamiento de Imágenes Java Native Interface Comunicación PC/Robot Problemas Por hacer