final nnnn

Dependencies:   mbed

Este proyecto es un Piccolo en el cual se envía comandos para la realización de un dibujo en especifico. El programa va a controlar servos y motores paso a paso teniendo libertad de movimiento en los ejes X,Y,Z; En el programa se utiliza Comunicacion Serial (TX,RX) y para leer el dato fue necesario concatenarlo debido a que recibe 8 Bits pero tenemos que recibir 4 paquetes de 8 Bits para llegar a 32 Bits y poder asi leerlo.

Se estan implementando algunas librerias para su ejecucion como la #include "memory.h" que es de memoria, #include memory_array_h, tambien definimos la memoria #define mm_size 10 de tipo Type Uint32_t, la libreria de operaciones #include "math.h" y la libreria para los motores #include "stepmotor.h".

Para su ejecucion se crearon variables de ejecucion:

CM_DRAWING 0XFF: Se ejecuta siempre y cuando exista datos validos para leer de memoria y nos muestra por medio de un mensaje que se esta ejecutando el dibujo

CM_SAVING 0XFE: Inicia el comando de guardar

CM_VERTEX2D 0XFD: Se encarga de dar las coordenadas a los servomotores en X,Y.

CM_DRAW 0XFC: Se encarga de mover nuestro motor en Z

CM_NODRAW 0XFB: Su funcion es volver a la posicion inicial el motor en el eje Z

CM_MOTOR 0XF9: Se encarga de mover los motores paso a paso para llegar a la ubicacion asignada ingresando el Numero de cuadrantes y su sentido de giro.

Committer:
ANTONIO_VARGAS
Date:
Thu Apr 26 01:48:40 2018 +0000
Revision:
2:14fcd29abee0
Parent:
1:6ed951d975cc
explicacion programa piccolo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ANTONIO_VARGAS 0:0119b611fc51 1
ANTONIO_VARGAS 0:0119b611fc51 2 #include "stepmotor.h"
ANTONIO_VARGAS 0:0119b611fc51 3 #include "mbed.h"
ANTONIO_VARGAS 0:0119b611fc51 4
ANTONIO_VARGAS 0:0119b611fc51 5 stepmotor::stepmotor(PinName in1, PinName in2, PinName in3, PinName in4) : motor_out(in1,in2,in3,in4) {
ANTONIO_VARGAS 0:0119b611fc51 6
ANTONIO_VARGAS 0:0119b611fc51 7
ANTONIO_VARGAS 0:0119b611fc51 8 motor_out=0x0;
ANTONIO_VARGAS 0:0119b611fc51 9 nstep=0;
ANTONIO_VARGAS 0:0119b611fc51 10 motorSpeed=1100;
ANTONIO_VARGAS 0:0119b611fc51 11
ANTONIO_VARGAS 0:0119b611fc51 12 }
ANTONIO_VARGAS 0:0119b611fc51 13
ANTONIO_VARGAS 0:0119b611fc51 14
ANTONIO_VARGAS 0:0119b611fc51 15 void stepmotor::move() {
ANTONIO_VARGAS 0:0119b611fc51 16
ANTONIO_VARGAS 0:0119b611fc51 17 switch(nstep)
ANTONIO_VARGAS 0:0119b611fc51 18 {
ANTONIO_VARGAS 0:0119b611fc51 19 case 0: motor_out = 0x1; break; // 0001
ANTONIO_VARGAS 0:0119b611fc51 20 case 1: motor_out = 0x3; break; // 0011
ANTONIO_VARGAS 0:0119b611fc51 21 case 2: motor_out = 0x2; break; // 0010
ANTONIO_VARGAS 0:0119b611fc51 22 case 3: motor_out = 0x6; break; // 0110
ANTONIO_VARGAS 0:0119b611fc51 23 case 4: motor_out = 0x4; break; // 0100
ANTONIO_VARGAS 0:0119b611fc51 24 case 5: motor_out = 0xC; break; // 1100
ANTONIO_VARGAS 0:0119b611fc51 25 case 6: motor_out = 0x8; break; // 1000
ANTONIO_VARGAS 0:0119b611fc51 26 case 7: motor_out = 0x9; break; // 1001
ANTONIO_VARGAS 0:0119b611fc51 27
ANTONIO_VARGAS 0:0119b611fc51 28 default: motor_out = 0x0; break; // 0000
ANTONIO_VARGAS 0:0119b611fc51 29 }
ANTONIO_VARGAS 0:0119b611fc51 30 wait_us(motorSpeed);
ANTONIO_VARGAS 0:0119b611fc51 31
ANTONIO_VARGAS 0:0119b611fc51 32 }
ANTONIO_VARGAS 0:0119b611fc51 33
ANTONIO_VARGAS 0:0119b611fc51 34 void stepmotor::set_speed(int speed){
ANTONIO_VARGAS 0:0119b611fc51 35 motorSpeed=speed; //set motor speed us
ANTONIO_VARGAS 0:0119b611fc51 36 }
ANTONIO_VARGAS 0:0119b611fc51 37 uint32_t stepmotor::get_speed(){
ANTONIO_VARGAS 0:0119b611fc51 38 return motorSpeed; //
ANTONIO_VARGAS 0:0119b611fc51 39 }
ANTONIO_VARGAS 0:0119b611fc51 40
ANTONIO_VARGAS 0:0119b611fc51 41 void stepmotor::step(uint32_t num_steps, bool cw) {
ANTONIO_VARGAS 0:0119b611fc51 42 // funcion para mover el motor N pasos CW o CCW
ANTONIO_VARGAS 0:0119b611fc51 43 // num_steps número de paso que da el motor
ANTONIO_VARGAS 0:0119b611fc51 44 // cw =True para dirección en sentido del reloj
ANTONIO_VARGAS 0:0119b611fc51 45 // cw =False para dirección contraria de las manecillas del reloj
ANTONIO_VARGAS 0:0119b611fc51 46
ANTONIO_VARGAS 0:0119b611fc51 47 uint32_t count=num_steps ;
ANTONIO_VARGAS 0:0119b611fc51 48 while(count){
ANTONIO_VARGAS 0:0119b611fc51 49 if (cw) nstep++;
ANTONIO_VARGAS 0:0119b611fc51 50 else nstep--;
ANTONIO_VARGAS 0:0119b611fc51 51 if (nstep>7) nstep=0;
ANTONIO_VARGAS 0:0119b611fc51 52 if (nstep<0) nstep=7;
ANTONIO_VARGAS 0:0119b611fc51 53 move();
ANTONIO_VARGAS 0:0119b611fc51 54 count--;
ANTONIO_VARGAS 0:0119b611fc51 55
ANTONIO_VARGAS 0:0119b611fc51 56 }
ANTONIO_VARGAS 0:0119b611fc51 57
ANTONIO_VARGAS 0:0119b611fc51 58 }