Ricardo Soto
/
IMTarmProgramable
IMTcchallenge para prepos
main.cpp@0:21188b66200a, 2015-10-15 (annotated)
- Committer:
- Soto
- Date:
- Thu Oct 15 17:25:56 2015 +0000
- Revision:
- 0:21188b66200a
- Child:
- 1:d47f3431441b
Meh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Soto | 0:21188b66200a | 1 | /* Programa para el control de |
Soto | 0:21188b66200a | 2 | un brazon robotico con 5 servos |
Soto | 0:21188b66200a | 3 | |
Soto | 0:21188b66200a | 4 | Carrera Ingenieria Mecatronica |
Soto | 0:21188b66200a | 5 | IMT |
Soto | 0:21188b66200a | 6 | */ |
Soto | 0:21188b66200a | 7 | |
Soto | 0:21188b66200a | 8 | #include "mbed.h" |
Soto | 0:21188b66200a | 9 | #include "Servo.h" |
Soto | 0:21188b66200a | 10 | #include <vector> |
Soto | 0:21188b66200a | 11 | |
Soto | 0:21188b66200a | 12 | //*****************Servos y sus Puertos******* |
Soto | 0:21188b66200a | 13 | |
Soto | 0:21188b66200a | 14 | Servo Garra(PTC9); |
Soto | 0:21188b66200a | 15 | Servo Muneca(PTC8); |
Soto | 0:21188b66200a | 16 | Servo Codo(PTA5); |
Soto | 0:21188b66200a | 17 | Servo Hombro(PTA4); |
Soto | 0:21188b66200a | 18 | Servo Eje(PTA12); |
Soto | 0:21188b66200a | 19 | |
Soto | 0:21188b66200a | 20 | //*********Definicion de Funciones************ |
Soto | 0:21188b66200a | 21 | |
Soto | 0:21188b66200a | 22 | void ServosMovingTogether(float, float, float, float, float); |
Soto | 0:21188b66200a | 23 | |
Soto | 0:21188b66200a | 24 | //*********Macros Defines********************* |
Soto | 0:21188b66200a | 25 | #define MidStepDelay 1 //modificar este valor para el tiempo entre el movimiento de un motor y otro |
Soto | 0:21188b66200a | 26 | #define GenralLoopDelay 1 //Modificar este valor para el tiempo entre una secuencia de movimiento de 5 motores y la secuencia siguiente |
Soto | 0:21188b66200a | 27 | |
Soto | 0:21188b66200a | 28 | //Comando para iniciar un comunicacion entre la FRDM-KL-Z y la computador |
Soto | 0:21188b66200a | 29 | |
Soto | 0:21188b66200a | 30 | Serial pc(USBTX, USBRX); |
Soto | 0:21188b66200a | 31 | //-------------------------------------------------------------------- |
Soto | 0:21188b66200a | 32 | //**************Inicio del programa principal************************* |
Soto | 0:21188b66200a | 33 | //-------------------------------------------------------------------- |
Soto | 0:21188b66200a | 34 | int main(){ |
Soto | 0:21188b66200a | 35 | |
Soto | 0:21188b66200a | 36 | pc.baud(9600); //Velocidad de la comunicacion entre la tarjeta y la computadora |
Soto | 0:21188b66200a | 37 | |
Soto | 0:21188b66200a | 38 | printf("\nBienvenido\n\n Iniciando la rutina del IMTarm"); |
Soto | 0:21188b66200a | 39 | while(1){ //Loop infinito |
Soto | 0:21188b66200a | 40 | |
Soto | 0:21188b66200a | 41 | ServosMovingTogether(0.5,0.5,0.5,0.5,0.5); |
Soto | 0:21188b66200a | 42 | wait(GenralLoopDelay); |
Soto | 0:21188b66200a | 43 | |
Soto | 0:21188b66200a | 44 | |
Soto | 0:21188b66200a | 45 | }//Fin del Loop infinito |
Soto | 0:21188b66200a | 46 | |
Soto | 0:21188b66200a | 47 | //+++++++++++++++++++++++++++++++++++++++++++++++ |
Soto | 0:21188b66200a | 48 | //----------------------------------------------- |
Soto | 0:21188b66200a | 49 | }//********FIN DEL PROGRAMA PRINCIPAL************* |
Soto | 0:21188b66200a | 50 | //----------------------------------------------- |
Soto | 0:21188b66200a | 51 | //+++++++++++++++++++++++++++++++++++++++++++++++ |
Soto | 0:21188b66200a | 52 | |
Soto | 0:21188b66200a | 53 | |
Soto | 0:21188b66200a | 54 | //----------------------------------------------- |
Soto | 0:21188b66200a | 55 | //Funcion para mover los 5 servos en secuencia |
Soto | 0:21188b66200a | 56 | //----------------------------------------------- |
Soto | 0:21188b66200a | 57 | void ServosMovingTogether(float EjePos, float HombroPos, float CodoPos, float MunecaPos, float GarraPos) |
Soto | 0:21188b66200a | 58 | { |
Soto | 0:21188b66200a | 59 | Eje=EjePos; |
Soto | 0:21188b66200a | 60 | wait (MidStepDelay); |
Soto | 0:21188b66200a | 61 | |
Soto | 0:21188b66200a | 62 | Hombro=HombroPos; |
Soto | 0:21188b66200a | 63 | wait (MidStepDelay); |
Soto | 0:21188b66200a | 64 | |
Soto | 0:21188b66200a | 65 | Codo=CodoPos; |
Soto | 0:21188b66200a | 66 | wait (MidStepDelay); |
Soto | 0:21188b66200a | 67 | |
Soto | 0:21188b66200a | 68 | Muneca=MunecaPos; |
Soto | 0:21188b66200a | 69 | wait (MidStepDelay); |
Soto | 0:21188b66200a | 70 | |
Soto | 0:21188b66200a | 71 | |
Soto | 0:21188b66200a | 72 | Garra=GarraPos; |
Soto | 0:21188b66200a | 73 | wait (MidStepDelay); |
Soto | 0:21188b66200a | 74 | } |