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: Motor.cpp
- Revision:
- 4:d5b4ba5454d4
- Parent:
- 3:8f4f4d3a91bc
- Child:
- 5:38487ddb0fbf
diff -r 8f4f4d3a91bc -r d5b4ba5454d4 Motor.cpp --- a/Motor.cpp Sat Apr 25 02:42:23 2015 +0000 +++ b/Motor.cpp Mon Apr 27 23:53:44 2015 +0000 @@ -1,4 +1,5 @@ - #include "Motor.h" +#include "Motor.h" +#define BRK_THRESH 1.3 //in m/s /* Theory of operation of the tachometer reading system @@ -97,7 +98,8 @@ float iLimit, volatile float ki, volatile float kp, - PwmOut *motor) + PwmOut *motor, + DigitalOut *brk) { float delta_spd = target_spd - actual_spd; @@ -112,5 +114,11 @@ } // PI controller! - motor->write(kp * delta_spd + ki * (*iState)); + if (delta_spd < -BRK_THRESH) { + motor->write(0); + brk->write(1); + } else { + brk->write(0); + motor->write(kp * delta_spd + ki * (*iState)); + } }