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: motordriver.cpp
- Revision:
- 4:5fb1296c0d60
- Parent:
- 3:8822f4955035
- Child:
- 5:3110b9209d3c
diff -r 8822f4955035 -r 5fb1296c0d60 motordriver.cpp
--- a/motordriver.cpp Fri Nov 19 12:33:38 2010 +0000
+++ b/motordriver.cpp Thu Nov 25 13:31:22 2010 +0000
@@ -59,7 +59,7 @@
_rev = (speed < 0.0);
_pwm = 0;
temp = 0;
- } else {
+ } else {
_fwd = (speed > 0.0);
_rev = (speed < 0.0);
temp = abs(speed);
@@ -106,6 +106,19 @@
return -1;
}
+float Motor::state(void) {
+ if ((_fwd == _rev) && (_pwm > 0)) {
+ return -2;//braking
+ } else if (_pwm == 0) {
+ return 2;//coasting
+ } else if ((_fwd == 0) && (_rev == 1)) {
+ return -(_pwm);//reversing
+ } else if ((_fwd == 1) && (_rev == 0)) {
+ return _pwm;//fowards
+ } else
+ return -3;//error
+}
+
/*
test code, this demonstrates working motor drivers.