Alyson Castiblanco
/
PARQUEADERO_VERTICAL
Codigo donde falta la comunicacion serial
main.cpp@4:66f0a55f249d, 2018-09-07 (annotated)
- Committer:
- fabeltranm
- Date:
- Fri Sep 07 12:38:06 2018 +0000
- Revision:
- 4:66f0a55f249d
- Parent:
- 3:6fff0b259d65
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:89b318e49395 | 1 | #include "mbed.h" |
fabeltranm | 0:89b318e49395 | 2 | |
fabeltranm | 0:89b318e49395 | 3 | #include "main.h" |
fabeltranm | 0:89b318e49395 | 4 | |
fabeltranm | 0:89b318e49395 | 5 | |
fabeltranm | 0:89b318e49395 | 6 | |
fabeltranm | 0:89b318e49395 | 7 | |
fabeltranm | 0:89b318e49395 | 8 | Serial command(USBTX, USBRX); |
fabeltranm | 0:89b318e49395 | 9 | |
fabeltranm | 2:3936d249a67c | 10 | #define MAXDAT 3 |
fabeltranm | 2:3936d249a67c | 11 | #define TIPO_COMM 0 |
fabeltranm | 2:3936d249a67c | 12 | #define NUM_MOTOR 1 |
fabeltranm | 2:3936d249a67c | 13 | #define NUM_GRADOS 2 |
fabeltranm | 0:89b318e49395 | 14 | |
fabeltranm | 0:89b318e49395 | 15 | |
fabeltranm | 2:3936d249a67c | 16 | uint8_t dat[MAXDAT]={0,0,0}; |
fabeltranm | 2:3936d249a67c | 17 | |
fabeltranm | 2:3936d249a67c | 18 | |
fabeltranm | 2:3936d249a67c | 19 | |
fabeltranm | 0:89b318e49395 | 20 | int main() { |
fabeltranm | 0:89b318e49395 | 21 | init_servo(); |
fabeltranm | 0:89b318e49395 | 22 | init_serial(); |
fabeltranm | 1:526bdd5faa37 | 23 | |
fabeltranm | 0:89b318e49395 | 24 | debug_m("inicio \n"); |
fabeltranm | 0:89b318e49395 | 25 | uint32_t read_cc; |
fabeltranm | 0:89b318e49395 | 26 | while(1) |
fabeltranm | 0:89b318e49395 | 27 | { |
fabeltranm | 2:3936d249a67c | 28 | while(read_command()==0); |
fabeltranm | 2:3936d249a67c | 29 | switch (dat[TIPO_COMM]) { |
fabeltranm | 1:526bdd5faa37 | 30 | case 0x01: moving(); break; |
fabeltranm | 4:66f0a55f249d | 31 | default: debug_m("prueba comando. "); |
fabeltranm | 4:66f0a55f249d | 32 | break ; |
fabeltranm | 0:89b318e49395 | 33 | } |
fabeltranm | 0:89b318e49395 | 34 | } |
fabeltranm | 0:89b318e49395 | 35 | } |
fabeltranm | 0:89b318e49395 | 36 | |
fabeltranm | 0:89b318e49395 | 37 | |
fabeltranm | 0:89b318e49395 | 38 | |
fabeltranm | 0:89b318e49395 | 39 | uint32_t read_command() |
fabeltranm | 0:89b318e49395 | 40 | { |
fabeltranm | 1:526bdd5faa37 | 41 | // retorna los byte recibidos concatenados en un entero, |
fabeltranm | 0:89b318e49395 | 42 | |
fabeltranm | 1:526bdd5faa37 | 43 | |
fabeltranm | 1:526bdd5faa37 | 44 | |
fabeltranm | 1:526bdd5faa37 | 45 | char intc=command.getc(); |
fabeltranm | 0:89b318e49395 | 46 | |
fabeltranm | 1:526bdd5faa37 | 47 | while(intc != '<') |
fabeltranm | 1:526bdd5faa37 | 48 | intc=command.getc(); |
fabeltranm | 2:3936d249a67c | 49 | |
fabeltranm | 4:66f0a55f249d | 50 | for (int i =0;i<MAXDAT;i++) |
fabeltranm | 2:3936d249a67c | 51 | dat[i]=command.getc(); |
fabeltranm | 2:3936d249a67c | 52 | |
fabeltranm | 2:3936d249a67c | 53 | intc=command.getc(); |
fabeltranm | 2:3936d249a67c | 54 | |
fabeltranm | 4:66f0a55f249d | 55 | if(intc != '>'){ |
fabeltranm | 4:66f0a55f249d | 56 | debug_m("error de comando no se recibe bien ..\n"); |
fabeltranm | 2:3936d249a67c | 57 | return 0; |
fabeltranm | 4:66f0a55f249d | 58 | } |
fabeltranm | 2:3936d249a67c | 59 | return 1; |
fabeltranm | 0:89b318e49395 | 60 | } |
fabeltranm | 1:526bdd5faa37 | 61 | |
fabeltranm | 1:526bdd5faa37 | 62 | |
fabeltranm | 0:89b318e49395 | 63 | void init_serial() |
fabeltranm | 0:89b318e49395 | 64 | { |
fabeltranm | 0:89b318e49395 | 65 | command.baud(9600); |
fabeltranm | 0:89b318e49395 | 66 | } |
fabeltranm | 0:89b318e49395 | 67 | |
fabeltranm | 0:89b318e49395 | 68 | |
fabeltranm | 1:526bdd5faa37 | 69 | void moving(){ |
fabeltranm | 1:526bdd5faa37 | 70 | debug_m("se inicia el comado mover..\n"); |
fabeltranm | 0:89b318e49395 | 71 | |
fabeltranm | 2:3936d249a67c | 72 | char nmotor=dat[NUM_MOTOR]; |
fabeltranm | 2:3936d249a67c | 73 | char grados=dat[NUM_GRADOS]; |
fabeltranm | 1:526bdd5faa37 | 74 | mover_ser(nmotor,grados); |
fabeltranm | 3:6fff0b259d65 | 75 | debug_m("fin del comado ..\n"); |
fabeltranm | 0:89b318e49395 | 76 | |
fabeltranm | 0:89b318e49395 | 77 | } |
fabeltranm | 0:89b318e49395 | 78 | |
fabeltranm | 0:89b318e49395 | 79 | void debug_m(char *s , ... ){ |
fabeltranm | 0:89b318e49395 | 80 | #if DEBUG |
fabeltranm | 0:89b318e49395 | 81 | command.printf(s); |
fabeltranm | 0:89b318e49395 | 82 | #endif |
fabeltranm | 0:89b318e49395 | 83 | } |