sebastian martinez / Mbed 2 deprecated Movimiento_8Servos

Dependencies:   mbed

Fork of 01-04_Primer_Avance by sebastian martinez

mover.cpp

Committer:
sebasmartinez
Date:
2018-09-06
Revision:
2:10956b8ceffb
Parent:
1:526bdd5faa37
Child:
3:60722da62531

File content as of revision 2:10956b8ceffb:


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


PwmOut Servo1(PA_11);
PwmOut Servo2(PA_11);
PwmOut Servo3(PA_11);
PwmOut Servo4(PA_11);
PwmOut Servo5(PA_11);
PwmOut Servo6(PA_11);
PwmOut Servo7(PA_11);
PwmOut Servo8(PA_11);


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(750+coord*1900/50);// u6
    return 750;

}


 


void mover_ser(uint8_t motor, uint8_t pos){

    //int pulseX = coord2us(pos);
    int pulseX = 900;
    int pulseY = 1900;
   // myServo1.pulsewidth_us(pulseX);
 switch ( motor ) {
  
  case 0x01: 
     Servo1.pulsewidth_us(pulseX);
    break;
  case 0x02: 
     Servo2.pulsewidth_us(pulseY);
    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);
    
}