Library for the m3pi robot. This works with a Pololu 3pi robot with the Serial Slave firmware, and exposes and API.

Dependents:   m3pi_USBSerialRPC m3pi_BluetoothRPC m3pi_HelloWorld m3pi_WiiRacing ... more

Files at this revision

API Documentation at this revision

Comitter:
chris
Date:
Fri Mar 25 15:44:52 2011 +0000
Parent:
6:62ee1486ecb9
Child:
8:4b7d6ea9b35b
Commit message:
Revised library that includes a constructor that requires no parameters. As the design is fixed, they can be hard coded.

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	Wed Nov 10 09:01:21 2010 +0000
+++ b/m3pi.cpp	Fri Mar 25 15:44:52 2011 +0000
@@ -24,12 +24,17 @@
 #include "mbed.h"
 #include "m3pi.h"
 
-m3pi::m3pi(PinName nrst, PinName tx, PinName rx) :  Stream("m3pi"), _nrst(nrst), _ser(tx, rx), _leds(p20,p19,p18,p17,p16,p15,p14,p13)  {
-    _leds = 0;
+m3pi::m3pi(PinName nrst, PinName tx, PinName rx) :  Stream("m3pi"), _nrst(nrst), _ser(tx, rx)  {
     _ser.baud(115200);
     reset();
 }
 
+m3pi::m3pi() :  Stream("m3pi"), _nrst(p23), _ser(p9, p10)  {
+    _ser.baud(115200);
+    reset();
+}
+
+
 void m3pi::reset () {
     _nrst = 0;
     wait (0.01);
@@ -143,6 +148,8 @@
 
 
 void m3pi::leds(int val) {
+
+    BusOut _leds(p20,p19,p18,p17,p16,p15,p14,p13);
     _leds = val;
 }
 
--- a/m3pi.h	Wed Nov 10 09:01:21 2010 +0000
+++ b/m3pi.h	Fri Mar 25 15:44:52 2011 +0000
@@ -51,10 +51,6 @@
 
 
 
-
-
-
-
 /** m3pi control class
  *
  * Example:
@@ -64,7 +60,7 @@
    #include "mbed.h"
    #include "m3pi.h"
 
-   m3pi pi(p8,p9,p10);
+   m3pi pi;
 
    int main() {
 
@@ -91,13 +87,20 @@
 
     /** Create the m3pi object connected to the default pins
      *
-     * @param nrst GPIO pin used for reset. Default is p8
+     * @param nrst GPIO pin used for reset. Default is p23
      * @param tx Serial transmit pin. Default is p9
      * @param rx Serial receive pin. Default is p10
      */
+    m3pi();
+
+
+    /** Create the m3pi object connected to the default pins
+     *
+     */
     m3pi(PinName nrst, PinName tx, PinName rx);
 
 
+
     /** Force a hardware reset of the 3pi
      */
     void reset (void);
@@ -133,7 +136,6 @@
     void left (float speed);
 
     /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
-     *
      * @param speed A normalised number 0 - 1.0 represents the full range.
      */
     void right (float speed);
@@ -151,18 +153,19 @@
 
     /** Read the battery voltage on the 3pi
      * @returns battery voltage as a float
-     *
      */
     float battery(void);
 
     /** Read the position of the detected line
      * @returns position as A normalised number -1.0 - 1.0 represents the full range.
-     *
+     *  -1.0 means line is on the left, or the line has been lost
+     *   0.0 means the line is in the middle
+     *   1.0 means the line is on the right
      */
     float line_position (void);
 
 
-    /** Calibrate the sensors. This turns the robot left then right, loking for a line
+    /** Calibrate the sensors. This turns the robot left then right, looking for a line
      *
      */
     char sensor_auto_calibrate (void);
@@ -187,8 +190,6 @@
      */
     void leds(int val);
 
-
-
     /** Locate the cursor on the 8x2 LCD
      *
      * @param x The horizontal position, from 0 to 7
@@ -225,7 +226,6 @@
 
     DigitalOut _nrst;
     Serial _ser;
-    BusOut _leds;
     
     void motor (int motor, float speed);
     virtual int _putc(int c);