AVANCE PICCOLO CORTE 1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Camilokingxd
Date:
Tue Mar 13 04:30:04 2018 +0000
Child:
1:8574f732dba3
Commit message:
ENTREGA AVANZE PICCOLO CORTE 1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
servo.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 13 04:30:04 2018 +0000
@@ -0,0 +1,86 @@
+#include "mbed.h"
+#include "servo.h"
+
+DigitalOut myled(LED1);
+
+Serial pc(USBTX,USBRX);      //pines de transmision y recepcion asignados a puerto USB tipo B
+
+
+
+void S_EMPIEZA();
+void program_serial();
+void ejecutar();
+void guardar();
+void draw();
+void nodraw();
+
+int main() 
+{
+    program_serial();
+    uint8_t letra;
+    Servo Servos;
+    Servos.SetServo(0,0);        //calibración coordenadas (0,0)
+    Servos.SetZ(NODRAW);
+    myled = 1;
+    wait(2);
+    while(1) {
+        pc.printf(" ingrese comando \n");
+        letra=pc.getc();                //recibir caracter
+        switch(letra)
+        {
+            case CM_EJECUTAR: ejecutar(); break;
+            case CM_GUARDAR: guardar(); break;
+            case CM_SDRAW: draw(); break;
+            case CM_SN0DRAW: nodraw(); break;
+            default: pc.printf( "error de comando \n");break ;
+        }
+    }
+}
+void program_serial()
+{
+    pc.baud(9600);              //programar los baudios
+    pc.format(8,SerialBase::None,1);        //el numero de datos en bits, el bit de paridad, el bit de stop
+}
+void S_EMPIEZA()
+{
+    
+}
+void ejecutar()
+{
+    pc.printf( "el programa se esta ejecutando \n" );
+}
+void guardar()
+{
+    uint8_t letra;
+    Servo Servos;
+    program_serial();
+    pc.printf(" el programa se esta guardando \n" );
+    letra=pc.getc();
+    while(letra!=CM_END)
+    {
+        switch(letra)
+        {
+            case CM_SERVO:
+                letra=pc.getc();
+            break;
+            case CM_SDRAW:
+            break;
+            case CM_SN0DRAW:
+            break; 
+        }
+        letra=pc.getc();   
+    }
+    pc.printf(" el programa termino de guardar \n");
+}
+void draw()
+{
+    mypwmZ.pulsewidth_us(MAXPOS); 
+    //DRAW; 
+    pc.printf(" baja eje z \n");
+}
+void nodraw()
+{
+    mypwmZ.pulsewidth_us(NODRAW); 
+    //DRAW; 
+    pc.printf(" sube eje z \n");
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 13 04:30:04 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/aa5281ff4a02
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servo.h	Tue Mar 13 04:30:04 2018 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+#include "Serial.h"         //serial
+#ifndef SERVO_H
+#define SERVO_H
+#define MINPULSE 560
+#define MAXPULSE 2400
+#define MAXPOS 50// poscisión max de la coordenasda en mm
+#define DRAW 50 
+#define NODRAW 0
+#define CM_EJECUTAR 0Xff
+#define CM_GUARDAR 0Xfe
+#define CM_SERVO 0Xfd
+#define CM_SDRAW 0xfc
+#define CM_SN0DRAW 0xfb
+#define CM_STOP 0xfa
+#define CM_END 0xf0
+
+class Servo
+{
+    private:
+        uint8_t x,y,z;
+        int mm2pulse(float vmm);
+    public:
+        Servo();
+        ~Servo();
+        void SetServo(uint8_t,uint8_t);
+        void SetZ(uint8_t);
+        uint8_t GetServoX();
+        uint8_t GetServoY();
+        uint8_t GetServoZ();
+        int CONVERTIDOR(int);
+};
+
+#endif
+
+PwmOut mypwmX(PA_8);
+PwmOut mypwmY(PB_10);
+PwmOut mypwmZ(PB_4);
+
+Servo::Servo()
+{
+    mypwmX.period_ms(20);
+    mypwmY.period_ms(20);
+    mypwmZ.period_ms(20);
+    mypwmX.pulsewidth_us(MAXPULSE);
+    mypwmY.pulsewidth_us(MAXPULSE);
+    mypwmZ.pulsewidth_us(NODRAW);
+    
+}
+
+Servo::~Servo()
+{
+}
+int Servo::mm2pulse(float vmm)
+{
+  if (vmm < MAXPOS)
+    return int (vmm*(MAXPULSE-MINPULSE)/(MAXPOS)) +MINPULSE;
+  return MAXPULSE; 
+}
+void Servo::SetZ(uint8_t _z)
+{
+    z=_z;
+    int PULSEZ=mm2pulse(CONVERTIDOR(z));
+    mypwmZ.pulsewidth_us(PULSEZ); 
+}
+void Servo::SetServo(uint8_t _x,uint8_t _y)
+{
+    x=_x;
+    y=_y;
+    int PULSEX=mm2pulse(CONVERTIDOR(x));
+    int PULSEY=mm2pulse(CONVERTIDOR(y));
+    mypwmX.pulsewidth_us(PULSEX);
+    mypwmY.pulsewidth_us(PULSEY);   
+}
+uint8_t Servo::GetServoX()
+{
+    return x;
+}
+uint8_t Servo::GetServoY()
+{
+    return y;
+}
+uint8_t Servo::GetServoZ()
+{
+    return z;
+}
+int Servo::CONVERTIDOR(int c)
+{
+    int u=0;
+    u=c/16;
+    return c-6*u;
+}
\ No newline at end of file