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: pwm.cpp
- Revision:
- 3:c9df852ad9ac
- Parent:
- 1:12f18cede014
- Child:
- 4:48d390356fba
diff -r 7f4be54c7257 -r c9df852ad9ac pwm.cpp --- a/pwm.cpp Fri Feb 16 19:30:19 2018 +0000 +++ b/pwm.cpp Wed Feb 21 11:55:29 2018 +0000 @@ -3,27 +3,41 @@ #include "C12832.h" #include "pins.h" #include "pwm.h" +#include "constants.cpp" //will have to determine real pulsewidths by testing with encoder -//constants to be utilized in the buggy, can be changed as required -#define NORMAL_PWM 0.5f -#define FAST_PWM 0.7f -#define SLOW_PWM 0.3f -#define RIGHT_MOTOR_CONST 1 -#define LEFT_MOTOR_CONST 1 -#define MOTOR_PERIOD 1.0f + //currently the setup uses unipolar mode, hence the need for direction + void motorSetup(){ motorRight.period_ms(MOTOR_PERIOD); motorLeft.period_ms(MOTOR_PERIOD); motorDirLeft.write(0); motorDirRight.write(0); motorModeLeft.write(0); //1 =bipolar, 0 = unipolar - motorModeRight.write(0); - driveBoard.write(1); + motorModeRight.write(0); + driveBoard.write(1); //enables the buggy to drive +} + +if(joystickDown == 1){ +void buggyGoF(){ //drives forward + motorRight.write(NORMAL_PWM*potRight.read()); + motorLeft.write(NORMAL_PWM*potLeft.read()); } -void buggyGoF(){ //drives forward + +void buggyGoLeft(){// drives left + motorRight.write(FAST_PWM*potRight.read()); + motorLeft.write(SLOW_PWM*potLeft.read()); +} +void buggyGoRight(){ //drives right + motorRight.write(SLOW_PWM*potRight.read()); + motorLeft.write(FAST_PWM*potLeft.read()); +} +} + +else{ + void buggyGoF(){ //drives forward motorRight.write(NORMAL_PWM); motorLeft.write(NORMAL_PWM); } @@ -32,10 +46,19 @@ motorRight.write(FAST_PWM); motorLeft.write(SLOW_PWM); } -void buggyGoRight(){ //drives fast +void buggyGoRight(){ //drives right motorRight.write(SLOW_PWM); motorLeft.write(FAST_PWM); } +} + + +void buggyStop(){// no power + motorRight.write(0.0f); + motorLeft.write(0.0f); +} + + void buggyStop(){// no power motorRight.write(0.0f); motorLeft.write(0.0f);