Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope QEI biquadFilter mbed
Fork of EMG_Controller_5 by
servoController.h@7:eed677b636d3, 2016-10-25 (annotated)
- Committer:
- LeeJon
- Date:
- Tue Oct 25 12:35:29 2016 +0000
- Revision:
- 7:eed677b636d3
- Parent:
- 6:6cb7c0247560
- Child:
- 8:aa03407660f1
opgeruimdere versie
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NahuelM | 4:e59a99c5aa08 | 1 | #include "mbed.h" |
NahuelM | 4:e59a99c5aa08 | 2 | |
NahuelM | 4:e59a99c5aa08 | 3 | Serial pc(USBTX,USBRX); |
LeeJon | 7:eed677b636d3 | 4 | PwmOut ServoPWMpin(D9); |
NahuelM | 4:e59a99c5aa08 | 5 | |
NahuelM | 4:e59a99c5aa08 | 6 | double ServoAngle = 89 ; |
NahuelM | 4:e59a99c5aa08 | 7 | float Pulsew = 0.0015; |
pbaardwijk | 6:6cb7c0247560 | 8 | double treshold = 0.3; |
NahuelM | 4:e59a99c5aa08 | 9 | bool binary_input_signal = 0; |
NahuelM | 4:e59a99c5aa08 | 10 | bool binary_input_signal_previous = 0; |
NahuelM | 4:e59a99c5aa08 | 11 | |
LeeJon | 5:bb77e2a6c1e8 | 12 | void control_servo(double input_signal){ |
pbaardwijk | 6:6cb7c0247560 | 13 | pc.printf("/n/r %f", input_signal); |
NahuelM | 4:e59a99c5aa08 | 14 | if (input_signal > treshold){ // convert the emg to a zero or a one |
NahuelM | 4:e59a99c5aa08 | 15 | binary_input_signal = 1; |
NahuelM | 4:e59a99c5aa08 | 16 | } else { |
NahuelM | 4:e59a99c5aa08 | 17 | binary_input_signal = 0; |
NahuelM | 4:e59a99c5aa08 | 18 | } |
NahuelM | 4:e59a99c5aa08 | 19 | if(( binary_input_signal!= binary_input_signal_previous)&& binary_input_signal){ |
NahuelM | 4:e59a99c5aa08 | 20 | if( ServoAngle < 45){ // check wether it is more opened or closed |
NahuelM | 4:e59a99c5aa08 | 21 | ServoAngle = 89; // open |
NahuelM | 4:e59a99c5aa08 | 22 | } |
NahuelM | 4:e59a99c5aa08 | 23 | else{ |
NahuelM | 4:e59a99c5aa08 | 24 | ServoAngle = 1; // close |
NahuelM | 4:e59a99c5aa08 | 25 | } |
NahuelM | 4:e59a99c5aa08 | 26 | } |
NahuelM | 4:e59a99c5aa08 | 27 | Pulsew = 0.0015+(ServoAngle)/180000; // calculate the pulsewidth in the range 1 to 2 milliseconds |
NahuelM | 4:e59a99c5aa08 | 28 | ServoPWMpin.pulsewidth(Pulsew); // write the pulsewidth |
NahuelM | 4:e59a99c5aa08 | 29 | pc.printf("\n\r Pulsew is %f",Pulsew); |
NahuelM | 4:e59a99c5aa08 | 30 | |
NahuelM | 4:e59a99c5aa08 | 31 | binary_input_signal_previous = binary_input_signal; |
LeeJon | 7:eed677b636d3 | 32 | } |