Harrison Kubena
/
ES306_Motor
a
main.cpp
- Committer:
- m193516
- Date:
- 2017-11-06
- Revision:
- 0:40605c19e1a6
- Child:
- 1:ca98a3ae7a70
File content as of revision 0:40605c19e1a6:
/* Harrison Kubena and Rav Dhingra ES305 Lab 1 - Motor Ticker 27 August 2017 */ #include "mbed.h" #include "mbedWSEsbc.h" #define PI (3.14159) //declare objects Ticker Controller; //declare ticker obj //declare variables float TotalTime; float Time; float Tsamp = 0.0083; float Tstream = 0.01; float userDC; float ang, angp, speed; float dc; float enc1; float lowDC; void ctrCode(); void twoStepCode(); //enter main int main() { //init mbed mbedWSEsbcInit(115200); mot_en1.period(0.020); while(1) { pc.scanf("%f,%f", &TotalTime, &lowDC); Time = 0.0; t.reset(); Controller.attach(&twoStepCode,Tsamp); t.start(); //data streaming while(Time <= TotalTime) { Time = t.read(); pc.printf("%f, %f, %f\n", Time, speed, dc); wait(Tstream); } Controller.detach(); mot_control(1,0.0); } } // additional function definitions void ctrCode() { //read encoder enc1 = LS7366_read_counter(1); //convert counts to rads ang = 2.0*PI*enc1/6400.0; //estimate speed speed = (ang-angp)/Tsamp; //age variables angp = ang; //compute duty cycle dc = userDC; //send the duty cycle to motor mot_control(1,dc); } void twoStepCode() { //read encoder enc1 = LS7366_read_counter(1); //convert counts to rads ang = 2.0*PI*enc1/6400.0; //estimate speed speed = (ang-angp)/Tsamp; //age variables angp = ang; //compute duty cycle if(Time<0.1){ dc = 0.0; } else if(Time<0.55){ dc = lowDC; } else { dc = 0.10; } //send the duty cycle to motor mot_control(1,dc); }