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.
control.cpp@4:48d390356fba, 2018-02-22 (annotated)
- Committer:
- Weranest
- Date:
- Thu Feb 22 17:01:00 2018 +0000
- Revision:
- 4:48d390356fba
Tech Demo version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Weranest | 4:48d390356fba | 1 | #include "mbed.h" |
Weranest | 4:48d390356fba | 2 | #include "pwm.h" |
Weranest | 4:48d390356fba | 3 | #include "pins.h" |
Weranest | 4:48d390356fba | 4 | #include "constants.cpp" |
Weranest | 4:48d390356fba | 5 | #include "C12832.h" |
Weranest | 4:48d390356fba | 6 | #include "encoderBase.h" |
Weranest | 4:48d390356fba | 7 | |
Weranest | 4:48d390356fba | 8 | void buggyGoLeft(); |
Weranest | 4:48d390356fba | 9 | void buggyGoF(); |
Weranest | 4:48d390356fba | 10 | void buggyGoRight(); |
Weranest | 4:48d390356fba | 11 | void buggyStop(); |
Weranest | 4:48d390356fba | 12 | |
Weranest | 4:48d390356fba | 13 | void controlAutomatic(int flag){ //this is a showoff version |
Weranest | 4:48d390356fba | 14 | while(flag==1){ |
Weranest | 4:48d390356fba | 15 | wait(0.5); |
Weranest | 4:48d390356fba | 16 | buggyGoF(); |
Weranest | 4:48d390356fba | 17 | wait(2); |
Weranest | 4:48d390356fba | 18 | buggyGoLeft(); |
Weranest | 4:48d390356fba | 19 | wait(2); |
Weranest | 4:48d390356fba | 20 | buggyGoRight(); |
Weranest | 4:48d390356fba | 21 | wait(2); |
Weranest | 4:48d390356fba | 22 | buggyStop(); |
Weranest | 4:48d390356fba | 23 | } |
Weranest | 4:48d390356fba | 24 | } |
Weranest | 4:48d390356fba | 25 | void controlManual(int flag){ |
Weranest | 4:48d390356fba | 26 | while (1){ //this function is for manual wheel turnage using the potentiometers. Knock yourself out |
Weranest | 4:48d390356fba | 27 | while(1){ |
Weranest | 4:48d390356fba | 28 | if(joystickDown!=0) break; |
Weranest | 4:48d390356fba | 29 | |
Weranest | 4:48d390356fba | 30 | float rightPWM= (float)potentiometerRight.read() ; |
Weranest | 4:48d390356fba | 31 | float leftPWM= (float)potentiometerLeft.read(); |
Weranest | 4:48d390356fba | 32 | lcd.locate(0,3); |
Weranest | 4:48d390356fba | 33 | lcd.printf("L=%d; R=%d", encoderVelocityLeft(), encoderVelocityRight()); |
Weranest | 4:48d390356fba | 34 | //wait(2); |
Weranest | 4:48d390356fba | 35 | lcd.cls(); |
Weranest | 4:48d390356fba | 36 | buggyPWM(leftPWM ,rightPWM); |
Weranest | 4:48d390356fba | 37 | } |
Weranest | 4:48d390356fba | 38 | wait(0.5); |
Weranest | 4:48d390356fba | 39 | buggyGoF(); |
Weranest | 4:48d390356fba | 40 | wait(1); |
Weranest | 4:48d390356fba | 41 | buggyGoLeft(); |
Weranest | 4:48d390356fba | 42 | wait(2); |
Weranest | 4:48d390356fba | 43 | buggyGoRight(); |
Weranest | 4:48d390356fba | 44 | wait(2); |
Weranest | 4:48d390356fba | 45 | buggyGoF(); |
Weranest | 4:48d390356fba | 46 | wait (1); |
Weranest | 4:48d390356fba | 47 | buggyStop(); |
Weranest | 4:48d390356fba | 48 | } |
Weranest | 4:48d390356fba | 49 | } |
Weranest | 4:48d390356fba | 50 | |
Weranest | 4:48d390356fba | 51 | |
Weranest | 4:48d390356fba | 52 | void stateMachine(int flag){ |
Weranest | 4:48d390356fba | 53 | while (1){ //depending on the flag changes the state. Not efficient, since relies on looping the whole thing, but will do for now |
Weranest | 4:48d390356fba | 54 | switch(flag){ |
Weranest | 4:48d390356fba | 55 | case 0: controlManual(flag); |
Weranest | 4:48d390356fba | 56 | case 1:controlAutomatic(flag); |
Weranest | 4:48d390356fba | 57 | break; |
Weranest | 4:48d390356fba | 58 | } |
Weranest | 4:48d390356fba | 59 | } |
Weranest | 4:48d390356fba | 60 | } |
Weranest | 4:48d390356fba | 61 | void buggyGoLeft(){ |
Weranest | 4:48d390356fba | 62 | buggyPWM(SLOW_PWM, FAST_PWM); |
Weranest | 4:48d390356fba | 63 | } |
Weranest | 4:48d390356fba | 64 | void buggyGoRight(){ |
Weranest | 4:48d390356fba | 65 | buggyPWM(FAST_PWM, SLOW_PWM); |
Weranest | 4:48d390356fba | 66 | } |
Weranest | 4:48d390356fba | 67 | void buggyGoF(){ |
Weranest | 4:48d390356fba | 68 | buggyPWM(NORMAL_PWM, NORMAL_PWM); |
Weranest | 4:48d390356fba | 69 | } |
Weranest | 4:48d390356fba | 70 | void buggyStop(){ |
Weranest | 4:48d390356fba | 71 | buggyPWM(0.0f, 0.0f); |
Weranest | 4:48d390356fba | 72 | } |