Yelfie / Mbed 2 deprecated TDP_main_BartFork

Dependencies:   LocalPositionSystem MMA8451Q Motor_Driver Sensors mbed

Fork of TDP_main by Yelfie

Files at this revision

API Documentation at this revision

Comitter:
Reckstyle
Date:
Fri Feb 13 15:18:43 2015 +0000
Child:
1:eace997e9a93
Commit message:
First save;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
motor_driver.h Show annotated file Show diff for this revision Revisions of this file
sensor_measure.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 13 15:18:43 2015 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+#include "sensor_measure.h"
+
+
+DigitalOut myled(LED1);
+
+int main() {
+
+wait(1); //give time to set up the system
+        
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Feb 13 15:18:43 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensor_measure.h	Fri Feb 13 15:18:43 2015 +0000
@@ -0,0 +1,68 @@
+/*
+
+Sensor measurement header file. 
+Contains the pin declarations and variables for all sensors-related work
+Also contains the measurement function - should it???
+
+
+TODO 
+-decide whether pins should be Interrupts INs or is it going to be polling - polling atm
+- how to distingisuh between different sensor on/off frequency - maybe create a new class??
+- 
+LAST REVISED 13/02
+*/
+
+#ifndef _SENSOR_MEASURE_H
+#define _SENSOR_MEASURE_H
+
+#define NUMBER_SAMPLES 40 // NUMBER OF SAMPLES FOR SENSOR TESTING
+
+//define pinout for all the sensors
+InterruptIn pin_right_right(PTD0);
+InterruptIn pin_right_centre(PTD1);
+InterruptIn pin_right_left(PTD2);
+InterruptIn pin_left_right(PTD3);
+InterruptIn pin_left_centre(PTD4);
+InterruptIn pin_left_left(PTD5);
+//InterruptIn in(PTD0); maybe more~?
+
+//timer used by the sensor
+Timer sensorTimer;
+
+//structure for sensors
+typedef struct sensor_data {
+    InterruptIn pin;
+    int  black_value;
+    int  white_value;    
+}sensor_data;
+
+//Decalre all the sensors
+//sample rightright
+sensor_data right_right;
+right_right.pin = pin_right_right;
+right_right.black_value = 2013;
+right_right.white_value = 10000;
+
+// and continue with the others..
+
+//measuring function - returning whether it is black or white line 
+//"1" - black, "0" - white
+int measure (sensor_data sensor){
+    sensorTimer.reset();
+    int freq,period = 0;
+    int n =0; //number of samples
+    int sensor_old  = 0;//variable to remember old sensor state
+    
+    while (n < NUMBER_SAMPLES){
+        
+        if (sensor.pin == 1 && sensor_old == 0){ // detect on rising edge
+            n++;
+        }
+        sensor_old = sensor.pin;
+    }
+    
+    period = sensorTimer.read_us()/(float)n; // Get time
+    freq = (1/period)*1000000;   // Convert period (in us) to frequency (Hz). Works up to 100kHz. 
+    return freq;
+}
+#endif
\ No newline at end of file