![](/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@13:83e3672b24ee, 2017-09-21 (annotated)
- Committer:
- tvlogman
- Date:
- Thu Sep 21 09:29:19 2017 +0000
- Revision:
- 13:83e3672b24ee
- Parent:
- 12:0462757e1ed2
- Child:
- 14:664870b5d153
Motor works
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 | 12:0462757e1ed2 | 6 | QEI Encoder(D12,D13,NC,64, QEI::X4_ENCODING); |
tvlogman | 10:e23cbcdde7e3 | 7 | MODSERIAL pc(USBTX, USBRX); |
tvlogman | 8:0067469c3389 | 8 | |
tvlogman | 13:83e3672b24ee | 9 | DigitalOut motor1_direction(D4); |
tvlogman | 13:83e3672b24ee | 10 | PwmOut motor1_pwm(D5); |
tvlogman | 13:83e3672b24ee | 11 | float pwmPeriod = 1.0/5000.0; |
tvlogman | 13:83e3672b24ee | 12 | |
tvlogman | 10:e23cbcdde7e3 | 13 | Ticker encoderTicker; |
tvlogman | 10:e23cbcdde7e3 | 14 | volatile int counts = 0; |
tvlogman | 12:0462757e1ed2 | 15 | volatile float revs = 0.00; |
tvlogman | 7:1bffab95fc5f | 16 | |
tvlogman | 10:e23cbcdde7e3 | 17 | void readEncoder(){ |
tvlogman | 10:e23cbcdde7e3 | 18 | counts = Encoder.getPulses(); |
tvlogman | 12:0462757e1ed2 | 19 | revs = counts/64.0f; |
tvlogman | 12:0462757e1ed2 | 20 | pc.printf("%i pulses \r\n", counts); |
tvlogman | 12:0462757e1ed2 | 21 | pc.printf("%f revolutions \r\n", revs); |
tvlogman | 10:e23cbcdde7e3 | 22 | } |
vsluiter | 0:c8f15874531b | 23 | |
tvlogman | 13:83e3672b24ee | 24 | int frequency_pwm = 10000; //10kHz PWM |
tvlogman | 13:83e3672b24ee | 25 | |
tvlogman | 7:1bffab95fc5f | 26 | |
vsluiter | 0:c8f15874531b | 27 | int main() |
tvlogman | 10:e23cbcdde7e3 | 28 | { |
tvlogman | 13:83e3672b24ee | 29 | motor1_direction = true; |
tvlogman | 13:83e3672b24ee | 30 | motor1_pwm.period(pwmPeriod);//T=1/f |
tvlogman | 13:83e3672b24ee | 31 | |
vsluiter | 0:c8f15874531b | 32 | pc.baud(115200); |
tvlogman | 12:0462757e1ed2 | 33 | encoderTicker.attach(readEncoder, 1.0); |
tvlogman | 10:e23cbcdde7e3 | 34 | pc.printf("Encoder ticker attached and baudrate set"); |
tvlogman | 13:83e3672b24ee | 35 | |
tvlogman | 13:83e3672b24ee | 36 | |
tvlogman | 13:83e3672b24ee | 37 | while(true){ |
tvlogman | 13:83e3672b24ee | 38 | for(int i = 0 ; i<=30 ; i= i+10) |
tvlogman | 13:83e3672b24ee | 39 | { |
tvlogman | 13:83e3672b24ee | 40 | motor1_pwm.write(i/100.0);//write Duty Cycle |
tvlogman | 13:83e3672b24ee | 41 | } |
tvlogman | 13:83e3672b24ee | 42 | } |
tvlogman | 11:d1692be2de30 | 43 | |
vsluiter | 0:c8f15874531b | 44 | } |
tvlogman | 7:1bffab95fc5f | 45 |