
mbed Car
Revision 0:6cfc4ab23aac, committed 2016-10-27
- Comitter:
- malcolmlear
- Date:
- Thu Oct 27 13:26:41 2016 +0000
- Commit message:
- Test
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 6cfc4ab23aac main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 27 13:26:41 2016 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" + +PwmOut steering(p21); +PwmOut velocity(p22); + +float vo=0; + +// Velocity expects -1 (reverse) to +1 (forward) +void Velocity(float v) { + v=v+1; + if (v>=0 && v<=2) { + if (vo>=1 && v<1) { // + velocity.pulsewidth(0.0014); // this is required to + wait(0.1); // + velocity.pulsewidth(0.0015); // move into reverse + wait(0.1); // + } // + velocity.pulsewidth(v/2000+0.001); + vo=v; + } +} +// Steering expects -1 (left) to +1 (right) +void Steering(float s) { + s=s+1; + if (s>=0 && s<=2) { + steering.pulsewidth(s/2000+0.001); + } +} + +int main() { + velocity.period(0.02); + steering.period(0.02); + Velocity(0); // initiate the drive motor (this must be done) + Steering(0); // centre steering + wait(0.5); + while(1) { + for(int i=0; i<100; i++) { // stop to full forward + Velocity(i/100.0); + wait(0.1); + } + for(int i=100; i>-100; i--) { // full forward to full reverse + Velocity(i/100.0); + wait(0.1); + } + for(int i=-100; i<0; i++) { // full reverse to stop + Velocity(i/100.0); + wait(0.1); + } + for(int i=0; i<100; i++) { // centre to full right + Steering(i/100.0); + wait(0.1); + } + for(int i=100; i>-100; i--) { // full right to full left + Steering(i/100.0); + wait(0.1); + } + for(int i=-100; i<0; i++) { // full left to centre + Steering(i/100.0); + wait(0.1); + } + } +}
diff -r 000000000000 -r 6cfc4ab23aac mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 27 13:26:41 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file