el programa permite ingresar la posición en el eje X,Y,Z, haciendo que el Servo MG90S con sus movimientos de 180° trabaje en mm de 0 a 50.

Dependents:   PICCOLO_CNC PICCOLO_CNC1

Committer:
Stevenor1997
Date:
Mon Feb 26 19:38:14 2018 +0000
Revision:
2:cc30b42ac66f
Child:
3:07bcb3c9a8b8
Programa de servos, con opci?n de eje z para DRAW y NODRAW;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Stevenor1997 2:cc30b42ac66f 1 #include "Servo_X.h"
Stevenor1997 2:cc30b42ac66f 2 #include "mbed.h"
Stevenor1997 2:cc30b42ac66f 3
Stevenor1997 2:cc30b42ac66f 4 PwmOut mypwmX(PA_8);
Stevenor1997 2:cc30b42ac66f 5 PwmOut mypwmY(PB_10);
Stevenor1997 2:cc30b42ac66f 6 PwmOut mypwmZ(PB_4);
Stevenor1997 2:cc30b42ac66f 7 Servo::Servo()
Stevenor1997 2:cc30b42ac66f 8 {
Stevenor1997 2:cc30b42ac66f 9 mypwmX.period_ms(20);
Stevenor1997 2:cc30b42ac66f 10 mypwmY.period_ms(20);
Stevenor1997 2:cc30b42ac66f 11 mypwmZ.period_ms(20);
Stevenor1997 2:cc30b42ac66f 12 mypwmX.pulsewidth_us(MINPULSE);
Stevenor1997 2:cc30b42ac66f 13 mypwmY.pulsewidth_us(MINPULSE);
Stevenor1997 2:cc30b42ac66f 14 mypwmZ.pulsewidth_us(NODRAW);
Stevenor1997 2:cc30b42ac66f 15
Stevenor1997 2:cc30b42ac66f 16 }
Stevenor1997 2:cc30b42ac66f 17 Servo::~Servo(){
Stevenor1997 2:cc30b42ac66f 18 }
Stevenor1997 2:cc30b42ac66f 19 int Servo::mm2pulse(int vmm)
Stevenor1997 2:cc30b42ac66f 20 {
Stevenor1997 2:cc30b42ac66f 21 if (vmm < MAXPOS)
Stevenor1997 2:cc30b42ac66f 22 return vmm*(MAXPULSE-MINPULSE)/MAXPOS +MINPULSE;
Stevenor1997 2:cc30b42ac66f 23 return MAXPULSE;
Stevenor1997 2:cc30b42ac66f 24 }
Stevenor1997 2:cc30b42ac66f 25 void Servo::SetZ(int _z)
Stevenor1997 2:cc30b42ac66f 26 {
Stevenor1997 2:cc30b42ac66f 27 z=_z;
Stevenor1997 2:cc30b42ac66f 28 mypwmZ.pulsewidth_us(mm2pulse(z));
Stevenor1997 2:cc30b42ac66f 29 }
Stevenor1997 2:cc30b42ac66f 30 void Servo::SetServo(int _x,int _y)
Stevenor1997 2:cc30b42ac66f 31 {
Stevenor1997 2:cc30b42ac66f 32 x=_x;
Stevenor1997 2:cc30b42ac66f 33 y=_y;
Stevenor1997 2:cc30b42ac66f 34 mypwmX.pulsewidth_us(mm2pulse(x));
Stevenor1997 2:cc30b42ac66f 35 mypwmY.pulsewidth_us(mm2pulse(y));
Stevenor1997 2:cc30b42ac66f 36 }
Stevenor1997 2:cc30b42ac66f 37 int Servo::GetServoX()
Stevenor1997 2:cc30b42ac66f 38 {
Stevenor1997 2:cc30b42ac66f 39 return x;
Stevenor1997 2:cc30b42ac66f 40 }
Stevenor1997 2:cc30b42ac66f 41 int Servo::GetServoY()
Stevenor1997 2:cc30b42ac66f 42 {
Stevenor1997 2:cc30b42ac66f 43 return y;
Stevenor1997 2:cc30b42ac66f 44 }
Stevenor1997 2:cc30b42ac66f 45 int Servo::GetServoZ()
Stevenor1997 2:cc30b42ac66f 46 {
Stevenor1997 2:cc30b42ac66f 47 return z;
Stevenor1997 2:cc30b42ac66f 48 }