segway_self balancing robot 4180 project
Dependencies: mbed mbed-rtos LSM9DS1_Library
Revision 10:aafadd98d91c, committed 2020-04-18
- Comitter:
- pandirimukund
- Date:
- Sat Apr 18 20:13:31 2020 +0000
- Parent:
- 9:28821420f7a4
- Commit message:
- changed to rtos;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-rtos.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 18 20:03:58 2020 +0000
+++ b/main.cpp Sat Apr 18 20:13:31 2020 +0000
@@ -1,22 +1,27 @@
#include "mbed.h"
+#include "rtos.h"
DigitalOut myled(LED2);
Ticker bluetooth;
Serial pc(USBTX, USBRX);
+Mutex parameters_mutex;
//Control system variables
float rp = 50;
float rd = 51;
float ri = 50;
float desired_angle = 0;
+
+
+
Serial blue(p28,p27);
void bluetooth_update() {
char bnum=0;
char bhit=0;
-
+ while(1){
while (blue.getc()!='!') {
}
@@ -24,6 +29,7 @@
bnum = blue.getc(); //button number
pc.printf("%d",bnum);
bhit = blue.getc(); //1=hit, 0=release
+ parameters_mutex.lock();
if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
myled = bnum - '0'; //current button number will appear on LEDs
switch (bnum) {
@@ -87,17 +93,21 @@
break;
}
}
+ parameters_mutex.unlock();
}
- //}
+ Thread::wait(100);
+ }
}
int main() {
pc.printf("this is running");
//bluetooth.attach(&bluetooth_update, 0.1);
while(1) {
- bluetooth_update();
+// bluetooth_update();
+ parameters_mutex.lock();
pc.printf("rp: %f, rd: %f, ri: %f, desired_angle: %f\n", rp, rd, ri, desired_angle);
- wait(0.1);
+ parameters_mutex.unlock();
+ Thread::wait(0.1);
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sat Apr 18 20:13:31 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/ST/code/mbed-rtos/#83895f30f8f2
