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@11:c8b6a2b314c3, 2016-10-27 (annotated)
- Committer:
- NahuelM
- Date:
- Thu Oct 27 14:10:49 2016 +0000
- Revision:
- 11:c8b6a2b314c3
- Parent:
- 8:aa03407660f1
- Child:
- 13:0adbf6a5de37
Filter in controller ingebouwd, kapot
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); |
LeeJon | 8:aa03407660f1 | 5 | Timeout resetter; |
NahuelM | 4:e59a99c5aa08 | 6 | |
LeeJon | 8:aa03407660f1 | 7 | bool readtime = 1; |
NahuelM | 4:e59a99c5aa08 | 8 | double ServoAngle = 89 ; |
NahuelM | 4:e59a99c5aa08 | 9 | float Pulsew = 0.0015; |
pbaardwijk | 6:6cb7c0247560 | 10 | double treshold = 0.3; |
NahuelM | 4:e59a99c5aa08 | 11 | bool binary_input_signal = 0; |
NahuelM | 4:e59a99c5aa08 | 12 | bool binary_input_signal_previous = 0; |
NahuelM | 4:e59a99c5aa08 | 13 | |
LeeJon | 8:aa03407660f1 | 14 | void set21(){ |
LeeJon | 8:aa03407660f1 | 15 | readtime = 1; |
LeeJon | 8:aa03407660f1 | 16 | } |
LeeJon | 8:aa03407660f1 | 17 | |
LeeJon | 5:bb77e2a6c1e8 | 18 | void control_servo(double input_signal){ |
NahuelM | 11:c8b6a2b314c3 | 19 | //pc.printf("/n/r %f", input_signal); |
NahuelM | 4:e59a99c5aa08 | 20 | if (input_signal > treshold){ // convert the emg to a zero or a one |
NahuelM | 4:e59a99c5aa08 | 21 | binary_input_signal = 1; |
NahuelM | 4:e59a99c5aa08 | 22 | } else { |
NahuelM | 4:e59a99c5aa08 | 23 | binary_input_signal = 0; |
NahuelM | 4:e59a99c5aa08 | 24 | } |
LeeJon | 8:aa03407660f1 | 25 | if((( binary_input_signal!= binary_input_signal_previous)&& binary_input_signal)&& readtime){ |
LeeJon | 8:aa03407660f1 | 26 | readtime = 0; |
LeeJon | 8:aa03407660f1 | 27 | resetter.attach(&set21, 1); |
NahuelM | 4:e59a99c5aa08 | 28 | if( ServoAngle < 45){ // check wether it is more opened or closed |
NahuelM | 4:e59a99c5aa08 | 29 | ServoAngle = 89; // open |
NahuelM | 4:e59a99c5aa08 | 30 | } |
NahuelM | 4:e59a99c5aa08 | 31 | else{ |
NahuelM | 4:e59a99c5aa08 | 32 | ServoAngle = 1; // close |
NahuelM | 4:e59a99c5aa08 | 33 | } |
NahuelM | 4:e59a99c5aa08 | 34 | } |
NahuelM | 4:e59a99c5aa08 | 35 | Pulsew = 0.0015+(ServoAngle)/180000; // calculate the pulsewidth in the range 1 to 2 milliseconds |
NahuelM | 4:e59a99c5aa08 | 36 | ServoPWMpin.pulsewidth(Pulsew); // write the pulsewidth |
NahuelM | 11:c8b6a2b314c3 | 37 | //pc.printf("\n\r Pulsew is %f",Pulsew); |
NahuelM | 4:e59a99c5aa08 | 38 | |
NahuelM | 4:e59a99c5aa08 | 39 | binary_input_signal_previous = binary_input_signal; |
LeeJon | 7:eed677b636d3 | 40 | } |