![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Control up to two motors using filtered EMG signals and a PID controller
Dependencies: FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics
Fork of Minor_test_serial by
main.cpp@9:5f0e796c9489, 2017-09-19 (annotated)
- Committer:
- tvlogman
- Date:
- Tue Sep 19 15:25:42 2017 +0000
- Revision:
- 9:5f0e796c9489
- Parent:
- 8:0067469c3389
- Child:
- 10:e23cbcdde7e3
Screwed it up nicely; Work in progress
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsluiter | 0:c8f15874531b | 1 | #include "mbed.h" |
vsluiter | 0:c8f15874531b | 2 | #include "MODSERIAL.h" |
tvlogman | 8:0067469c3389 | 3 | #include "HIDScope.h" |
tvlogman | 9:5f0e796c9489 | 4 | #include "QEI.h" |
tvlogman | 8:0067469c3389 | 5 | |
tvlogman | 8:0067469c3389 | 6 | HIDScope scope(2); |
tvlogman | 8:0067469c3389 | 7 | |
tvlogman | 8:0067469c3389 | 8 | Ticker AInTicker; |
tvlogman | 9:5f0e796c9489 | 9 | AnalogIn button1(A4); |
tvlogman | 8:0067469c3389 | 10 | |
tvlogman | 8:0067469c3389 | 11 | volatile float x; |
tvlogman | 8:0067469c3389 | 12 | volatile float x_prev =0; |
tvlogman | 8:0067469c3389 | 13 | volatile float y; // filtered 'output' of ReadAnalogInAndFilter |
tvlogman | 8:0067469c3389 | 14 | volatile float ledBrightness = 0.00; |
tvlogman | 8:0067469c3389 | 15 | |
tvlogman | 8:0067469c3389 | 16 | void ReadAnalogInAndFilter() |
tvlogman | 8:0067469c3389 | 17 | { |
tvlogman | 9:5f0e796c9489 | 18 | x = button1; // Capture data |
tvlogman | 8:0067469c3389 | 19 | scope.set(0, x); // store data in first element of scope memory |
tvlogman | 8:0067469c3389 | 20 | y = (x_prev + x)/2.0; // averaging filter |
tvlogman | 8:0067469c3389 | 21 | scope.set(1, y); // store data in second element of scope memory |
tvlogman | 8:0067469c3389 | 22 | x_prev = x; // Prepare for next round |
tvlogman | 8:0067469c3389 | 23 | |
tvlogman | 8:0067469c3389 | 24 | scope.send(); // send what's in scope memory to PC |
tvlogman | 8:0067469c3389 | 25 | } |
vsluiter | 0:c8f15874531b | 26 | |
tvlogman | 7:1bffab95fc5f | 27 | PwmOut ledPwm(D5); |
tvlogman | 7:1bffab95fc5f | 28 | float pwmPeriod = 1.0/5000.0; |
tvlogman | 7:1bffab95fc5f | 29 | |
tvlogman | 7:1bffab95fc5f | 30 | AnalogIn pot(A5); |
tvlogman | 9:5f0e796c9489 | 31 | |
tvlogman | 8:0067469c3389 | 32 | DigitalIn button2(D6); |
tvlogman | 8:0067469c3389 | 33 | |
tvlogman | 7:1bffab95fc5f | 34 | |
vsluiter | 0:c8f15874531b | 35 | MODSERIAL pc(USBTX, USBRX); |
vsluiter | 0:c8f15874531b | 36 | |
tvlogman | 7:1bffab95fc5f | 37 | |
vsluiter | 0:c8f15874531b | 38 | int main() |
vsluiter | 0:c8f15874531b | 39 | { |
tvlogman | 7:1bffab95fc5f | 40 | |
vsluiter | 0:c8f15874531b | 41 | pc.baud(115200); |
tvlogman | 8:0067469c3389 | 42 | AInTicker.attach(&ReadAnalogInAndFilter, 0.01); |
tvlogman | 7:1bffab95fc5f | 43 | ledPwm.period(pwmPeriod); |
tvlogman | 9:5f0e796c9489 | 44 | pc.printf("Hello world"); |
tvlogman | 9:5f0e796c9489 | 45 | int counts; |
tvlogman | 9:5f0e796c9489 | 46 | |
tvlogman | 9:5f0e796c9489 | 47 | QEI Encoder(D12,D13,NC,32); |
tvlogman | 7:1bffab95fc5f | 48 | |
vsluiter | 0:c8f15874531b | 49 | while (true) { |
tvlogman | 9:5f0e796c9489 | 50 | counts = Encoder.getPulses(); |
tvlogman | 9:5f0e796c9489 | 51 | pc.printf("Number of pulses is %i", counts); |
tvlogman | 9:5f0e796c9489 | 52 | wait(0.5); |
tvlogman | 7:1bffab95fc5f | 53 | |
vsluiter | 0:c8f15874531b | 54 | } |
tvlogman | 7:1bffab95fc5f | 55 | |
vsluiter | 0:c8f15874531b | 56 | } |