This adds to the existing m3pi mbed library to add driving commands with speeds as integers ranging from -255 for 255, as does the serial slave program for the m3pi. Library for the m3pi robot. This works with a Pololu 3pi robot with the Serial Slave firmware, and exposes an API.
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 |
--- 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) {
--- 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 *