Masterman / Mbed 2 deprecated mbed_3pi_bluefruit

Dependencies:   m3piExpandedCommandSet mbed

Files at this revision

API Documentation at this revision

Comitter:
kkillebrew
Date:
Tue May 29 14:29:12 2018 +0000
Parent:
3:add27c286be9
Commit message:
First published version.

Changed in this revision

m3pi.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/m3pi.lib	Mon May 28 18:26:42 2018 +0000
+++ b/m3pi.lib	Tue May 29 14:29:12 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/chris/code/m3pi/#3f9c47a7fc66
+https://os.mbed.com/teams/Masterman/code/m3piExpandedCommandSet/#3f9c47a7fc66
--- a/main.cpp	Mon May 28 18:26:42 2018 +0000
+++ b/main.cpp	Tue May 29 14:29:12 2018 +0000
@@ -8,12 +8,24 @@
 
 // default serial buffer length is 8 bytes
 const int BUFF_LENGTH = 8;
+const int MAX_SPEED = 255;
+const int MIN_SPEED = -255;
 
 uint8_t rx_buf[BUFF_LENGTH];
 char str_buf[BUFF_LENGTH];
 char battery[BUFF_LENGTH] = "";
 char str[BUFF_LENGTH] = "";
 
+void drive(int left, int right) {
+    // bounds check speeds
+    if (right > MIN_SPEED && right < MAX_SPEED &&
+        left > MIN_SPEED && left < MAX_SPEED) {
+                
+        m3pi.left_motor(left);
+        m3pi.right_motor(right);
+    }
+}    
+
 /**
  * Receive commands in the form of a one-character leading command,
  * followed by two optional wheel speeds, if driving forwards or back.
@@ -27,13 +39,11 @@
     switch(cmd) {
         case 'f': {
             // forward
-            m3pi.left_motor(left);
-            m3pi.right_motor(right);
+            drive(left, right);
             break;
         } case 'r': {
             // reverse
-            m3pi.left_motor(-left);
-            m3pi.right_motor(-right);
+            drive(-left, -right);
             break;
         } case 'b': {
             // return battery level as 8-character string repr of float