You are here

Things used in this project

Hardware components:
Psoc 20analog 20coprocessor 20pioneer 20kit 20web
Cypress PSoC Analog Coprocessor Pioneer Kit
×1
11028 01
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
×1
Software apps and online services:
Creator bannerimage 2
Cypress PSoC Creator

Custom parts and enclosures

esquematico_mpu6050_7x20vIeFNr.jpg
{1} http://www.nextiafenix.com/wp-content/uploads/2014/06/esquematico.jpg
{2} https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/
Esquematico mpu6050 7x20viefnr

Schematics

Diagram of connection of the Mpu6050 sensors and PSOC.
The connection diagram shows the connection between the PSOC ANALOG COPROCESSOR CY8CKIT-048 and the IMU MPU-6050 sensors for calculating the flexion and extension angles of a joint with the use of pitch, yaw and roll navigation angles.
Final oqtpzmxptt
Physical mounting of digital gonniometer
Design of the digital goniometer using elastic tape, plastic boxes and linings for the sensors.
20170219 170628 cqepp91jsb

Code

GUI Java
This is the graphical user interface of the goniometer project.
import gnu.io.CommPortIdentifier     ; 
import gnu.io.SerialPort             ;
import gnu.io.SerialPortEvent        ;
import gnu.io.SerialPortEventListener;
import java.io.IOException           ;
import java.io.InputStream           ;
import java.io.OutputStream          ;
import java.util.Enumeration         ;
import javax.swing.Timer;

public class GONIOMETRO extends javax.swing.JFrame implements SerialPortEventListener {

Timer    Reloj;
int      contador=0;
int      valor = 0; 
//
private OutputStream Output = null;
private InputStream  Input  = null;
SerialPort serialPort;
private final String     PORT_NAME =     "COM3";
private static final int TIME_OUT  =      2000 ;//2000
private static final int DATA_RATE =      9600 ;
  
String Mensaje     = "";    
int    DatoEntrada, entragrafica, maxi, mini; 
String entrada;
    
//VALORES Y VARIALES PARA EL LIENZO 
pintar  lienzo;  

int ptXi  = 10, ptXf=10, ptYi=((DatoEntrada*-1)+190),ptYf=((DatoEntrada*-1)+190);
int Boton = 0, barra;  

boolean estado = false;
                   
public GONIOMETRO() {
   
    initComponents();
    ArduinoConnection();
        
     boton2.setVisible(false);
    MAX.setVisible(false);       MIN.setVisible(false);
      title2.setVisible(false); 
    title3.setVisible(false);   title4.setVisible(false);
    title5.setVisible(false);   title6.setVisible(false);
    
    box1.setVisible(false);   box2.setVisible(false);  
    box3.setVisible(false);   box4.setVisible(false);
    
    BORRAR.setVisible(false); area1.setVisible(false);    
    jScrollPane1.setVisible(false);
       
    subtitle1.setVisible(false);
    subtitle2.setVisible(false);
    tiempo.setVisible(false);
    INPUTUSB.setVisible(false);
    
        
    lienzo = new pintar(this);         
    lienzo.setBackground(new java.awt.Color(0,0,0));      
    getContentPane() .add(lienzo);   
    lienzo.setVisible(false);
    lienzo.setBounds(40,50,620,380); 
        
    degrees(); 
    
    Reloj = new Timer(100, new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                evento_tempo(evt);
            }
        });                           
 
         
} 

    public void evento_tempo (java.awt.event.ActionEvent evt){
        
        contador++;
        
       this.tiempo.setText("" + contador);
     
    }

   public void degrees(){
   
  A180.setVisible(estado);     A_180.setVisible(estado);
  A170.setVisible(estado);     A_170.setVisible(estado);
  A160.setVisible(estado);     A_160.setVisible(estado);
  A150.setVisible(estado);     A_150.setVisible(estado);
  A140.setVisible(estado);     A_140.setVisible(estado);
  A130.setVisible(estado);     A_130.setVisible(estado);
  A120.setVisible(estado);     A_120.setVisible(estado);
  A110.setVisible(estado);     A_110.setVisible(estado);
  A100.setVisible(estado);     A_100.setVisible(estado);
  A90 .setVisible(estado);     A_90 .setVisible(estado);
  A80 .setVisible(estado);     A_80 .setVisible(estado);
  A70 .setVisible(estado);     A_70 .setVisible(estado); 
  A60 .setVisible(estado);     A_60 .setVisible(estado);
  A50 .setVisible(estado);     A_50 .setVisible(estado);
  A40 .setVisible(estado);     A_40 .setVisible(estado);
  A30 .setVisible(estado);     A_30 .setVisible(estado);
  A20 .setVisible(estado);     A_20 .setVisible(estado);
  A10 .setVisible(estado);     A_10 .setVisible(estado);
  A0  .setVisible(estado);  
  
   }

    public synchronized void serialEvent(SerialPortEvent oEvent) {
       
        while (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {

            try {
                 int datos;                  //Se declaran las variables                   
                 datos = RecibirDatos(); //Se lee los datos en el puerto serie

                if (datos > 0) { //Si el valor leido es mayor a 0...
                    Mensaje = Mensaje + (char) datos; //Se acumula el mensaje

                    if (Mensaje.charAt(Mensaje.length() - 1) == ',') { //Cuando se recibe la coma
                        //el mensaje ha llegado a su final, por lo que se procede a imprimir
                        //La parte ENTERA. Se busca el punto, donde quiera que esté
                        //y se transforma de String a entero
                        for (int i = 0; i <= Mensaje.length() - 1; i++) {
                            
                            if (Mensaje.charAt(i) == '.') {
                               
                                DatoEntrada = Integer.parseInt(Mensaje.substring(0, i));
                                entrada = String.valueOf(DatoEntrada);
                                INPUTUSB.setText(entrada+"°");
                                area1.setText(area1.getText()+"Angulo: "+entrada+"°"+"  TIEMPO: "+contador+'\n');
                                
        
        
        if(maxi>DatoEntrada){
        this.MAX.setText("VALOR MAXIMO: "+String.valueOf(maxi)+"°");
        }  
        else if (maxi<DatoEntrada){
        maxi= DatoEntrada;
        this.MAX.setText("VALOR MAXIMO: "+String.valueOf(maxi)+"°");
        }
        else if (maxi==DatoEntrada){
        this.MAX.setText("VALOR MAXIMO: "+String.valueOf(maxi)+"°");
        }
        
                if(mini<DatoEntrada){
        this.MIN.setText("VALOR MINIMO: "+String.valueOf(mini)+"°");
        }  
        else if (mini>DatoEntrada){
        mini = DatoEntrada;
        this.MIN.setText("VALOR MINIMO: "+String.valueOf(mini)+"°");
        }
        else if (mini==DatoEntrada){
        this.MIN.setText("VALOR MINIMO: "+String.valueOf(mini)+"°");
        }
        
        
        
                                           ptXf++;
       if ((ptXf>=10)&&(ptXf<=610)){
       ptYf= -1*DatoEntrada+190;     
       lienzo.valores(ptXi, ptYi,ptXf,ptYf);
       lienzo.repaint();}
       ptXi=ptXf;
       ptYi=ptYf;
       //lienzo.repaint();
       if(ptXf>610){
       ptXf=10;
       ptXi=10;
       lienzo.valores(ptXi, ptYi,ptXf,ptYf);
       lienzo.repaint();
 
       }
    
        
//******************************************************************************
      
   

                                
                                Mensaje = ""; //Se limpia la variable y se prepara para nueva lectura
                                
                                
                            }
                        }
                    }
                }
            } 
            catch (Exception e) {System.err.println(e.toString());}
        }
    }//END serialEvent
        
    public void ArduinoConnection() {

    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

    while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();

        if (PORT_NAME.equals(currPortId.getName())) {
                portId = currPortId;
                break;
        }
                                        }

    if (portId == null) {
        System.exit(ERROR);
        return;         
    }

    try {

        serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);

        serialPort.setSerialPortParams(DATA_RATE,
                   SerialPort.DATABITS_8,
                   SerialPort.STOPBITS_1,
                   SerialPort.PARITY_NONE);

            Output = serialPort.getOutputStream();
            Input  = serialPort.getInputStream ();

            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        }
    
    catch (Exception e) {
            System.exit(ERROR);
        }

    }
    private int RecibirDatos() throws IOException {
           int Output = 0;
               Output = Input.read();
        return Output;
    }

    private void EnviarDatos(String data) {

        try { Output.write(data.getBytes());} 
        
        catch (IOException e) {System.exit(ERROR);}
    }
     /*   if (   Boton == 0){ 
           Boton =  1; 
          
          
           this.boton3.setText("PARAR");
           area1.setText("NOMBRE:      "+box1.getText()+'\n'+'\n'+"APELLIDOS: "+box2.getText()+'\n'+'\n'+"EDAD:            "+box3.getText()+'\n'+'\n'+"GENERO:      "+box4.getText()+'\n'+'\n'+"ÁNGULOS:"+'\n'+'\n');
           EnviarDatos("b");//Se rehabilita a Arduino para el envío de datos       
            
    }
    
    else{  Boton = 0; 
           
           this.boton3.setText("INICIAR");
           EnviarDatos("c");//Se deshabilita a Arduino para que no envíe datos          
    }*/

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        A180 = new javax.swing.JLabel();
        A170 = new javax.swing.JLabel();
        A160 = new javax.swing.JLabel();
        A150 = new javax.swing.JLabel();
        A140 = new javax.swing.JLabel();
        A130 = new javax.swing.JLabel();
        A120 = new javax.swing.JLabel();
        A110 = new javax.swing.JLabel();
        A100 = new javax.swing.JLabel();
        A90 = new javax.swing.JLabel();
        A80 = new javax.swing.JLabel();
        A70 = new javax.swing.JLabel();
        A60 = new javax.swing.JLabel();
        A50 = new javax.swing.JLabel();
        A40 = new javax.swing.JLabel();
        A30 = new javax.swing.JLabel();
        A20 = new javax.swing.JLabel();
        A10 = new javax.swing.JLabel();
        A0 = new javax.swing.JLabel();
        A_10 = new javax.swing.JLabel();
        A_20 = new javax.swing.JLabel();
        A_30 = new javax.swing.JLabel();
        A_40 = new javax.swing.JLabel();
        A_50 = new javax.swing.JLabel();
        A_60 = new javax.swing.JLabel();
        A_70 = new javax.swing.JLabel();
        A_80 = new javax.swing.JLabel();
        A_90 = new javax.swing.JLabel();
        A_100 = new javax.swing.JLabel();
        A_110 = new javax.swing.JLabel();
        A_120 = new javax.swing.JLabel();
        A_130 = new javax.swing.JLabel();
        A_140 = new javax.swing.JLabel();
        A_150 = new javax.swing.JLabel();
        A_160 = new javax.swing.JLabel();
        A_170 = new javax.swing.JLabel();
        A_180 = new javax.swing.JLabel();
        INPUTUSB = new javax.swing.JLabel();
        title1 = new javax.swing.JLabel();
        subtitle1 = new javax.swing.JLabel();
        title2 = new javax.swing.JLabel();
        title3 = new javax.swing.JLabel();
        title4 = new javax.swing.JLabel();
        title5 = new javax.swing.JLabel();
        title6 = new javax.swing.JLabel();
        box1 = new javax.swing.JTextField();
        box2 = new javax.swing.JTextField();
        box3 = new javax.swing.JTextField();
        box4 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        area1 = new javax.swing.JTextArea();
        boton1 = new javax.swing.JButton();
        tiempo = new javax.swing.JLabel();
        boton2 = new javax.swing.JButton();
        BORRAR = new javax.swing.JButton();
        MIN = new javax.swing.JLabel();
        MAX = new javax.swing.JLabel();
        area2 = new javax.swing.JTextArea();
        subtitle2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GONIÓMETRO DIGITAL PARA LA MEDICIÓN DE RANGOS ARTICULARES DE LOS MIEMBROS INFERIORES ");
        setBackground(new java.awt.Color(0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setIconImage(getIconImage());
        getContentPane().setLayout(null);

        A180.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A180.setText(" 180°");
        getContentPane().add(A180);
        A180.setBounds(0, 51, 35, 20);

        A170.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A170.setText(" 170°");
        getContentPane().add(A170);
        A170.setBounds(0, 61, 35, 20);

        A160.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A160.setText(" 160°");
        getContentPane().add(A160);
        A160.setBounds(0, 71, 35, 20);

        A150.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A150.setText(" 150°");
        getContentPane().add(A150);
        A150.setBounds(0, 81, 35, 20);

        A140.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A140.setText(" 140°");
        getContentPane().add(A140);
        A140.setBounds(0, 91, 35, 20);

        A130.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A130.setText(" 130°");
        getContentPane().add(A130);
        A130.setBounds(0, 101, 35, 20);

        A120.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A120.setText(" 120°");
        getContentPane().add(A120);
        A120.setBounds(0, 111, 35, 20);

        A110.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A110.setText(" 110°");
        getContentPane().add(A110);
        A110.setBounds(0, 121, 35, 20);

        A100.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A100.setText(" 100°");
        getContentPane().add(A100);
        A100.setBounds(0, 131, 35, 20);

        A90.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A90.setText(" 90°");
        getContentPane().add(A90);
        A90.setBounds(0, 141, 35, 20);

        A80.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A80.setText(" 80°");
        getContentPane().add(A80);
        A80.setBounds(0, 151, 35, 20);

        A70.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A70.setText(" 70°");
        getContentPane().add(A70);
        A70.setBounds(0, 161, 35, 20);

        A60.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A60.setText("60°");
        getContentPane().add(A60);
        A60.setBounds(0, 171, 35, 20);

        A50.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A50.setText(" 50°");
        getContentPane().add(A50);
        A50.setBounds(0, 181, 35, 20);

        A40.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A40.setText("40°");
        getContentPane().add(A40);
        A40.setBounds(0, 191, 35, 20);

        A30.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A30.setText("30°");
        getContentPane().add(A30);
        A30.setBounds(0, 201, 35, 20);

        A20.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A20.setText(" 20°");
        getContentPane().add(A20);
        A20.setBounds(0, 211, 35, 20);

        A10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A10.setText(" 10°");
        getContentPane().add(A10);
        A10.setBounds(0, 221, 35, 20);

        A0.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A0.setText("0°");
        getContentPane().add(A0);
        A0.setBounds(0, 231, 35, 20);

        A_10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_10.setText(" -10°");
        getContentPane().add(A_10);
        A_10.setBounds(0, 241, 35, 20);

        A_20.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_20.setText("-20°");
        getContentPane().add(A_20);
        A_20.setBounds(0, 251, 35, 20);

        A_30.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_30.setText(" -30°");
        getContentPane().add(A_30);
        A_30.setBounds(0, 261, 35, 20);

        A_40.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_40.setText("-40°");
        getContentPane().add(A_40);
        A_40.setBounds(0, 271, 35, 20);

        A_50.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_50.setText(" -50°");
        getContentPane().add(A_50);
        A_50.setBounds(0, 281, 35, 20);

        A_60.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_60.setText("-60°");
        getContentPane().add(A_60);
        A_60.setBounds(0, 291, 35, 20);

        A_70.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_70.setText(" -70°");
        getContentPane().add(A_70);
        A_70.setBounds(0, 301, 35, 20);

        A_80.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_80.setText("-80°");
        getContentPane().add(A_80);
        A_80.setBounds(0, 311, 35, 20);

        A_90.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_90.setText(" -90°");
        getContentPane().add(A_90);
        A_90.setBounds(0, 321, 35, 20);

        A_100.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_100.setText(" -100°");
        getContentPane().add(A_100);
        A_100.setBounds(0, 331, 35, 20);

        A_110.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_110.setText(" -110°");
        getContentPane().add(A_110);
        A_110.setBounds(0, 341, 35, 20);

        A_120.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_120.setText(" -120°");
        getContentPane().add(A_120);
        A_120.setBounds(0, 351, 35, 20);

        A_130.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_130.setText(" -130°");
        getContentPane().add(A_130);
        A_130.setBounds(0, 361, 35, 20);

        A_140.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_140.setText("-140°");
        getContentPane().add(A_140);
        A_140.setBounds(0, 371, 35, 20);

        A_150.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_150.setText(" -150°");
        getContentPane().add(A_150);
        A_150.setBounds(0, 381, 35, 20);

        A_160.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_160.setText("-160°");
        getContentPane().add(A_160);
        A_160.setBounds(0, 391, 35, 20);

        A_170.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_170.setText(" -170°");
        getContentPane().add(A_170);
        A_170.setBounds(0, 401, 35, 20);

        A_180.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        A_180.setText("-180°");
        getContentPane().add(A_180);
        A_180.setBounds(0, 411, 35, 20);

        INPUTUSB.setFont(new java.awt.Font("Century Gothic", 0, 24)); // NOI18N
        INPUTUSB.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        INPUTUSB.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        getContentPane().add(INPUTUSB);
        INPUTUSB.setBounds(450, 520, 90, 60);

        title1.setFont(new java.awt.Font("Georgia", 1, 11)); // NOI18N
        title1.setText("GONIÓMETRO DIGITAL ");
        getContentPane().add(title1);
        title1.setBounds(260, 30, 150, 20);

        subtitle1.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        subtitle1.setForeground(new java.awt.Color(0, 102, 102));
        subtitle1.setText("TIEMPO: 100ms");
        getContentPane().add(subtitle1);
        subtitle1.setBounds(560, 490, 100, 10);

        title2.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        title2.setForeground(new java.awt.Color(0, 102, 102));
        title2.setText("REGISTRO DEL PROCESO");
        getContentPane().add(title2);
        title2.setBounds(250, 490, 150, 20);

        title3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        title3.setText("NOMBRES:");
        getContentPane().add(title3);
        title3.setBounds(20, 430, 90, 20);

        title4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        title4.setText("APELLIDOS:");
        getContentPane().add(title4);
        title4.setBounds(20, 490, 90, 20);

        title5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        title5.setText("EDAD:");
        getContentPane().add(title5);
        title5.setBounds(20, 550, 90, 20);

        title6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        title6.setText("GENERO:");
        getContentPane().add(title6);
        title6.setBounds(20, 610, 90, 20);

        box1.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        box1.setText("Digite aquí. ");
        box1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                box1MouseClicked(evt);
            }
        });
        getContentPane().add(box1);
        box1.setBounds(20, 450, 210, 30);

        box2.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        box2.setText("Digite aquí. ");
        box2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                box2MouseClicked(evt);
            }
        });
        getContentPane().add(box2);
        box2.setBounds(20, 510, 210, 30);

        box3.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        box3.setText("Digite aquí. ");
        box3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                box3MouseClicked(evt);
            }
        });
        getContentPane().add(box3);
        box3.setBounds(20, 570, 210, 30);

        box4.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        box4.setText("Digite aquí. ");
        box4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                box4MouseClicked(evt);
            }
        });
        getContentPane().add(box4);
        box4.setBounds(20, 630, 210, 30);

        area1.setColumns(20);
        area1.setRows(5);
        jScrollPane1.setViewportView(area1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(254, 520, 166, 160);

        boton1.setFont(new java.awt.Font("Century Gothic", 1, 14)); // NOI18N
        boton1.setText("GONIÓMETRO DIGITAL");
        boton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boton1ActionPerformed(evt);
            }
        });
        getContentPane().add(boton1);
        boton1.setBounds(240, 370, 190, 50);

        tiempo.setFont(new java.awt.Font("Century Gothic", 0, 24)); // NOI18N
        tiempo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tiempo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        getContentPane().add(tiempo);
        tiempo.setBounds(560, 520, 90, 60);

        boton2.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        boton2.setText("INICIAR");
        boton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boton2ActionPerformed(evt);
            }
        });
        getContentPane().add(boton2);
        boton2.setBounds(270, 450, 90, 30);

        BORRAR.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        BORRAR.setText("BORRAR");
        BORRAR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BORRARActionPerformed(evt);
            }
        });
        getContentPane().add(BORRAR);
        BORRAR.setBounds(420, 450, 90, 30);

        MIN.setFont(new java.awt.Font("Century Gothic", 1, 14)); // NOI18N
        MIN.setForeground(new java.awt.Color(51, 204, 0));
        MIN.setText("VALOR MINIMO:");
        MIN.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        getContentPane().add(MIN);
        MIN.setBounds(450, 660, 160, 30);

        MAX.setFont(new java.awt.Font("Century Gothic", 1, 14)); // NOI18N
        MAX.setForeground(new java.awt.Color(255, 0, 51));
        MAX.setText("VALOR MAXIMO:");
        MAX.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        getContentPane().add(MAX);
        MAX.setBounds(450, 610, 160, 30);

        area2.setBackground(new java.awt.Color(204, 255, 153));
        area2.setColumns(20);
        area2.setFont(new java.awt.Font("Century Gothic", 1, 14)); // NOI18N
        area2.setRows(5);
        area2.setText(" EL Goniómetro Digital es un dispositivo \"LIBRE\" que  permite la medición de \n ángulos de flexión y extensión de los miembro inferiores del cuerpo humano.\n\n El Goniómetro utiliza sensores IMU Referencia MPU-6050 (GY-521) fabricado\n por IVENSENSE para mayor información acerca de los sensores:\n http://www.invensense.com/\n\n El dispositivo utiliza una serie de drivers  que permiten al Microcontrolador \n poderse comunicar con  una GUI ( interfaz grafica de usuario). \n\n Esta versión del goniómetro la compilo:\n Yulian Reyes (Sept 08 2014 02:59:40)\n Netbeans IDE 8.0\n\n                      UNIVERSIDAD DISTRITAL FRANCISCO JOSÉ DE CALDAS");
        area2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        area2.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        getContentPane().add(area2);
        area2.setBounds(70, 60, 540, 290);

        subtitle2.setFont(new java.awt.Font("Century Gothic", 1, 11)); // NOI18N
        subtitle2.setForeground(new java.awt.Color(0, 102, 102));
        subtitle2.setText("ANGULO ACTUAL ");
        getContentPane().add(subtitle2);
        subtitle2.setBounds(440, 490, 100, 10);

        setSize(new java.awt.Dimension(686, 788));
        setLocationRelativeTo(null);
    }// </editor-fold>                        

    private void boton1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
    MAX.setVisible(true);
    MIN.setVisible(true);
    
    BORRAR.setVisible(true);
    BORRAR.setEnabled(false);

    boton2.setVisible(true);
    area2.setVisible(false);  

    boton1.setVisible(false);
    lienzo.setVisible(true);        
   
    title2.setVisible(true);
    title3.setVisible(true);     title4.setVisible(true);
    title5.setVisible(true);     title6.setVisible(true);
    
    box1.setVisible(true);     box2.setVisible(true);
    box3.setVisible(true);     box4.setVisible(true);
    
    subtitle2.setVisible(true);
    subtitle1.setVisible(true);
    tiempo.setVisible(true);
    INPUTUSB.setVisible(true);
         
    jScrollPane1.setVisible(true);
    area1.setVisible(true);
    
    estado= true;
    
    degrees ();
    

    }                                      

    private void boton2ActionPerformed(java.awt.event.ActionEvent evt) {                                       
       if (Boton == 0){ 
            Boton =  1; 
           area1.setText("MOMBRE(s):   "+box1.getText()+'\n'+"APELLIDO(s): "+box2.getText()+'\n'+"EDAD:              "+box3.getText()+'\n'+"GENERO:        "+box4.getText()+'\n');
          BORRAR.setEnabled(false);
           this.boton2.setText("PARAR");           
           EnviarDatos("b");

           
           Reloj.start();
          
       }
       
         else if(Boton==1){
         Boton = 2; 
         this.boton2.setText("INICIAR");
         EnviarDatos("c");
         BORRAR.setEnabled(true);
         Reloj.stop();
        }
        
     else if(Boton==2){   
    
           Boton = 1; 
           this.boton2.setText("PARAR");
           EnviarDatos("b");
           BORRAR.setEnabled(false);
           Reloj.start();
    }
    }                                      

    private void BORRARActionPerformed(java.awt.event.ActionEvent evt) {                                       
        Boton = 0;
        area1.setText("");
       // EnviarDatos("c");
        this.boton2.setText("INICIAR");
        INPUTUSB.setText("");

       ptXf=10;
       ptXi=10;
       ptYi=190;
       ptYf=190;
       
       
       lienzo.valores(ptXi, ptYi,ptXf,ptYf);
       lienzo.repaint();
       
           box1.setEnabled(true);
           box2.setEnabled(true);
           box3.setEnabled(true);
           box4.setEnabled(true); 
           
           Reloj.stop();
           contador=0;
           
       
    }                                      

    private void box1MouseClicked(java.awt.event.MouseEvent evt) {                                  
box1.setText("");        // TODO add your handling code here:
    }                                 

    private void box2MouseClicked(java.awt.event.MouseEvent evt) {                                  
box2.setText("");        // TODO add your handling code here:
    }                                 

    private void box4MouseClicked(java.awt.event.MouseEvent evt) {                                  
box4.setText("");        // TODO add your handling code here:
    }                                 

    private void box3MouseClicked(java.awt.event.MouseEvent evt) {                                  
 box3.setText("");         // TODO add your handling code here:
    }                                 




   public static void main(String args[]){
   java.awt.EventQueue.invokeLater(new Runnable() {
   public void run() {
   new GONIOMETRO().setVisible(true);
   }    });}
      
    // Variables declaration - do not modify                     
    private javax.swing.JLabel A0;
    private javax.swing.JLabel A10;
    private javax.swing.JLabel A100;
    private javax.swing.JLabel A110;
    private javax.swing.JLabel A120;
    private javax.swing.JLabel A130;
    private javax.swing.JLabel A140;
    private javax.swing.JLabel A150;
    private javax.swing.JLabel A160;
    private javax.swing.JLabel A170;
    private javax.swing.JLabel A180;
    private javax.swing.JLabel A20;
    private javax.swing.JLabel A30;
    private javax.swing.JLabel A40;
    private javax.swing.JLabel A50;
    private javax.swing.JLabel A60;
    private javax.swing.JLabel A70;
    private javax.swing.JLabel A80;
    private javax.swing.JLabel A90;
    private javax.swing.JLabel A_10;
    private javax.swing.JLabel A_100;
    private javax.swing.JLabel A_110;
    private javax.swing.JLabel A_120;
    private javax.swing.JLabel A_130;
    private javax.swing.JLabel A_140;
    private javax.swing.JLabel A_150;
    private javax.swing.JLabel A_160;
    private javax.swing.JLabel A_170;
    private javax.swing.JLabel A_180;
    private javax.swing.JLabel A_20;
    private javax.swing.JLabel A_30;
    private javax.swing.JLabel A_40;
    private javax.swing.JLabel A_50;
    private javax.swing.JLabel A_60;
    private javax.swing.JLabel A_70;
    private javax.swing.JLabel A_80;
    private javax.swing.JLabel A_90;
    private javax.swing.JButton BORRAR;
    private javax.swing.JLabel INPUTUSB;
    private javax.swing.JLabel MAX;
    private javax.swing.JLabel MIN;
    private javax.swing.JTextArea area1;
    private javax.swing.JTextArea area2;
    private javax.swing.JButton boton1;
    private javax.swing.JButton boton2;
    private javax.swing.JTextField box1;
    private javax.swing.JTextField box2;
    private javax.swing.JTextField box3;
    private javax.swing.JTextField box4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel subtitle1;
    private javax.swing.JLabel subtitle2;
    private javax.swing.JLabel tiempo;
    private javax.swing.JLabel title1;
    private javax.swing.JLabel title2;
    private javax.swing.JLabel title3;
    private javax.swing.JLabel title4;
    private javax.swing.JLabel title5;
    private javax.swing.JLabel title6;
    // End of variables declaration                   
}
PROGRAMC/C++
/* ========================================
 * PROTOTYPE DE GONIOMETRE DIGITAL
 *
 * ========================================
*/


#include <project.h>
#include <interrupts.h>
#include <mpu6050.h>
#include <stdio.h>
#include <math.h>

#define forever 1
#define numberOfTests   100



//*************** MPU1 y MPU 2 *************** 

//MPU6050 accelerometro1(0x68); // direccion del mpu#1  (0x68) es GND 0V
//MPU6050 accelerometro2(0x69); // direccion del mpu#2  (0x69) es VCC 3V3



void calibrateOffsets(void);

uint8 flag = 0;

char buf[200];     // Buffer general para mensajes
char Abuf[200];    // para guardar el texto del valor de aceleración

int i = 0;  // para la variable de incremento de bucle
   
int16_t CAX, CAY, CAZ; // valores de aceleración actuales MPU1
int16_t CAX2, CAY2, CAZ2; // valores de aceleración actuales MPU2

int16_t CGX, CGY, CGZ; // valores actuales del giroscopio MPU1
int16_t CGX2, CGY2, CGZ2; // valores actuales del giroscopio MPU 2
int16_t CT;               //temperatura actual MPU1 MPU2
int16_t CT2;               //temperatura actual
   
float   AXoff, AYoff, AZoff; // valores de desplazamiento del acelerómetro MPU1
float   GXoff, GYoff, GZoff; // valores de desplazamiento del giroscopio MPU1

float   AXoff2, AYoff2, AZoff2; // valores de desplazamiento del acelerómetro MPU1
float   GXoff2, GYoff2, GZoff2; // valores de desplazamiento del giroscopio MPU1

float   AX, AY, AZ; // flota de aceleración MPU1
float   GX, GY, GZ; // giroscopio flota MPU1

float   AX2, AY2, AZ2; // flota de aceleración MPU2
float   GX2, GY2, GZ2; // giroscopio flota MPU2

float   Pitch;
float   Pitch2;

float   FPitch;
float   FPitch2;
float GREAL,GONIO;

float   x;
float   x2;
int main()
{
   /* Coloque aquí su código de inicialización / inicio (por ejemplo, MyInst_Start ()) */
    uint8 volatile ch;  
    /* Iniciar el SCB UART */
    UART_Start(); 
    /* Iniciar el Interrupt */
    UART_RX_ISR_StartEx(uartInterrupt);  
    /* Transmitir string atravez del UART */
    UART_UartPutString("UART Initialised");

    CyGlobalIntEnable; /* Descomente esta línea para habilitar interrupciones globales. */
    
    I2C_MPU6050_Start();

	MPU6050_init();
	MPU6050_initialize();
	UART_UartPutString(MPU6050_testConnection() ? "MPU6050 connection successful\n\r" : "MPU6050 connection failed\n\n\r");
    
    UART_UartPutString("Starting to calibrate values from sensor..\n\r");
    calibrateOffsets(); //work out our offsets - // resuelve nuestras compensaciones
    
    while(forever)
    {         
      //Convert values to G's FOT MPU1
      MPU6050_getMotion6t(&CAY, &CAX, &CAZ, &CGX, &CGY, &CGZ, &CT);
      
      AX = ((float)CAX-AXoff)/16384.00;
      AY = ((float)CAY-AYoff)/16384.00; //16384 is just 32768/2 to get our 1G value
      AZ = ((float)CAZ-(AZoff-16384))/16384.00; //remove 1G before dividing
    
      GX = ((float)CGX-GXoff)/131.07; //131.07 is just 32768/250 to get us our 1deg/sec value
      GY = ((float)CGY-GYoff)/131.07;
      GZ = ((float)CGZ-GZoff)/131.07; 
    
    
       //Convert values to G's FOT MPU2
      MPU6050_getMotion6t(&CAY, &CAX, &CAZ, &CGX, &CGY, &CGZ, &CT);
      
      AX2 = ((float)CAX-AXoff)/16384.00;
      AY2 = ((float)CAY-AYoff)/16384.00; //16384 is just 32768/2 to get our 1G value
      AZ2 = ((float)CAZ-(AZoff-16384))/16384.00; //remove 1G before dividing
    
      GX2 = ((float)CGX2-GXoff2)/131.07; //131.07 is just 32768/250 to get us our 1deg/sec value
      GY2 = ((float)CGY2-GYoff2)/131.07;
      GZ2 = ((float)CGZ2-GZoff2)/131.07; 
    
      //UART_UartPutString(buf);
    
      
      Pitch = atan2f(AY, sqrt(AX*AX + AZ*AZ)) * 180/M_PI; 
      Pitch2 = atan2f(AY2, sqrt(AX2*AX2 + AZ2*AZ2)) * 180/M_PI; 
    
    x= Pitch;
    x2= Pitch2;
    
// Resultado   
//            angle_y  = [-pi2/pi/2]                 //            angle_y2  = [-pi2/pi/2]               //
//                                                   //                                                  //
//                        90°                       //                        90°                      //
//                    **********                     //                    **********                    //
//              45°****************45°             //              45°****************45°            //
//               ********************                //               ********************               //
//           0° ********************** 0°          //            0°********************** 0°         //
//               ********************                //               ********************               //
//             -45°****************-45°            //             -45°****************-45°           //
//                   ************                    //                   ************                   //
//                       -90                         //                       -90                        //
     
  
    // Resultado   
//            angle_y  = [-pi2/pi/2]                 //            angle_y2  = [-pi2/pi/2]               //
//                                                   //                                                  //
//                        90°                       //                        90°                      //
//                    **********                     //                    **********                    //
//              45°****************45°             //              45°****************45°            //
//               ********************                //               ********************               //
//           0° ********************** 0°          //            0°********************** 0°         //
//               ********************                //               ********************               //
//             -45°****************-45°            //             -45°****************-45°           //
//                   ************                    //                   ************                   //
//                       -90                         //                       -90                        //
  
//********* Transformacion del angulo de [-180 -> 0 <- 180] *********   

//-----------  MPU6050 #1 -----------//
         if (Pitch  >0 && x<=0 )    {  FPitch  =  180-Pitch;       }
    else if (Pitch  <0 && x<=0 )    {  FPitch  = (180+Pitch)*(-1);  }
//    else if (angle_y >=      180)    {  angle_yA=  180;                }
//    else if (angle_y <=   (-180))    {  angle_yA=  180;                } // REVISAR
    else                             {  FPitch=  Pitch;            }
 
//-----------  MPU6050 #2 -----------//
         if (Pitch2 > 0 && x2<=0)  {  FPitch2=  180-Pitch2 ;      }
    else if (Pitch2 < 0 && x2<=0)  {  FPitch2= (180+Pitch2)*(-1); }
//    else if (angle_y2 >=   180    )  {  angle_yB=  180;                }
//    else if (angle_y2 <= (-180)   )  {  angle_yB=  180;                }  // revisar -180 
    else                             {  FPitch2=  Pitch2;           }


// SE RESTA EL ANGULO DE MPU1 SOBRE EL DOS Y EL UNO SE CONVIERTE EN 0
 GREAL= FPitch2-FPitch;

         if (GREAL > 180)   {  GONIO= GREAL-360;  }
    else if (GREAL <-180 )  {  GONIO= GREAL+360;  }
    else                    {  GONIO= GREAL;      }
            

    

}
    
    sprintf(Abuf, "%f,\t\r\n",GONIO);
        
      if(flag == 1)
      {
        flag = 0;
        ch = UART_UartGetChar();
        if(ch == 'a') //asking for acceleration values
        {
          UART_UartPutString(Abuf);   
        }
        TX_LED_Write(!TX_LED_Read());  
      }
        
          //CyDelay(500);
    }


void calibrateOffsets(void)
{
  //Count and average the first n values, defined by numberOfTests above..
  // Descomente estas líneas para mostrar la salida en serie ...
    for(i=0; i<numberOfTests; i++)
    {  
      MPU6050_getMotion6t(&CAX, &CAY, &CAZ, &CGX, &CGY, &CGZ, &CT);
      AXoff += CAX;
      AYoff += CAY;
      AZoff += CAZ;
      GXoff += CGX;
      GYoff += CGY;
      GZoff += CGZ;
      
      //Uncomment these lines to show serial output...
     // Descomente estas líneas para mostrar la salida en serie ...
      //sprintf(buf, "Test Number: %d \n\r", i);
      //SERIAL_UartPutString(buf);
      //sprintf(buf, "AX:%d, AY:%d, AZ:%d || GX:%d, GY:%d, GZ:%d,\t", CAX,CAY,CAZ,CGX,CGY,CGZ);
      //SERIAL_UartPutString(buf);
      //SERIAL_UartPutString("\n\r");
      CyDelay(25);
    }
    
    AXoff = AXoff/numberOfTests;
    AYoff = AYoff/numberOfTests;
    AZoff = AZoff/numberOfTests;
    GXoff = GXoff/numberOfTests;
    GYoff = GYoff/numberOfTests;
    GZoff = GZoff/numberOfTests;
    
    UART_UartPutString("\nTest finished, offset values are shown below\n\r");
    sprintf(buf, "\n\rGONIO:%d,\t\n\r", (int)GONIO);
    UART_UartPutString(buf);  
}


/* [] END OF FILE */

Credits

88637dc91e67f58c82a6670624a59470
yulian Hackters
1 project • 0 followers
Estudiante de ingeniería en electrónica
Contact
Thanks to hackster bogota .

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login