za

Fork of m3pi by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
s4stevo
Date:
Sun Mar 24 00:15:29 2013 +0000
Parent:
8:4b7d6ea9b35b
Child:
10:30aaa3c1910a
Commit message:
Rev A

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 Mar 24 00:15:29 2013 +0000
@@ -1,29 +1,11 @@
-/* m3pi Library
- *
- * Copyright (c) 2007-2010 cstyles
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
 
 #include "mbed.h"
 #include "m3pi.h"
 
+
+mbed::AnalogIn pRight(p19);
+
+
 m3pi::m3pi(PinName nrst, PinName tx, PinName rx) :  Stream("m3pi"), _nrst(nrst), _ser(tx, rx)  {
     _ser.baud(115200);
     reset();
@@ -35,6 +17,7 @@
 }
 
 
+
 void m3pi::reset () {
     _nrst = 0;
     wait (0.01);
@@ -93,7 +76,7 @@
     _ser.putc(opcode);
     _ser.putc(arg);
 }
-
+//Battery Function
 float m3pi::battery() {
     _ser.putc(SEND_BATTERY_MILLIVOLTS);
     char lowbyte = _ser.getc();
@@ -102,29 +85,34 @@
     return(v);
 }
 
-float m3pi::line_position() {
+
+float m3pi::position() {
     int pos = 0;
-    _ser.putc(SEND_LINE_POSITION);
-    pos = _ser.getc();
-    pos += _ser.getc() << 8;
+    
     
-    float fpos = ((float)pos - 2048.0)/2048.0;
-    return(fpos);
+ return(pos);   
+    
 }
 
+//Don't need this.
+/*
 char m3pi::sensor_auto_calibrate() {
     _ser.putc(AUTO_CALIBRATE);
     return(_ser.getc());
-}
+}*/
 
-
+//Don't need this but need something similar. 
+/*
 void m3pi::calibrate(void) {
     _ser.putc(PI_CALIBRATE);
 }
 
+//Don't need this.
+
 void m3pi::reset_calibration() {
     _ser.putc(LINE_SENSORS_RESET_CALIBRATION);
 }
+*/
 
 void m3pi::PID_start(int max_speed, int a, int b, int c, int d) {
     _ser.putc(max_speed);
@@ -138,32 +126,34 @@
     _ser.putc(STOP_PID);
 }
 
-float m3pi::pot_voltage(void) {
+//Don't need. 
+
+/*float m3pi::pot_voltage(void) {
     int volt = 0;
     _ser.putc(SEND_TRIMPOT);
     volt = _ser.getc();
     volt += _ser.getc() << 8;
     return(volt);
 }
-
-
+*/
+//Print to LEDs. Probably wont use, possibly for voltage level. 
 void m3pi::leds(int val) {
 
     BusOut _leds(p20,p19,p18,p17,p16,p15,p14,p13);
     _leds = val;
 }
 
-
+//LCD Function.
 void m3pi::locate(int x, int y) {
     _ser.putc(DO_LCD_GOTO_XY);
     _ser.putc(x);
     _ser.putc(y);
 }
-
+//Clear LCD
 void m3pi::cls(void) {
     _ser.putc(DO_CLEAR);
 }
-
+//Print function for LCD
 int m3pi::print (char* text, int length) {
     _ser.putc(DO_PRINT);  
     _ser.putc(length);       
@@ -173,6 +163,7 @@
     return(0);
 }
 
+//Print function for LCD
 int m3pi::_putc (int c) {
     _ser.putc(DO_PRINT);  
     _ser.putc(0x1);       
@@ -208,8 +199,8 @@
         { "left_motor", rpc_method_caller<m3pi, float, &m3pi::left_motor> },
         { "right_motor", rpc_method_caller<m3pi, float, &m3pi::right_motor> },
         { "battery", rpc_method_caller<float, m3pi, &m3pi::battery> },
-        { "line_position", rpc_method_caller<float, m3pi, &m3pi::line_position> },
-        { "sensor_auto_calibrate", rpc_method_caller<char, m3pi, &m3pi::sensor_auto_calibrate> },
+        { "position", rpc_method_caller<float, m3pi, &m3pi::position> },
+        //{ "sensor_auto_calibrate", rpc_method_caller<char, m3pi, &m3pi::sensor_auto_calibrate> },
 
 
         RPC_METHOD_SUPER(Base)
--- a/m3pi.h	Thu May 12 13:26:37 2011 +0000
+++ b/m3pi.h	Sun Mar 24 00:15:29 2013 +0000
@@ -1,28 +1,9 @@
-/* mbed m3pi Library
- * Copyright (c) 2007-2010 cstyles
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+
 
 #ifndef M3PI_H
 #define M3PI_H
 
+
 #include "mbed.h"
 #include "platform.h"
 
@@ -51,35 +32,9 @@
 
 
 
-/** m3pi control class
- *
- * Example:
- * @code
- * // Drive the m3pi forward, turn left, back, turn right, at half speed for half a second
-
-   #include "mbed.h"
-   #include "m3pi.h"
-
-   m3pi pi;
-
-   int main() {
-
-     wait(0.5);
+ 
 
-     pi.forward(0.5);
-     wait (0.5);
-     pi.left(0.5);
-     wait (0.5);
-     pi.backward(0.5);
-     wait (0.5);
-     pi.right(0.5);
-     wait (0.5);
-
-     pi.stop();
-
- }
- * @endcode
- */
+ 
 class m3pi :  public Stream {
 
     // Public functions
@@ -149,7 +104,7 @@
      * @returns voltage as a float
      *
      */
-    float pot_voltage(void);
+    //float pot_voltage(void);
 
     /** Read the battery voltage on the 3pi
      * @returns battery voltage as a float
@@ -162,23 +117,23 @@
      *   0.0 means the line is in the middle
      *   1.0 means the line is on the right
      */
-    float line_position (void);
+    float position (void);
 
 
     /** Calibrate the sensors. This turns the robot left then right, looking for a line
      *
      */
-    char sensor_auto_calibrate (void);
+    //char sensor_auto_calibrate (void);
 
     /** Set calibration manually to the current settings.
      *
      */
-    void calibrate(void);
+    //void calibrate(void);
 
     /** Clear the current calibration settings
      *
      */
-    void reset_calibration (void);
+    //void reset_calibration (void);
 
     void PID_start(int max_speed, int a, int b, int c, int d);
 
@@ -197,6 +152,8 @@
      */
     void locate(int x, int y);
 
+   
+    
     /** Clear the LCD
      *
      */