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

Servo_X.cpp

Committer:
Stevenor1997
Date:
2018-02-26
Revision:
2:cc30b42ac66f
Child:
3:07bcb3c9a8b8

File content as of revision 2:cc30b42ac66f:

#include "Servo_X.h"
#include "mbed.h"

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(MINPULSE);
    mypwmY.pulsewidth_us(MINPULSE);
    mypwmZ.pulsewidth_us(NODRAW);
    
}
Servo::~Servo(){
}
int Servo::mm2pulse(int vmm)
{
  if (vmm < MAXPOS)
    return vmm*(MAXPULSE-MINPULSE)/MAXPOS +MINPULSE;
  return MAXPULSE;   
}
void Servo::SetZ(int _z)
{
    z=_z;
    mypwmZ.pulsewidth_us(mm2pulse(z)); 
}
void Servo::SetServo(int _x,int _y)
{
    x=_x;
    y=_y;
    mypwmX.pulsewidth_us(mm2pulse(x));
    mypwmY.pulsewidth_us(mm2pulse(y));   
}
int Servo::GetServoX()
{
    return x;
}
int Servo::GetServoY()
{
    return y;
}
int Servo::GetServoZ()
{
    return z;
}