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.
pwm.cpp@0:5ffcaef3e603, 2018-04-18 (annotated)
- Committer:
- Weranest
- Date:
- Wed Apr 18 16:53:05 2018 +0000
- Revision:
- 0:5ffcaef3e603
Control added
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Weranest | 0:5ffcaef3e603 | 1 | //this defines motor setup and movement |
| Weranest | 0:5ffcaef3e603 | 2 | #include "mbed.h" |
| Weranest | 0:5ffcaef3e603 | 3 | #include "pins.cpp" |
| Weranest | 0:5ffcaef3e603 | 4 | //will have to determine real pulsewidths by testing with encoder |
| Weranest | 0:5ffcaef3e603 | 5 | //constants to be utilized in the buggy, can be changed as required |
| Weranest | 0:5ffcaef3e603 | 6 | #define NORMAL_PWM 0.2f |
| Weranest | 0:5ffcaef3e603 | 7 | #define FAST_PWM 0.7f |
| Weranest | 0:5ffcaef3e603 | 8 | #define SLOW_PWM 0.3f |
| Weranest | 0:5ffcaef3e603 | 9 | #define RIGHT_MOTOR_CONST 1 |
| Weranest | 0:5ffcaef3e603 | 10 | #define LEFT_MOTOR_CONST 1 |
| Weranest | 0:5ffcaef3e603 | 11 | #define MOTOR_PERIOD 1.0f |
| Weranest | 0:5ffcaef3e603 | 12 | //currently the setup uses unipolar mode, hence the need for direction |
| Weranest | 0:5ffcaef3e603 | 13 | |
| Weranest | 0:5ffcaef3e603 | 14 | |
| Weranest | 0:5ffcaef3e603 | 15 | void motorSetup(){ |
| Weranest | 0:5ffcaef3e603 | 16 | motorRight.period_ms(MOTOR_PERIOD); |
| Weranest | 0:5ffcaef3e603 | 17 | motorLeft.period_ms(MOTOR_PERIOD); |
| Weranest | 0:5ffcaef3e603 | 18 | motorDirLeft.write(1); |
| Weranest | 0:5ffcaef3e603 | 19 | motorDirRight.write(1); |
| Weranest | 0:5ffcaef3e603 | 20 | motorModeLeft.write(1); |
| Weranest | 0:5ffcaef3e603 | 21 | motorModeRight.write(1); |
| Weranest | 0:5ffcaef3e603 | 22 | driveBoard.write(1); |
| Weranest | 0:5ffcaef3e603 | 23 | } |
| Weranest | 0:5ffcaef3e603 | 24 | void buggyGoF(){ //drives forward |
| Weranest | 0:5ffcaef3e603 | 25 | motorRight.write(NORMAL_PWM); |
| Weranest | 0:5ffcaef3e603 | 26 | motorLeft.write(NORMAL_PWM); |
| Weranest | 0:5ffcaef3e603 | 27 | } |
| Weranest | 0:5ffcaef3e603 | 28 | |
| Weranest | 0:5ffcaef3e603 | 29 | void buggyGoLeft(){// drives left |
| Weranest | 0:5ffcaef3e603 | 30 | motorRight.write(FAST_PWM); |
| Weranest | 0:5ffcaef3e603 | 31 | motorLeft.write(SLOW_PWM); |
| Weranest | 0:5ffcaef3e603 | 32 | } |
| Weranest | 0:5ffcaef3e603 | 33 | void buggyGoRight(){ //drives fast |
| Weranest | 0:5ffcaef3e603 | 34 | motorRight.write(SLOW_PWM); |
| Weranest | 0:5ffcaef3e603 | 35 | motorLeft.write(FAST_PWM); |
| Weranest | 0:5ffcaef3e603 | 36 | } |
| Weranest | 0:5ffcaef3e603 | 37 | void buggyStop(){// no power |
| Weranest | 0:5ffcaef3e603 | 38 | motorRight.write(0.0f); |
| Weranest | 0:5ffcaef3e603 | 39 | motorLeft.write(0.0f); |
| Weranest | 0:5ffcaef3e603 | 40 | } |
