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@17:80316a7a917a, 2016-10-31 (annotated)
- Committer:
- LeeJon
- Date:
- Mon Oct 31 12:39:41 2016 +0000
- Revision:
- 17:80316a7a917a
- Parent:
- 13:0adbf6a5de37
- Child:
- 18:7178416f2db5
wordt nu gecomment
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 | |
LeeJon | 7:eed677b636d3 | 3 | PwmOut ServoPWMpin(D9); |
LeeJon | 8:aa03407660f1 | 4 | Timeout resetter; |
NahuelM | 4:e59a99c5aa08 | 5 | |
LeeJon | 8:aa03407660f1 | 6 | bool readtime = 1; |
NahuelM | 4:e59a99c5aa08 | 7 | double ServoAngle = 89 ; |
NahuelM | 4:e59a99c5aa08 | 8 | float Pulsew = 0.0015; |
LeeJon | 13:0adbf6a5de37 | 9 | double treshold = 0.6; |
NahuelM | 4:e59a99c5aa08 | 10 | bool binary_input_signal = 0; |
NahuelM | 4:e59a99c5aa08 | 11 | bool binary_input_signal_previous = 0; |
NahuelM | 4:e59a99c5aa08 | 12 | |
LeeJon | 8:aa03407660f1 | 13 | void set21(){ |
LeeJon | 8:aa03407660f1 | 14 | readtime = 1; |
LeeJon | 8:aa03407660f1 | 15 | } |
LeeJon | 8:aa03407660f1 | 16 | |
LeeJon | 5:bb77e2a6c1e8 | 17 | void control_servo(double input_signal){ |
NahuelM | 4:e59a99c5aa08 | 18 | if (input_signal > treshold){ // convert the emg to a zero or a one |
NahuelM | 4:e59a99c5aa08 | 19 | binary_input_signal = 1; |
NahuelM | 4:e59a99c5aa08 | 20 | } else { |
NahuelM | 4:e59a99c5aa08 | 21 | binary_input_signal = 0; |
NahuelM | 4:e59a99c5aa08 | 22 | } |
LeeJon | 8:aa03407660f1 | 23 | if((( binary_input_signal!= binary_input_signal_previous)&& binary_input_signal)&& readtime){ |
LeeJon | 8:aa03407660f1 | 24 | readtime = 0; |
LeeJon | 8:aa03407660f1 | 25 | resetter.attach(&set21, 1); |
NahuelM | 4:e59a99c5aa08 | 26 | if( ServoAngle < 45){ // check wether it is more opened or closed |
NahuelM | 4:e59a99c5aa08 | 27 | ServoAngle = 89; // open |
NahuelM | 4:e59a99c5aa08 | 28 | } |
NahuelM | 4:e59a99c5aa08 | 29 | else{ |
NahuelM | 4:e59a99c5aa08 | 30 | ServoAngle = 1; // close |
NahuelM | 4:e59a99c5aa08 | 31 | } |
NahuelM | 4:e59a99c5aa08 | 32 | } |
NahuelM | 4:e59a99c5aa08 | 33 | Pulsew = 0.0015+(ServoAngle)/180000; // calculate the pulsewidth in the range 1 to 2 milliseconds |
NahuelM | 4:e59a99c5aa08 | 34 | ServoPWMpin.pulsewidth(Pulsew); // write the pulsewidth |
NahuelM | 4:e59a99c5aa08 | 35 | |
NahuelM | 4:e59a99c5aa08 | 36 | binary_input_signal_previous = binary_input_signal; |
LeeJon | 7:eed677b636d3 | 37 | } |