Library version for DC_Stepper_Controller_Lib with PWM speed control

Dependencies:   mbed QEI PID

Dependents:   DR-ArmServoTest Auto_DC_pick_class MBed_TR1 ros_button_2021

sample_main.cpp

Committer:
stivending
Date:
2021-05-31
Revision:
15:87df75ee8731
Parent:
14:c9611cf036ad

File content as of revision 15:87df75ee8731:

/*******************************************************
              DC MODOR CONTROLLER LIBRARY
 *******************************************************           
         IMPORTANT: GO TO README FOR DOCUMENT!
********************************************************/

#include "mbed.h"
#include "QEI.h"
#include "DC_Motor_Controller.h"


DC_Motor_PID motor(D6,D3,D4,D5,792); //M1, M2, INA, INB, PPR 
DigitalIn but(D9);

// angle = 412 degree to move from one to another
// angle = 100 degree to

int main() {
    
    motor.set_pid(0.008, 0, 0, 0.10);
    
    Serial pc(USBTX, USBRX);  // tx, rx
    pc.baud(9600);
    
    but.mode(PullDown);
    
    while(1){
    
    wait(0.5);motor.set_out(0.4,0);
    /*while(1)
    {
            if(but) {motor.set_out(0.4,0); pc.printf("\nbegin: %d \n", motor.get_pulse()); break;}
    }
    
    wait(2);
    */while(1)
    {
            if(but) { motor.set_out(0,0); pc.printf("\nend: %d \n", motor.get_pulse()); break;}
    }
    
    wait(0.5);
    motor.reset();
    wait(0.5);
    motor.move_angle(615);
    wait(2);
    
    motor.move_angle(412); // speed, 0 to 1
    wait(2);
    motor.move_angle(412); // speed, 0 to 1
    wait(2);
    motor.move_angle(412); // speed, 0 to 1
    wait(2);
    motor.move_angle(412); // speed, 0 to 1
    wait(2);
    motor.move_angle(120); // speed, 0 to 1
    wait(2);
    }
    
}