Codigo donde falta la comunicacion serial

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
acastiblancoc
Date:
Thu Nov 22 09:48:47 2018 +0000
Parent:
4:66f0a55f249d
Commit message:
Codigo parqueadero

Changed in this revision

main.cpp Show diff for this revision Revisions of this file
main.h Show diff for this revision Revisions of this file
mover.cpp Show diff for this revision Revisions of this file
mover.h Show diff for this revision Revisions of this file
princilap.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Sep 07 12:38:06 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-#include "mbed.h"
-
-#include "main.h"
-
-
-
-
-Serial command(USBTX, USBRX);
-
-#define MAXDAT 3
-#define TIPO_COMM 0
-#define NUM_MOTOR 1
-#define NUM_GRADOS 2 
-
-
-uint8_t dat[MAXDAT]={0,0,0};
-
-  
-
-int main() {
-    init_servo();
-    init_serial();
-
-    debug_m("inicio \n");
-    uint32_t read_cc;
-    while(1)
-    {
-        while(read_command()==0);
-        switch (dat[TIPO_COMM]) {
-            case  0x01: moving(); break;
-            default: debug_m("prueba comando. ");
-            break ;      
-        }
-    }
-}
-
-
-
-uint32_t read_command()
-{
-   // retorna los byte recibidos concatenados en un entero, 
-   
-
-    
-    char intc=command.getc();
-    
-    while(intc != '<')
-        intc=command.getc();
-        
-    for (int i =0;i<MAXDAT;i++)
-        dat[i]=command.getc();
-    
-    intc=command.getc();
-    
-    if(intc != '>'){
-        debug_m("error de comando no se recibe bien  ..\n");    
-        return 0;
-        }
-    return 1;
-}
-
-
-void init_serial()
-{
-    command.baud(9600);    
-}
-
-
-void moving(){
-    debug_m("se inicia el comado mover..\n");    
-    
-    char nmotor=dat[NUM_MOTOR];
-    char grados=dat[NUM_GRADOS];
-    mover_ser(nmotor,grados); 
-    debug_m("fin del comado ..\n");    
-    
-}
-
-void debug_m(char *s , ... ){
-    #if DEBUG
-    command.printf(s);
-    #endif  
-}
\ No newline at end of file
--- a/main.h	Fri Sep 07 12:38:06 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef MAIN_H   
-#define MAIN_H  
-
-
-#include "mover.h"
-
-//******************************************************************************
-// Desarrollado por ferney beltran fbeltran@ecci.edu.co
-//******************************************************************************
-
-
-#define DEBUG 1
-
-
-void debug_m(char *s , ... );
-uint32_t read_command();
-void init_serial();
-
-void moving();
-
-
-#endif //  MAIN_H 
\ No newline at end of file
--- a/mover.cpp	Fri Sep 07 12:38:06 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-
-#include "mover.h"
-#include "mbed.h"
-#include "math.h"
-
-
-PwmOut myServo1(PB_3);
-PwmOut myServo2(PB_4);
-PwmOut myServo3(PB_5);
-
-
-uint8_t  ss_time=50;     // tiempo  de espera para moverse 1 mm en microsegundos
-
-void put_sstime(uint8_t vtime){
-    ss_time=vtime;
-    
-}
-
-int coord2us(float coord)
-{
-    if(0 <= coord <= MAXPOS)
-        return int(750+coord*1900/50);// u6
-    return 750;
-
-}
-
-
- 
-
-
-void mover_ser(uint8_t motor, uint8_t pos){
-
-    int pulseX = coord2us(pos);
-    
-    myServo1.pulsewidth_us(pulseX);
- 
-
-}
-
-void init_servo()
-{
-   myServo1.period_ms(20);
-   myServo2.period_ms(20);
-   myServo3.period_ms(20);
-
-    
-}
\ No newline at end of file
--- a/mover.h	Fri Sep 07 12:38:06 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#ifndef DRAW_H   
-#define DRAW_H  
-
-#include "mbed.h"
-
-#define MAXPOS 50       // en milimetros
-#define POSDRAW 50  
-#define POSNODRAW 10  
-
-
-void init_servo();
-void draw();
-void nodraw();
-void mover_ser(uint8_t motor, uint8_t pos);
-
-
-
-#endif //  DRAW_H 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/princilap.cpp	Thu Nov 22 09:48:47 2018 +0000
@@ -0,0 +1,130 @@
+#include "mbed.h"
+Serial pc(SERIAL_TX, SERIAL_RX);
+AnalogIn sensoras1(A0);
+AnalogIn sensoras2(A1);
+AnalogIn sensoras3(A2);
+DigitalIn sensorc1(D15);
+DigitalIn sensorc2(D14);
+DigitalIn sensorc3(D13);
+DigitalIn sensorc4(D12);
+DigitalIn sensorc5(D11);
+DigitalIn sensorc6(D10);
+BusOut myleds(LED1, LED2, LED3, LED4);
+BusOut motor(D4, D5, D6, D7);
+
+int tiempo = 12000; 
+void ADCC()
+{
+    float s1=sensoras1.read();
+    float s2=sensoras2.read();
+    float s3=sensoras3.read();
+    /*printf("sensor 1 = %f\n", s1);
+    printf("sensor 2 = %f\n", s2);
+    printf("sensor 3 = %f\n", s3);*/
+    if(s1>0.8 && s2<0.1 && s3>0.8)
+    printf("piso 1\n");
+    if(s1<0.1 && s2>0.8 && s3<0.1)
+    printf("piso 2\n");
+    if(s1>0.8 && s2<0.1 && s3<0.1)
+    printf("piso 3\n");
+    if(s1<0.1 && s2<0.1 && s3>0.8)
+    printf("piso 4\n");
+    if(s1<0.1 && s2>0.8 && s3>0.8)
+    printf("piso 5\n");
+    if(s1>0.8 && s2>0.8 && s3<0.1)
+    printf("piso 6\n");
+    else
+    printf("no piso\n");
+}
+
+void carro1()
+{int c=sensorc1.read();
+//printf("sensor piso 1 = %i\n", c);
+if(c==1)
+printf("Hay carro en piso 1 \n");
+}
+void carro2()
+{int c1=sensorc2.read();
+//printf("sensor piso 1 = %i\n", c);
+if(c1==1)
+printf("Hay carro en piso 2 \n");
+}
+void carro3()
+{int c2=sensorc3.read();
+//printf("sensor piso 1 = %i\n", c);
+if(c2==1)
+printf("Hay carro en piso 3 \n");
+}
+void carro4()
+{int c3=sensorc4.read();
+//printf("sensor piso 1 = %i\n", c);
+if(c3==1)
+printf("Hay carro en piso 4 \n");
+}
+void carro5()
+{int c4=sensorc5.read();
+//printf("sensor piso 1 = %i\n", c);
+if(c4==1)
+printf("Hay carro en piso 1 \n");
+}
+void carro6()
+{int c5=sensorc6.read();
+//printf("sensor piso 1 = %i\n", c);
+if(c5==1)
+printf("Hay carro en piso 1 \n");
+}
+void detectarcarro()
+{
+//int c=sensorc.read();
+//printf("sensor piso 1 = %i\n", c);
+/*if(c==1)
+printf("Hay carro en piso 1 \n");*/
+carro1();
+wait_ms(200);
+carro2();
+wait_ms(200);
+carro3();
+wait_ms(200);
+carro4();
+wait_ms(200);
+carro5();
+wait_ms(200);
+carro6();
+wait_ms(200);
+}
+
+void pasoapaso()
+{
+     for (int s = 0; s < 120 ; s +=1) {
+        motor = (0xA); //1010
+        wait_us(tiempo);
+        motor = (0x6);//0110
+        wait_us(tiempo);
+        motor = (0x5);//0101
+        wait_us(tiempo);
+        motor = (0x9);//1001
+        wait_us(tiempo);
+        }
+        wait(2);
+        for (int s = 0; s < 120 ; s +=1) {//ahora en sentido contrario
+        motor = (0x9);//1001
+        wait_us(tiempo);
+        motor = (0x5);//0101
+        wait_us(tiempo);
+        motor = (0x6);//0110
+        wait_us(tiempo);
+        motor = (0xA);//1010
+        wait_us(tiempo);
+        }
+        wait(2);
+    }
+    
+int main() {
+    
+    while(1) {
+        //ADCC();
+        detectarcarro();
+        //wait(0.5);
+        //pasoapaso();
+    }
+}