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-26
Revision:
12:3949fd23be49
Parent:
11:e880912260b5
Child:
13:675456f1f401

File content as of revision 12:3949fd23be49:

/*******************************************************
              DC MODOR CONTROLLER LIBRARY
 *******************************************************           
 Important:
 1) Enable / Disable DEBUG_MODE in DC_Motor_controller.cpp 
    (DEBUG_MODE affects accuracy in control!!!)
 2) If compliation issue occurs, DELETE this file. 
********************************************************/

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


DC_Motor_Controller 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.reset();
    
    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, 0.5); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(412, 0.5); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(412, 0.5); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(412, 0.5); // speed, 0 to 1
    wait(0.5);
    motor.move_angle(120, 0.5); // speed, 0 to 1
    
}