Matthew Hall
/
es305_hall_lab2
g
Revision 0:c5257a56d3c7, committed 2017-11-05
- Comitter:
- matthewhall115
- Date:
- Sun Nov 05 19:25:12 2017 +0000
- Commit message:
- nothing
Changed in this revision
diff -r 000000000000 -r c5257a56d3c7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Nov 05 19:25:12 2017 +0000 @@ -0,0 +1,77 @@ +#include "mbed.h" +#include "mbedWSEsbc.h" +#define PI (3.14159) + +//Declare objects (if necessary) +Ticker Controller; //declare Ticker object name "Controller" + +//variables for data handling and storage +float TotalTime; //Total run time +float Time; //Current elapsed time +float Ts=0.0083; //Control update period (seconds) (100Hz equivalent) +float Tstrm=0.01; //Data streaming period (seconds) (50Hz equivalent) +float usrDC; //user-specified duty cycle +float speed; +float ang; +float angp; +float dc; +float enc1; + + + + +//Function definition Prototypes (declaration) +void ctrCode(); //declare that a separate (other than main) function named "ctrCode" exists + +//main function +int main () +{ + //Initialize mbed to access functionality of encoder, A/D, driver, etc. chipsets + //Input is baud rate for PC communication + mbedWSEsbcInit(115200); //also intializes timer oject t + mot_en1.period(0.020); //sets PWM period to 0.02 seconds for best DC motor operation + + while(1) { + + //Scan serial port for user input to begin experiment + pc.scanf("%f,%f",&TotalTime,&usrDC); + //perform necessary functions to time the experiment + Time=0.0; //reset time variable + t.reset(); // reset time object + +//Attached the ctrCode function to ticker oject specified with period Ts + Controller.attach(&ctrCode,Ts); + + t.start(); //start measuring elapsed time + + //perform operations while the elapsed time is less than the desired total time + while(Time <= TotalTime) { + + //read current elapsed time + Time= t.read(); + + //send data over serial port + pc.printf("%f,%f,%f\n",Time,speed,usrDC); + + + wait(Tstrm); //print data at approximately 50 Hz + + } // end while(Time<=Ttime) + + Controller.detach(); // detach ticker to turn off controller + mot_control(1,0.0);//Turn motor off at end of experiment + + }//end while(1) +}// end main + +//aditional function definitions +void ctrCode() //fuction to attach to ticker +{ + enc1=LS7366_read_counter(1); + ang = 2*PI*enc1/6500;//convert to radians + speed = (ang - angp)/Ts;//estimate speed + angp = ang;//age variables + dc = usrDC;//compute duty cycle + mot_control(1,dc);//send duty cycle to moto + +} \ No newline at end of file
diff -r 000000000000 -r c5257a56d3c7 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Nov 05 19:25:12 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file
diff -r 000000000000 -r c5257a56d3c7 mbedWSEsbc.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbedWSEsbc.lib Sun Nov 05 19:25:12 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/jebradshaw/code/mbedWSEsbc/#2564f54c89df