Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of RCControlOOP by
Diff: WirelessMousr.cpp
- Revision:
- 3:b3ec75e9163f
- Parent:
- 2:e9042e88abf1
- Child:
- 5:dda15798ba1f
diff -r e9042e88abf1 -r b3ec75e9163f WirelessMousr.cpp
--- a/WirelessMousr.cpp Wed Oct 08 16:59:47 2014 +0000
+++ b/WirelessMousr.cpp Wed Oct 08 19:29:07 2014 +0000
@@ -1,6 +1,9 @@
#include "WirelessMousr.h"
+#define INSTRUCTION 0
+#define VELOCITY 1
WirelessMousr::WirelessMousr() : Mousr(), pc(p28, p27) {}
+//WirelessMousr::WirelessMousr() : Mousr(), pc(USBTX, USBRX) {}
int WirelessMousr::init()
{
@@ -11,39 +14,79 @@
void WirelessMousr::rxCallback()
{
- char state = this->pc.getc(); // read RX character, clearing interrupt
- pc.putc(state); // loopback
- pc.putc(10);
+ char message = this->pc.getc(); // read RX character, clearing interrupt
+ static char oldstate;
+ char newstate;
+ float pwmval;
+ int numerator;
+ float denominator;
+ this->pc.putc(message);
+ this->pc.putc('\n');
+ newstate = message;
- // state machine
- switch(state)
- {
- case 'v': //STOP
- this->stop(); break;
- case 'w': //STRAIGHT
- //pc.putc('g');
- this->straight(getStraightSpeed()); break;
- case 's': //STRAIGHT SLOW
- //pc.putc('g');
- this->straight(getStraightSlowSpeed()); break;
- case 'a': //ROTATE LEFT MEDIUM
- this->left(getRotateSpeed()); break;
- case 'd': //ROTATE RIGHT MEDIUM
- this->right(getRotateSpeed()); break;
- case 'x': //BACKWARDS
- this->backwards(getStraightSlowSpeed()); break;
- case 'q': //ROTATE LEFT FAST (CHANGE TO CIRCLE)
- pc.putc('g');
- this->left(getRotateFastSpeed()); break;
- case 'e': //ROTATE RIGHT FAST (CHANGE TO CIRCLE)
- this->right(getRotateFastSpeed()); break;
- case 'z':
- this->left(getRotateSlowSpeed()); break;
- case 'c':
- this->right(getRotateSlowSpeed()); break;
- case '1':
- this->flipLeft(); break;
- case '3':
- this->flipRight(); break;
- }
-}
\ No newline at end of file
+
+ if ((oldstate == 'l') || (oldstate == 'r'))
+ {
+ this->pc.putc('V');
+
+ numerator = ((int)message - 128);
+ denominator = (float) 128;
+ pwmval = ((float) numerator) / denominator;
+ if (oldstate == 'l')
+ {
+ this->lefttire(pwmval);
+ this->pc.putc('L');
+ this->pc.putc('L');
+ }
+ else if (oldstate == 'r')
+ {
+ this->righttire(pwmval);
+ this->pc.putc('R');
+ this->pc.putc('R');
+ }
+ }
+ else
+ {
+ switch(message)
+ {
+ case 'q': //STOP
+ this->left90();
+ this->pc.putc('L');
+ this->pc.putc('9');
+ this->pc.putc('0');
+ this->pc.putc('\n');
+ break;
+ case 'a': //STRAIGHT
+ this->left180();
+ this->pc.putc('L');
+ this->pc.putc('8');
+ this->pc.putc('0');
+ this->pc.putc('\n');
+ break;
+ case 'e': //STRAIGHT SLOW
+ this->right90();
+ this->pc.putc('R');
+ this->pc.putc('9');
+ this->pc.putc('0');
+ this->pc.putc('\n');
+ break;
+ case 'd': //ROTATE LEFT MEDIUM
+ this->right180();
+ this->pc.putc('R');
+ this->pc.putc('8');
+ this->pc.putc('0');
+ this->pc.putc('\n');
+ break;
+ case 's': //ROTATE RIGHT MEDIUM
+ this->stop();
+ this->pc.putc('S');
+ this->pc.putc('T');
+ this->pc.putc('P');
+ this->pc.putc('\n'); break;
+ }
+ }
+ // }
+
+ oldstate = newstate;
+
+}
