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.
Fork of m3pi by
Revision 9:3f9c47a7fc66, committed 2018-05-27
- Comitter:
- kkillebrew
- Date:
- Sun May 27 22:06:09 2018 +0000
- Parent:
- 8:4b7d6ea9b35b
- Commit message:
- Overload methods to allow setting wheel speeds in the 0 - 255 range.
Changed in this revision
m3pi.cpp | Show annotated file Show diff for this revision Revisions of this file |
m3pi.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4b7d6ea9b35b -r 3f9c47a7fc66 m3pi.cpp --- a/m3pi.cpp Thu May 12 13:26:37 2011 +0000 +++ b/m3pi.cpp Sun May 27 22:06:09 2018 +0000 @@ -75,6 +75,26 @@ motor(1,0.0); } +void m3pi::left_motor(int speed) { + if (speed > 0) { + _ser.putc(M1_FORWARD); + _ser.putc(speed); + } else { + _ser.putc(M1_BACKWARD); + _ser.putc(-speed); + } +} + +void m3pi::right_motor(int speed) { + if (speed > 0) { + _ser.putc(M2_FORWARD); + _ser.putc(speed); + } else { + _ser.putc(M2_BACKWARD); + _ser.putc(-speed); + } +} + void m3pi::motor (int motor, float speed) { char opcode = 0x0; if (speed > 0.0) {
diff -r 4b7d6ea9b35b -r 3f9c47a7fc66 m3pi.h --- a/m3pi.h Thu May 12 13:26:37 2011 +0000 +++ b/m3pi.h Sun May 27 22:06:09 2018 +0000 @@ -104,6 +104,12 @@ /** Force a hardware reset of the 3pi */ void reset (void); + + /* Accept speeds in -255 to 255 range, as does the m3pi, + ** for easier serial passthrough of byte commands. + */ + void left_motor (int speed); + void right_motor (int speed); /** Directly control the speed and direction of the left motor *