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.
main.cpp@8:2abfdbf5a3b8, 2016-11-11 (annotated)
- Committer:
- dlweakley
- Date:
- Fri Nov 11 21:19:06 2016 +0000
- Revision:
- 8:2abfdbf5a3b8
- Parent:
- 6:8d2171811f14
- Child:
- 11:ed9539245ea0
test methods and angle class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Snay22 | 5:74fcd196ff96 | 1 | #include "QEI.h" |
dlweakley | 6:8d2171811f14 | 2 | #include "Motor.h" |
dlweakley | 8:2abfdbf5a3b8 | 3 | #include "pot.h" |
dlweakley | 4:41bbbaecd322 | 4 | |
Snay22 | 5:74fcd196ff96 | 5 | Serial pc(USBTX, USBRX); |
Snay22 | 5:74fcd196ff96 | 6 | //Use X4 encoding. |
Snay22 | 5:74fcd196ff96 | 7 | //QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING); |
Snay22 | 5:74fcd196ff96 | 8 | //Use X2 encoding by default. |
dlweakley | 8:2abfdbf5a3b8 | 9 | QEI encoder (PTC16, PTC17, PTB9, 512); |
dlweakley | 8:2abfdbf5a3b8 | 10 | Motor motor(PTC4, PTD0, PTC3, PTC12, PTB23, 1000); |
dlweakley | 8:2abfdbf5a3b8 | 11 | Pot pend(PTC10); |
dlweakley | 8:2abfdbf5a3b8 | 12 | void test_distance(){ |
dlweakley | 8:2abfdbf5a3b8 | 13 | int wait = 1000; |
dlweakley | 8:2abfdbf5a3b8 | 14 | int steps = 100; |
dlweakley | 8:2abfdbf5a3b8 | 15 | while (wait > 500){ |
dlweakley | 8:2abfdbf5a3b8 | 16 | while (steps > 10){ |
dlweakley | 8:2abfdbf5a3b8 | 17 | printf("steps: %i wait: %i \r\n", steps, wait); |
dlweakley | 8:2abfdbf5a3b8 | 18 | for( int i = 0; i < 3; i++){ |
dlweakley | 8:2abfdbf5a3b8 | 19 | encoder.reset(); |
dlweakley | 8:2abfdbf5a3b8 | 20 | motor.step_clockwise(steps, wait); |
dlweakley | 8:2abfdbf5a3b8 | 21 | int pulses_cw = encoder.getPulses(); |
dlweakley | 8:2abfdbf5a3b8 | 22 | wait_ms(200); |
dlweakley | 8:2abfdbf5a3b8 | 23 | int coast_pulses_cw = encoder.getPulses(); |
dlweakley | 8:2abfdbf5a3b8 | 24 | |
dlweakley | 8:2abfdbf5a3b8 | 25 | |
dlweakley | 8:2abfdbf5a3b8 | 26 | encoder.reset(); |
dlweakley | 8:2abfdbf5a3b8 | 27 | motor.step_anticlockwise(steps, wait); |
dlweakley | 8:2abfdbf5a3b8 | 28 | int pulses_ccw = encoder.getPulses(); |
dlweakley | 8:2abfdbf5a3b8 | 29 | wait_ms(200); |
dlweakley | 8:2abfdbf5a3b8 | 30 | int coast_pulses_ccw = encoder.getPulses(); |
dlweakley | 8:2abfdbf5a3b8 | 31 | printf("trial: %i \tclockwise pluses: \t%i \tanticlockwise pluses: \t%i \r\n", i + 1, pulses_cw, pulses_ccw); |
dlweakley | 8:2abfdbf5a3b8 | 32 | printf("\t\tpulses after coast: \t%i \tpulses after coast: \t%i\r\n", coast_pulses_cw, coast_pulses_ccw); |
dlweakley | 8:2abfdbf5a3b8 | 33 | } |
dlweakley | 8:2abfdbf5a3b8 | 34 | steps -=10; |
dlweakley | 8:2abfdbf5a3b8 | 35 | printf("\r\n"); |
dlweakley | 8:2abfdbf5a3b8 | 36 | } |
dlweakley | 8:2abfdbf5a3b8 | 37 | |
dlweakley | 8:2abfdbf5a3b8 | 38 | wait-=100; |
dlweakley | 8:2abfdbf5a3b8 | 39 | steps=100; |
dlweakley | 8:2abfdbf5a3b8 | 40 | } |
dlweakley | 8:2abfdbf5a3b8 | 41 | } |
dlweakley | 6:8d2171811f14 | 42 | |
dlweakley | 8:2abfdbf5a3b8 | 43 | void test_speed(){ |
dlweakley | 8:2abfdbf5a3b8 | 44 | |
dlweakley | 8:2abfdbf5a3b8 | 45 | } |
dlweakley | 8:2abfdbf5a3b8 | 46 | void test_pendulum(){ |
Snay22 | 5:74fcd196ff96 | 47 | while(1){ |
dlweakley | 8:2abfdbf5a3b8 | 48 | printf("angle: %f \r\n", pend.get_angle()); |
Snay22 | 0:44fc57e03a56 | 49 | } |
dlweakley | 8:2abfdbf5a3b8 | 50 | } |
dlweakley | 8:2abfdbf5a3b8 | 51 | int main() { |
dlweakley | 8:2abfdbf5a3b8 | 52 | |
dlweakley | 8:2abfdbf5a3b8 | 53 | test_pendulum(); |
dlweakley | 8:2abfdbf5a3b8 | 54 | //motor.step_clockwise(100,1500); |
dlweakley | 8:2abfdbf5a3b8 | 55 | //motor.step_clockwise(100,1000); |
dlweakley | 8:2abfdbf5a3b8 | 56 | //motor.step_clockwise(100,700); |
dlweakley | 8:2abfdbf5a3b8 | 57 | |
dlweakley | 8:2abfdbf5a3b8 | 58 | |
Snay22 | 5:74fcd196ff96 | 59 | |
dlweakley | 8:2abfdbf5a3b8 | 60 | } |