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

Dependencies:   btbee

Dependents:   configure_btbee m3pi_btTest Test_SlowDown TurnAround ... more

Fork of m3pi by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
ngoldin
Date:
Tue May 14 11:05:33 2013 +0000
Parent:
9:deb9547909c3
Child:
11:7bfb33432791
Commit message:
Fixed my additional methods. Constructing the array inside the function led to memory overrun in the long run. Now, they expect to be given a pointer to somewhere to write.

Changed in this revision

m3pi_ng.cpp Show annotated file Show diff for this revision Revisions of this file
m3pi_ng.h Show annotated file Show diff for this revision Revisions of this file
--- a/m3pi_ng.cpp	Mon May 13 10:54:18 2013 +0000
+++ b/m3pi_ng.cpp	Tue May 14 11:05:33 2013 +0000
@@ -38,37 +38,31 @@
 }
 
 
-char * m3pi::signature () {
-    char* sig = new char[6]; //must be initialised with new, else it is destroyed when the function exits
+void m3pi::signature (char * sig) {
     _ser.putc(SEND_SIGNATURE);
     for (int i=0; i<6;i++){
         sig[i]=_ser.getc();
     }
-    return sig;
 }
 
-int * m3pi::raw_sensor () {
+void m3pi::raw_sensor (int * raw) {
     _ser.putc(SEND_RAW_SENSOR_VALUES);
-    int* raw = new int[5]; //must be initialised with new, else it is destroyed when the function exits
     for (int i=0; i<5; i++){
         char lowbyte = _ser.getc();
         char hibyte  = _ser.getc();
         int s = (lowbyte + (hibyte << 8));
         raw[i] = s;
     }
-    return(raw);
 }
 
-int * m3pi::calibrated_sensor () {
+void m3pi::calibrated_sensor (int * cal) {
     _ser.putc(SEND_CALIBRATED_SENSOR_VALUES);
-    int* cal = new int[5]; //must be initialised with new, else it is destroyed when the function exits
     for (int i=0; i<5; i++){
         char lowbyte = _ser.getc();
         char hibyte  = _ser.getc();
         int s = (lowbyte + (hibyte << 8));
         cal[i] = s;
     }
-    return(cal);
 }
 
 void m3pi::playtune (char* text, int length) {
--- a/m3pi_ng.h	Mon May 13 10:54:18 2013 +0000
+++ b/m3pi_ng.h	Tue May 14 11:05:33 2013 +0000
@@ -105,17 +105,19 @@
     m3pi(PinName nrst, PinName tx, PinName rx);
 
     /** Get the signature 
-        returns length 6 char array
+     *  needs a length 6 char array to write into
      */
-    char * signature (void);
+    void signature (char *);
 
     /** Get the raw sensor values
-    */
-    int * raw_sensor (void);
+     *  needs a int[5] array to write into
+     */
+    void raw_sensor (int *);
 
     /** Get the calibrated sensor values
-    */
-    int * calibrated_sensor (void);
+     *  needs a int[5] array to write into
+     */
+    void calibrated_sensor (int *);
    
     /** Play music using the buzzer
      */