![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
a
Diff: main.cpp
- Revision:
- 0:980f29af9da6
- Child:
- 1:da8fb81386ab
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 14 05:55:46 2018 +0000 @@ -0,0 +1,70 @@ +#include "mbed.h" +#include "mbedWSEsbc.h" +#define PI (3.14159) + +float trt; // Total run time +float cet; // Current elapsed time +float updateperiod = 0.0083; // Control update period (seconds) (120 Hz equivalent) +float dsp = 0.01; // Data streaming period (seconds) (100 Hz equivalent) +//float ang,angp,speed; // variables for approximating speed from encoder measurements +//float DCAmp; // duty cycle applied to motor +float dc; // duty cycle +//long enc1; // encoder variable +float parameter; +float speed; +float DCAmp; +float measurement; +float rad; +float rad_old; + +Ticker Controller; + +void ctrCode (); +void StepCode(); + +int main() { + mbedWSEsbcInit(115200); + mot_en1.period(.020); + + while(1) { + pc.scanf("%f,%f",&trt,&DCAmp); + cet = 0; + t.reset(); + Controller.attach(&StepCode,updateperiod); + t.start(); + while (cet <= trt){ + pc.printf("%f,%f,%f\n",cet,speed,dc); + wait(dsp); + + } + Controller.detach(); + mot_control(1,0.0); + } + } + void ctrCode() { + cet=t.read(); + measurement= LS7366_read_counter(1); + rad = (2.0*PI)/6500*measurement; + speed = (rad - rad_old)/updateperiod; + rad_old = rad; + + dc = SineAmp*sin(2.0*PI*cet/5.0); + mot_control(1,dc); + } + + void StepCode() { + cet=t.read(); + measurement = LS7366_read_counter(1); + rad = (2.0*PI)/6500*measurement; + speed = (rad - rad_old)/updateperiod; + rad_old = rad; + + if(cet<0.1){ + dc = 0.0; + } else{ + dc = SineAmp; + } + mot_control(1,dc); + } + + \ No newline at end of file