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-27
Revision:
13:675456f1f401
Parent:
12:3949fd23be49
Child:
14:c9611cf036ad

File content as of revision 13:675456f1f401:

/*******************************************************
              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(USER_BUTTON);

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

int main() {
    
    motor.set_pid(0.008, 0, 0);
    
    Serial pc(USBTX, USBRX);  // tx, rx
    pc.baud(9600);
    
    while(1)
    {

        while(!pc.readable())
            if(but) { motor.set_out(0,0); pc.printf("\n now: %d \n", motor.get_pulse()); break;}
        if(pc.readable()) {
            if(pc.getc() == '1') motor.set_out(0.6,0);
            else if(pc.getc() == '2') motor.set_out(0,0.6);
        }
        else break;
    }
    
    /*
    motor.set_out(1,0);
    wait(5);
    motor.set_out(0,1);
    wait(5);
    */
    wait(0.5);
    motor.move_angle(412); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(-412); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(412); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(412); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(120); // speed, 0 to 1
    
}