ferney alberto beltran molina
/
00_LAB_COMMAND_SERVO
mover servomotore por telecomandos
main.cpp@0:a9181441db9b, 2019-02-22 (annotated)
- Committer:
- fabeltranm
- Date:
- Fri Feb 22 12:53:42 2019 +0000
- Revision:
- 0:a9181441db9b
- Child:
- 1:b473a0ad2b83
init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:a9181441db9b | 1 | #include "mbed.h" |
fabeltranm | 0:a9181441db9b | 2 | |
fabeltranm | 0:a9181441db9b | 3 | /***************************************************************************** |
fabeltranm | 0:a9181441db9b | 4 | generar un programa que controle por el puerto serial el grado de 4 servo motores |
fabeltranm | 0:a9181441db9b | 5 | por medio de la comunicacion serial donde el comando sea |
fabeltranm | 0:a9181441db9b | 6 | |
fabeltranm | 0:a9181441db9b | 7 | | | | | |
fabeltranm | 0:a9181441db9b | 8 | | init_commd | N_motor | N_grados | |
fabeltranm | 0:a9181441db9b | 9 | | 0xff | 0x01- 0x04 | 0x00 - 0xb4 | |
fabeltranm | 0:a9181441db9b | 10 | |
fabeltranm | 0:a9181441db9b | 11 | para enviar los comandos usar el programa Coolterm |
fabeltranm | 0:a9181441db9b | 12 | *****************************************************************************/ |
fabeltranm | 0:a9181441db9b | 13 | |
fabeltranm | 0:a9181441db9b | 14 | |
fabeltranm | 0:a9181441db9b | 15 | Serial command(USBTX, USBRX); |
fabeltranm | 0:a9181441db9b | 16 | PwmOut myservo1(PB_4); |
fabeltranm | 0:a9181441db9b | 17 | /*INGRESE L A CONFIGURACION DE LOS MOTORES*/ |
fabeltranm | 0:a9181441db9b | 18 | |
fabeltranm | 0:a9181441db9b | 19 | |
fabeltranm | 0:a9181441db9b | 20 | |
fabeltranm | 0:a9181441db9b | 21 | // definicion de las variables globales |
fabeltranm | 0:a9181441db9b | 22 | |
fabeltranm | 0:a9181441db9b | 23 | uint8_t nm; // almacena el número de motor |
fabeltranm | 0:a9181441db9b | 24 | uint8_t ng; // almacena los grados que se mueve el motor |
fabeltranm | 0:a9181441db9b | 25 | |
fabeltranm | 0:a9181441db9b | 26 | |
fabeltranm | 0:a9181441db9b | 27 | void setup_uart(); |
fabeltranm | 0:a9181441db9b | 28 | void setup_motor(); |
fabeltranm | 0:a9181441db9b | 29 | void mover_servo(); |
fabeltranm | 0:a9181441db9b | 30 | |
fabeltranm | 0:a9181441db9b | 31 | |
fabeltranm | 0:a9181441db9b | 32 | int main() { |
fabeltranm | 0:a9181441db9b | 33 | |
fabeltranm | 0:a9181441db9b | 34 | myservo1.period_ms(20); |
fabeltranm | 0:a9181441db9b | 35 | int cw=1; |
fabeltranm | 0:a9181441db9b | 36 | int dpulse=1000; |
fabeltranm | 0:a9181441db9b | 37 | myservo1.pulsewidth_us(dpulse); |
fabeltranm | 0:a9181441db9b | 38 | |
fabeltranm | 0:a9181441db9b | 39 | while(1) { |
fabeltranm | 0:a9181441db9b | 40 | myservo1.pulsewidth_us(dpulse); |
fabeltranm | 0:a9181441db9b | 41 | wait(0.5); |
fabeltranm | 0:a9181441db9b | 42 | if (cw){ |
fabeltranm | 0:a9181441db9b | 43 | dpulse+=100; |
fabeltranm | 0:a9181441db9b | 44 | if (dpulse==2500) |
fabeltranm | 0:a9181441db9b | 45 | cw=0; |
fabeltranm | 0:a9181441db9b | 46 | }else{ |
fabeltranm | 0:a9181441db9b | 47 | dpulse-=100; |
fabeltranm | 0:a9181441db9b | 48 | if (dpulse==100) |
fabeltranm | 0:a9181441db9b | 49 | cw=1; |
fabeltranm | 0:a9181441db9b | 50 | } |
fabeltranm | 0:a9181441db9b | 51 | } |
fabeltranm | 0:a9181441db9b | 52 | } |