Eimantas Bernotavicius / Mbed 2 deprecated Buggy_Project

Dependencies:   QEI mbed

Committer:
Weranest
Date:
Wed Feb 21 11:55:29 2018 +0000
Revision:
3:c9df852ad9ac
Parent:
1:12f18cede014
Child:
4:48d390356fba
For Alston

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Weranest 0:62e51b80d738 1 //this defines motor setup and movement
Weranest 0:62e51b80d738 2 #include "mbed.h"
Weranest 0:62e51b80d738 3 #include "C12832.h"
Weranest 1:12f18cede014 4 #include "pins.h"
Weranest 1:12f18cede014 5 #include "pwm.h"
Weranest 3:c9df852ad9ac 6 #include "constants.cpp"
Weranest 0:62e51b80d738 7 //will have to determine real pulsewidths by testing with encoder
Weranest 3:c9df852ad9ac 8
Weranest 0:62e51b80d738 9 //currently the setup uses unipolar mode, hence the need for direction
Weranest 0:62e51b80d738 10
Weranest 0:62e51b80d738 11
Weranest 3:c9df852ad9ac 12
Weranest 0:62e51b80d738 13 void motorSetup(){
Weranest 0:62e51b80d738 14 motorRight.period_ms(MOTOR_PERIOD);
Weranest 0:62e51b80d738 15 motorLeft.period_ms(MOTOR_PERIOD);
Weranest 1:12f18cede014 16 motorDirLeft.write(0);
Weranest 1:12f18cede014 17 motorDirRight.write(0);
Weranest 1:12f18cede014 18 motorModeLeft.write(0); //1 =bipolar, 0 = unipolar
Weranest 3:c9df852ad9ac 19 motorModeRight.write(0);
Weranest 3:c9df852ad9ac 20 driveBoard.write(1); //enables the buggy to drive
Weranest 3:c9df852ad9ac 21 }
Weranest 3:c9df852ad9ac 22
Weranest 3:c9df852ad9ac 23 if(joystickDown == 1){
Weranest 3:c9df852ad9ac 24 void buggyGoF(){ //drives forward
Weranest 3:c9df852ad9ac 25 motorRight.write(NORMAL_PWM*potRight.read());
Weranest 3:c9df852ad9ac 26 motorLeft.write(NORMAL_PWM*potLeft.read());
Weranest 0:62e51b80d738 27 }
Weranest 3:c9df852ad9ac 28
Weranest 3:c9df852ad9ac 29 void buggyGoLeft(){// drives left
Weranest 3:c9df852ad9ac 30 motorRight.write(FAST_PWM*potRight.read());
Weranest 3:c9df852ad9ac 31 motorLeft.write(SLOW_PWM*potLeft.read());
Weranest 3:c9df852ad9ac 32 }
Weranest 3:c9df852ad9ac 33 void buggyGoRight(){ //drives right
Weranest 3:c9df852ad9ac 34 motorRight.write(SLOW_PWM*potRight.read());
Weranest 3:c9df852ad9ac 35 motorLeft.write(FAST_PWM*potLeft.read());
Weranest 3:c9df852ad9ac 36 }
Weranest 3:c9df852ad9ac 37 }
Weranest 3:c9df852ad9ac 38
Weranest 3:c9df852ad9ac 39 else{
Weranest 3:c9df852ad9ac 40 void buggyGoF(){ //drives forward
Weranest 0:62e51b80d738 41 motorRight.write(NORMAL_PWM);
Weranest 0:62e51b80d738 42 motorLeft.write(NORMAL_PWM);
Weranest 0:62e51b80d738 43 }
Weranest 0:62e51b80d738 44
Weranest 0:62e51b80d738 45 void buggyGoLeft(){// drives left
Weranest 0:62e51b80d738 46 motorRight.write(FAST_PWM);
Weranest 0:62e51b80d738 47 motorLeft.write(SLOW_PWM);
Weranest 0:62e51b80d738 48 }
Weranest 3:c9df852ad9ac 49 void buggyGoRight(){ //drives right
Weranest 0:62e51b80d738 50 motorRight.write(SLOW_PWM);
Weranest 0:62e51b80d738 51 motorLeft.write(FAST_PWM);
Weranest 0:62e51b80d738 52 }
Weranest 3:c9df852ad9ac 53 }
Weranest 3:c9df852ad9ac 54
Weranest 3:c9df852ad9ac 55
Weranest 3:c9df852ad9ac 56 void buggyStop(){// no power
Weranest 3:c9df852ad9ac 57 motorRight.write(0.0f);
Weranest 3:c9df852ad9ac 58 motorLeft.write(0.0f);
Weranest 3:c9df852ad9ac 59 }
Weranest 3:c9df852ad9ac 60
Weranest 3:c9df852ad9ac 61
Weranest 0:62e51b80d738 62 void buggyStop(){// no power
Weranest 0:62e51b80d738 63 motorRight.write(0.0f);
Weranest 0:62e51b80d738 64 motorLeft.write(0.0f);
Weranest 0:62e51b80d738 65 }