LED toggle
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL Encoder FastPWM
Diff: main.cpp
- Revision:
- 5:532b9a72e012
- Parent:
- 4:bb9bcbb22882
- Child:
- 6:81dda0c8eb71
--- a/main.cpp Mon Oct 07 09:32:26 2019 +0000 +++ b/main.cpp Mon Oct 07 13:06:33 2019 +0000 @@ -12,10 +12,9 @@ DigitalOut motor1_dir(D4); AnalogIn pod1(A0); AnalogIn pod2(A1); - - Ticker measure; +//Initial parameters control int m1_count; float m1_angle; float pi = 3.14; @@ -25,6 +24,44 @@ float motor1_er; float motor1_pwm_signal; +//initial parameters time and HIDSCOPE +volatile float theoretical_time = 0; +static int frequency_theoretical_time = 20; +static float duration_theoretical_time = (1/(float)frequency_theoretical_time); +Ticker sample_timer; //HIDSCOPE ticker, deze is langzamer dan en in periode met measure, + //deze frequentie is frequency_time +HIDScope scope( 2 ); //2 ingangen + +/** Sample function + * this function samples the emg and sends it to HIDScope + **/ +void sample() +{ + /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ + scope.set(0, m1_count ); + scope.set(1, theoretical_time); + /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) + * Ensure that enough channels are available (HIDScope scope( 2 )) + * Finally, send all channels to the PC at once */ + scope.send(); + /* To indicate that the function is working, the LED is toggled */ + //led = !led; suppressed for now +} + +/** Theoretical time function +*This function calculates time based on sample numbers and frequency +**/ +void theoretical_time_fun(){ +theoretical_time = theoretical_time + duration_theoretical_time; //increment by 1 second +} +void StepResponse(){ +theoretical_time_fun(); +sample(); +} + +/** Counter function +* this functions counts the encoder for position referene +**/ void getCounts(){ m1_count = motor1.getPulses(); m1_angle = (float)m1_count / 4200.0f * (2.0f * pi); @@ -64,6 +101,7 @@ motor1_pwm.period(1.0/10000); motor1_dir = 0; measure.attach(MeasureandControl,0.01); + sample_timer.attach(StepResponse,duration_theoretical_time); while(true){ pc.printf("\r\nMotor angle: %f Pod1 angle: %f K_p: %f Error: %f",m1_angle,pod1_angle,motor1_pwm_signal,motor1_er); wait(0.8);