Dependencies:   MODSERIAL mbed-rtos mbed

Revision:
5:10b1ff176798
Parent:
4:7a203e4c0cf9
Child:
6:3ae957a6437b
--- a/main.cpp	Mon Mar 23 19:48:33 2015 +0000
+++ b/main.cpp	Mon Mar 23 20:31:04 2015 +0000
@@ -15,7 +15,7 @@
 //    DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
 //};
 
-int leds[NUM_LRAS];
+//int leds[NUM_LRAS];
 
 //PwmOut lra[NUM_LRAS] = {
 //    PwmOut(p5), PwmOut(p6), PwmOut(p14), PwmOut(p20),
@@ -41,6 +41,7 @@
 int lraPeriod_ms[NUM_LRAS];
 float lraIntensity[NUM_LRAS];
 
+// THREAD POINTERS
 Thread* lra_thread[NUM_LRAS];
 Thread* commThread;
 RtosTimer* timer;
@@ -59,7 +60,7 @@
 
     while (true) {
         // Turn On LRA:
-        leds[(int)n] = 1;
+        //leds[(int)n] = 1;
         lra_en[(int)n] = 1;
         lra[(int)n] = lraIntensity[(int)n]; //set initial intensity
         startTime_ms = counter_ms; //get start time
@@ -74,11 +75,11 @@
         }
 
 
-        leds[(int)n] = 0;
+        //leds[(int)n] = 0;
         //Set LRA PWM to 0.5
-        lra[(int)n] = 0.5f;
+        lra[(int)n] = 0.5f; // that turns off the motor!
         //Turn LRA Off by setting enable pin to 0
-        lra_en[(int)n] = 0;
+        lra_en[(int)n] = 0; // no braking happening
 
         //set rest time to sleep while the lra is off
         elapsed_ms = (int)(counter_ms-startTime_ms);
@@ -115,6 +116,29 @@
     int newOnTime;
     int newTotalTime;
 
+    // add calculations of start length and total period
+//%FORMULA is
+//%(input-c)/d
+//
+//
+//% start length
+//a = 1; %character start value
+//b = 255; %character end value
+//u = 50; %start value mapped to this lower limit
+//t = 300; %end value mapped to this upper limit
+//
+//c=(a-u*b/t)/(1-u/t)
+//d = (b-c)/t
+//
+//
+//%%%%%%%%%%%%%%%%%%%%DIFFERENT CALCULATION
+//
+//% total length
+//u = 300;
+//t = 4000;
+//c=(a-u*b/t)/(1-u/t)
+//d = (b-c)/t
+
     while (true) {
         // Wait here until we detect the \0 going into the buffer.
         //new data in the buffer, read it out
@@ -148,7 +172,7 @@
                     // Total Period Length
                     input = (input < 1)? 1 : input;
                     input = (input > 255)? 255 : input;
-                    // scale total period length between 301 to 4000 - see matlab script "range_calculations.m" in git repo
+                    // scale total period length between 300 to 4000 - see matlab script "range_calculations.m" in git repo
                     newTotalTime = (int) floor( ((input+19.5946)/0.0686) +0.5); //floor(...+0.5) = round()
                     if(newTotalTime!=lraPeriod_ms[which]) {
                         lraPeriod_ms[which] = newTotalTime;
@@ -160,6 +184,7 @@
                     break;
             }
             index++;
+            //Thread::yield();// Pass control to next thread that is in state READY. 
         }
         index = 0; //reset index
         Thread::signal_wait(0x3); //signal 3
@@ -171,9 +196,9 @@
     bt.baud(BT_BAUD); //set baud rate of bluetooth connection
     bt.attach(&rx_cb, MODSERIAL::RxIrq); // attach callback to get '\0' command
 
-    commThread = new Thread(commThread_cb);
+    commThread = new Thread(commThread_cb); //Thread(commThread_cb,NULL,osPriorityBelowNormal)
     //start universal timer to count up a counter
-    timer = new RtosTimer(timer_cb,osTimerPeriodic);
+    timer = new RtosTimer(timer_cb,osTimerPeriodic); // adjust prorioty of osTimerThread ?
     counter_ms=0;
     timer->start(1); //run timer every millisecond
 
@@ -196,6 +221,6 @@
         lraPeriod_ms[i] = 1000;
         lraIntensity[i] = 0.0f;
         //Set up lra threads
-        lra_thread[i] = new Thread(lra_fun, (void *)i);
+        lra_thread[i] = new Thread(lra_fun, (void *)i); //Thread(lra_fun, (void *)i, osPriorityNormal)
     }
 }
\ No newline at end of file