haptic belt slave code that runs on single thread
Dependencies: USBDevice mbed mbed-rtos
Revision 5:301515ccaddc, committed 2015-03-27
- Comitter:
- baraki
- Date:
- Fri Mar 27 15:32:29 2015 +0000
- Parent:
- 4:91d5db5e8c9f
- Commit message:
- works with rtos timer now and we have all 7 pwms
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 |
diff -r 91d5db5e8c9f -r 301515ccaddc main.cpp --- a/main.cpp Fri Mar 27 14:36:29 2015 +0000 +++ b/main.cpp Fri Mar 27 15:32:29 2015 +0000 @@ -1,40 +1,37 @@ #include "mbed.h" #include "math.h" #include "bluetoothComm.h" +#include "rtos.h" #define BT_BAUD 9600 -#define NUM_LRAS 6 +#define NUM_LRAS 7 #define NUM_ENS NUM_LRAS -// bluetooth serial -// p9 - tx, p10 - rx -Timer timer; - -//DigitalOut leds[4] = { -// DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) -//}; - -//int leds[NUM_LRAS]; PwmOut lra[NUM_LRAS] = { - PwmOut(p5), PwmOut(p6),PwmOut(p20), + PwmOut(p5), PwmOut(p6),PwmOut(p17),PwmOut(p20), PwmOut(p25),PwmOut(p26),PwmOut(p34) }; -//,PwmOut(p17) - -//int lra[NUM_LRAS]; -//int lra_en[NUM_ENS]; DigitalOut lra_en[NUM_ENS] = { - DigitalOut(p7), DigitalOut(p8),DigitalOut(p12), + DigitalOut(p7), DigitalOut(p8),DigitalOut(p11),DigitalOut(p12), DigitalOut(p13),DigitalOut(p29),DigitalOut(p30) }; -DigitalOut en3(p11); + int lraOn_ms[NUM_LRAS]; int lraPeriod_ms[NUM_LRAS]; float lraIntensity[NUM_LRAS]; +RtosTimer* timer; +unsigned long counter_ms; + +void timer_cb(void const *n) +{ + counter_ms += 10; +} + void processData(char *n) { + //try to take these variables out and make them globals to speed processing int i = 0; int index = 0; int which = 0; @@ -97,13 +94,17 @@ int main (void) { - en3 = 0; //Init communication robotSetup(BT_BAUD); //set baud rate of bluetooth connection //start universal timer to count up a counter - timer.start(); - timer.reset(); - int counter_ms = timer.read_ms(); + //timer.start(); + //timer.reset(); + //int counter_ms = timer.read_ms(); + Thread::wait(100); + timer = new RtosTimer(timer_cb,osTimerPeriodic); // adjust prorioty of osTimerThread ? + counter_ms=0; + timer->start(10); //run timer every millisecond - arg is the time delay. + //initialize and start everything int startTime_ms[NUM_LRAS]; @@ -141,7 +142,7 @@ } for(int n=0;n<NUM_LRAS;n++){ // lra_fun - counter_ms = timer.read_ms(); + //counter_ms = timer.read_ms(); elapsed_ms[n] = (int)(counter_ms-startTime_ms[n]); if(isOn[n]) { leftToWait_ms[n] = lraOn_ms[n] - elapsed_ms[n]; @@ -149,7 +150,7 @@ lra[n] = lraIntensity[n]; //adjust intensity according to current value } else { - console1.printf("Turning motor off\n"); + //console1.printf("Turning motor off\n"); isOn[n] = false; //Set LRA PWM to 0.5 lra[n] = 0.5f; // that turns off the motor! @@ -159,18 +160,18 @@ } else { leftToWait_ms[n] = lraPeriod_ms[n] - elapsed_ms[n]; - if(n == 1){ + if(n == 1 && false){ console1.printf("leftToWait_ms[n] = %d\n",leftToWait_ms[n]); console1.printf("elapsed_ms[n] = %d\n",elapsed_ms[n]); } if(leftToWait_ms[n] < 0) { - console1.printf("Turning motor on\n"); + //console1.printf("Turning motor on\n"); isOn[n] = true; //Set LRA PWM to desired intensity lra[n] = lraIntensity[n]; // that turns on the motor! //Turn LRA On by setting enable pin to 1 lra_en[n] = 1; - startTime_ms[n] = timer.read_ms(); + startTime_ms[n] = counter_ms;//timer.read_ms(); } } }
diff -r 91d5db5e8c9f -r 301515ccaddc mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Mar 27 15:32:29 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#d3d0e710b443