sebastian martinez / Mbed 2 deprecated 01-04_Primer_Avance

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

mover.cpp

Committer:
sebasmartinez
Date:
2018-09-07
Revision:
3:60722da62531
Parent:
2:10956b8ceffb
Child:
4:ba51736778e1

File content as of revision 3:60722da62531:


#include "mover.h"
#include "mbed.h"
#include "math.h"


PwmOut Servo1(PA_1);
PwmOut Servo2(PB_8);
PwmOut Servo3(PB_14);
PwmOut Servo4(PB_15);
PwmOut Servo5(PA_8);
PwmOut Servo6(PB_6);
PwmOut Servo7(PA_9);
PwmOut Servo8(PA_10);


uint8_t  ss_time=50;     // tiempo  de espera para moverse 1 mm en microsegundos

void put_sstime(uint8_t vtime){
    ss_time=vtime;
    
}

int coord2us(float coord)
{
    if(0 <= coord <= MAXPOS)
        return int(500+coord*2000/180);// u6
    return 500;
/*
Secuencia 0, 180, 135, 90, 45, 0.
FF 01 01 00 FE FF 01 01 B4 FE FF 01 01 87 FE FF 01 01 5A FE FF 01 01 2D FE FF 01 01 00 FE
Grados: 180-B4, 135-87, 90-5A, 45-2D, 0-00;
*/
}


 


void mover_ser(uint8_t motor, uint8_t pos){

    int pulseX = coord2us(pos);

 switch ( motor ) {
  
  case 0x01: 
     Servo1.pulsewidth_us(pulseX);
    break;
  case 0x02: 
     Servo2.pulsewidth_us(pulseX);
    break;    
  case 0x03: 
     Servo3.pulsewidth_us(pulseX);
    break;
  case 0x04: 
     Servo4.pulsewidth_us(pulseX);
    break;
  case 0x05: 
     Servo5.pulsewidth_us(pulseX);
    break;
  case 0x06: 
     Servo6.pulsewidth_us(pulseX);
    break;
  case 0x07: 
     Servo7.pulsewidth_us(pulseX);
    break;   
  case 0x08: 
     Servo8.pulsewidth_us(pulseX);
    break;
            
  default: break;
}

}

void init_servo()
{
   Servo1.period_ms(20);
   Servo2.period_ms(20);
   Servo3.period_ms(20);
   Servo4.period_ms(20);
   Servo5.period_ms(20);
   Servo6.period_ms(20);
   Servo7.period_ms(20);
   Servo8.period_ms(20);
    
}