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.
Diff: main.cpp
- Revision:
- 11:ed9539245ea0
- Parent:
- 8:2abfdbf5a3b8
- Child:
- 13:ab5a6ab6c492
- Child:
- 14:67a4e886387f
diff -r e7e98246ef58 -r ed9539245ea0 main.cpp --- a/main.cpp Fri Nov 11 21:25:31 2016 +0000 +++ b/main.cpp Mon Nov 14 20:57:21 2016 +0000 @@ -7,8 +7,8 @@ //QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING); //Use X2 encoding by default. QEI encoder (PTC16, PTC17, PTB9, 512); -Motor motor(PTC4, PTD0, PTC3, PTC12, PTB23, 1000); -Pot pend(PTC10); +Motor motor(PTC4, PTD0, PTC3, PTC12, PTB23, 2000); +Pot pend(PTC10,0); void test_distance(){ int wait = 1000; int steps = 100; @@ -40,16 +40,30 @@ } } -void test_speed(){ -} void test_pendulum(){ while(1){ printf("angle: %f \r\n", pend.get_angle()); } } +void calibrate_pendulum(){ + encoder.reset(); + while(1){ + printf("voltage %%: %f pulse: %i", pend.get_voltage(), encoder.getPulses()); + } +} +void move_pulses(int pulses){ // find number of pulses from the encoder going from one end to the other. + int start = encoder.getPulses(); + if(pulses >=0){ + while(encoder.getPulses() < start + pulses){ + motor.clockwise(); + } + }else{ + while(encoder.getPulses() > start + pulses) + motor.anticlockwise(); + } +} int main() { - test_pendulum(); //motor.step_clockwise(100,1500); //motor.step_clockwise(100,1000);