a

Dependents:   3servotest 1stcomp 3rdcompfixstart 2ndcomp ... more

Fork of Servo by Tk A

servo.cpp

Committer:
choutin
Date:
2016-09-17
Revision:
8:5a8a6a3b9f33
Parent:
7:919db47443f4

File content as of revision 8:5a8a6a3b9f33:

#include "mbed.h"

PwmOut pwmarm(PC_6);
PwmOut pwmhand(PC_8);
PwmOut pwmbelt(PC_9);
float PERIOD=20000;

const float btime=2.2;

void armdegree(int degree) {
    int i;

   pwmarm.period_ms(20);        //20ms
   
       degree=10;

       i=500+degree*1900/180;
       pwmarm.write(i/PERIOD); 
}

void handdegree(int degree) {
    int i;

   pwmarm.period_ms(20);        //20ms
   
       degree=10;

       i=500+degree*1900/180;
       pwmhand.write(i/PERIOD); 
       
}

void beltup(void){

   pwmarm.period_ms(20);        //20ms
       pwmbelt.write(0.028); 
       
}

void beltdown(void){

   pwmarm.period_ms(20);        //20ms
       pwmbelt.write(0.1); 
       
}


void beltstop(void){

   pwmarm.period_ms(20);        //20ms
    pwmbelt.write(0.073); 
       
}

void close_hand(void) {
     int i,degree;

    pwmhand.period_ms(20);        //20ms
    
        degree=137;

        i=500+degree*1900/180;
        pwmhand.write(i/PERIOD); 
        
        
}

void close_arm(void) {
    int i,degree;

   pwmarm.period_ms(20);        //20ms
   
       degree=170;

       i=500+degree*1900/180;
       pwmarm.write(i/PERIOD); 
       
       
}


void open_hand(void) {
    int i,degree;

   pwmhand.period_ms(20);        //20ms
   
       degree=83;

       i=500+degree*1900/180;
       pwmhand.write(i/PERIOD); 
       
       
}



void open_arm(void) {
    int i,degree;

   pwmarm.period_ms(20);        //20ms
   
       degree=30;

       i=500+degree*1900/180;
       pwmarm.write(i/PERIOD); 
       
       
}

void lift(){
    
beltup();
wait(btime);
beltstop();
    
}