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.
Dependencies: mbed
Fork of Driving by
Revision 3:f557fc495719, committed 2018-03-29
- Comitter:
- KDrainEE
- Date:
- Thu Mar 29 18:12:44 2018 +0000
- Parent:
- 2:1fd3a4aff5d3
- Commit message:
- Seems to work fairly well again
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Mar 29 13:06:44 2018 +0000 +++ b/main.cpp Thu Mar 29 18:12:44 2018 +0000 @@ -1,39 +1,39 @@ #include "mbed.h" #include <iostream> -using namespace std; -//test #define SCALAR 0.6f #define TACH PTB1 #define SPEED_CONTROL PTD5 #define BRAKE PTA13 #define TI 0.001f -#define MINm 0.0f -#define MAXm 1.0f -#define KPm 0.1414f +#define MINM 0.0f +#define MAXM 1.0f +#define KPM 0.1414f #define KI 19.7408f Ticker sample; AnalogIn speed(TACH); PwmOut gateDrive(SPEED_CONTROL); -DigitalOut brake(BRAKE); +//DigitalOut brake(BRAKE); +DigitalOut myLed(LED_GREEN); -float Setpoint; -float errSum; +float Setpoint = 0.0; +float errSum = 0.0; +//Serial pc(USBTX, USBRX); Serial bt(PTE0, PTE1); //COM12 void serCb() { char x = bt.getc(); - if (x == 'a') + if (x == 'u') { - Setpoint = 0.25; + Setpoint = Setpoint + 0.05; } - else if(x == 's') + else if(x == 'h') { - Setpoint = 0.6; + Setpoint = Setpoint - 0.05; } else { @@ -46,35 +46,33 @@ float error = Setpoint-speed.read(); errSum +=(error * TI); float iTerm = KI*errSum; - if(iTerm > MAXm) iTerm = MAXm; - if(iTerm < MINm) iTerm = MINm; - float output = KPm*error + iTerm; - if(output > MAXm) output = MAXm; - if(output < MINm) output = MINm; - if(output < MINm) + if(iTerm > MAXM) iTerm = MAXM; + if(iTerm < MINM) iTerm = MINM; + float output = KPM*error + iTerm; + if(output > MAXM) output = MAXM; + if(output < MINM) output = MINM; + if(output < MINM) { - gateDrive.write(MINm); - brake.write(1); + gateDrive.write(MINM); + //brake.write(1); } else { - brake.write(0); + //brake.write(0); gateDrive.write(output); - } + } + //data[1] = output; } int main() { - Setpoint = 0.0; - errSum = 0.0; sample.attach(&compute_PI, TI); - + + myLed = 0; bt.baud(115200); - bt.printf("Press 'a' to go 25 and 's' to go 60%\r\n"); + bt.printf("Press 'u' to speed up and 'h' to slow down%\r\n"); + bt.attach(&serCb); - while(true) - { - - } + {} } \ No newline at end of file