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: LocalPositionSystem MMA8451Q Motor_Driver Sensors mbed
Fork of TDP_main by
Revision 16:3649eb1a056d, committed 2015-03-13
- Comitter:
- Reckstyle
- Date:
- Fri Mar 13 18:19:01 2015 +0000
- Parent:
- 15:6453cd351452
- Child:
- 17:de8b3111ddc5
- Commit message:
- fixed pointers problem,still needs testing though
Changed in this revision
--- a/LocalPositionSystem.lib Thu Mar 12 18:44:57 2015 +0000 +++ b/LocalPositionSystem.lib Fri Mar 13 18:19:01 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Yelfie/code/LocalPositionSystem/#21ca29888540 +http://developer.mbed.org/teams/Yelfie/code/LocalPositionSystem/#dd68ac680416
--- a/Motor_Driver.lib Thu Mar 12 18:44:57 2015 +0000 +++ b/Motor_Driver.lib Fri Mar 13 18:19:01 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Yelfie/code/Motor_Driver/#e648ae0d319e +http://developer.mbed.org/teams/Yelfie/code/Motor_Driver/#0c663c0d778d
--- a/main.cpp Thu Mar 12 18:44:57 2015 +0000
+++ b/main.cpp Fri Mar 13 18:19:01 2015 +0000
@@ -29,7 +29,7 @@
//DigitalOut led(LED1);
-Serial HC06(PTD3,PTD2); //TX,RX
+Serial HC06(PTE0,PTE1); //TX,RX
//Serial pc(USBTX, USBRX);
//Timer MeasureTimer; //Timer used for measurement
@@ -49,7 +49,7 @@
iterationNumber += NUMBER_SENSORS_SQUARE;
}
for (int i = 0; i < iterationNumber;i++){
- if (measure(*sensorArray[i]) == 1) {//if sensor is white
+ if (measure(sensorArray[i]) == 1) {//if sensor is white
sensorsCheckSum += (i+1)*(i+1);
}
}
@@ -57,11 +57,13 @@
}
void printBluetooth() { //for debugging
- HC06.printf("%i %i %i %i",sensorArray[NUMBER_SENSORS_REGULAR-1]->state,sensorArray[NUMBER_SENSORS_REGULAR-2]->state,sensorArray[1]->state,sensorArray[0]->state);
- HC06.printf("%i %i %i %i",sensorArray[NUMBER_SENSORS_REGULAR-3]->state,sensorArray[NUMBER_SENSORS_REGULAR-4]->state,sensorArray[3]->state,sensorArray[2]->state);
+
+ HC06.printf("rru%i rlu%i rrd%i rld%i\n",sensorArray[0]->state,sensorArray[1]->state,sensorArray[2]->state,sensorArray[3]->state);
+ //HC06.printf("%i %i %i %i",sensorArray[NUMBER_SENSORS_REGULAR-1]->state,sensorArray[NUMBER_SENSORS_REGULAR-2]->state,sensorArray[1]->state,sensorArray[0]->state);
+ //HC06.printf("%i %i %i %i",sensorArray[NUMBER_SENSORS_REGULAR-3]->state,sensorArray[NUMBER_SENSORS_REGULAR-4]->state,sensorArray[3]->state,sensorArray[2]->state);
//HC06.printf("%i %i/n%i %i,sensorArray[NUMBER_SENSORS_REGULAR]->state,sensorArray[NUMBER_SENSORS_REGULAR+1]->state,sensorArray[NUMBER_SENSORS_REGULAR+2]->state,sensorArray[NUMBER_SENSORS_REGULAR+3]->state);
//HC06.printf("%f %f",motor.getLeftSpeed(),motor.getRightSpeed());
- HC06.printf("/n/n");
+ //HC06.printf("/n/n");
}
int main() {
@@ -92,8 +94,13 @@
sensorTimer.start(); // start timer for sensors
HC06.baud(9600);
- HC06.printf("Press 'r'\n");
- pc.printf("we start");
+ HC06.printf("working..");
+ while(1){
+ measureSensors();
+ printBluetooth();
+ wait(0.5);
+ }
+
//HC06.printf("AT");
//HC06.printf("AT+PIN5555");
--- a/sensor_measure.h Thu Mar 12 18:44:57 2015 +0000
+++ b/sensor_measure.h Fri Mar 13 18:19:01 2015 +0000
@@ -17,14 +17,14 @@
#define _SENSOR_MEASURE_H
#define NUMBER_SAMPLES 20 // NUMBER OF SAMPLES FOR SENSOR TESTING
-#define NUMBER_SENSORS_REGULAR 8 // number for the array of sensors
+#define NUMBER_SENSORS_REGULAR 4 // number for the array of sensors
#define NUMBER_SENSORS_SQUARE 0
//define pinout for all the sensors
-DigitalIn pin_right_right_up(PTD0);
-DigitalIn pin_right_left_up(PTD2);
-DigitalIn pin_right_right_down(PTD2);
-DigitalIn pin_right_left_down(PTD3);
+DigitalIn pin_right_right_up(PTE5);
+DigitalIn pin_right_left_up(PTE2);
+DigitalIn pin_right_right_down(PTE3);
+DigitalIn pin_right_left_down(PTE4);
DigitalIn pin_left_right_down(PTD4);
DigitalIn pin_left_left_down(PTD5);
//DigitalIn pin_left_right_up();
@@ -75,13 +75,17 @@
right_left_up.grayValue = 0;
right_left_up.state = 0;
sensorArray [arrayBuilder++] = &right_left_up;
+ right_right_down.pin = &pin_right_right_down;
+ sensorArray [arrayBuilder++] = &right_right_down;
+ right_left_down.pin = &pin_right_left_down;
+ sensorArray[arrayBuilder++] = &right_left_down;
//and contiune so on..
}
-
+int counter1 = 0;
//measuring function - returning whether it is black or white line
//"0" - black, "1" - white
-int measure (sensor_data sensor){
+int measure (sensor_data *sensor){
sensorTimer.reset(); //reset the timer
double freq,period = 0.0;
@@ -90,7 +94,7 @@
int sensor_new = 0;
//double time_1 = sensorTimer.read(); used for debugging
while (n < NUMBER_SAMPLES){
- sensor_new = sensor.pin->read();
+ sensor_new = sensor->pin->read();
if ( sensor_new== 1 && sensor_old == 0){ // detect on rising edge
n++;
}
@@ -101,21 +105,23 @@
period = time_2/((double)NUMBER_SAMPLES); // Get time
freq = (1/period); // Convert period (in us) to frequency (Hz).
- // pc.printf(" period is %f and freq is %f ", period,freq); // Used for debugging
+ //pc.printf(" period is %f and freq is %f ", period,freq); // Used for debugging
+
+ sensor->state = freq;
- if (sensor.grayValue != 0 && freq < (sensor.grayValue + 1000) && freq > (sensor.grayValue - 1000)) { //definitely not sure about that!
- //this is a gray value sensor in its gray region
- sensor.state = 2;
- return 2;
- }
- else if (freq < sensor.blackValue*2){
- sensor.state = 0; //if it's less than black value it is black
- return 0;
- }
- else {
- sensor.state = 1;
- }
+// if (sensor->grayValue != 0 && freq < (sensor->grayValue + 1000) && freq > (sensor.grayValue - 1000)) { //definitely not sure about that!
+// //this is a gray value sensor in its gray region
+// sensor->state = 2;
+// return 2;
+// }
+// else if (freq < sensor->blackValue*2){
+// sensor->state = 0; //if it's less than black value it is black
+// return 0;
+// }
+// else {
+// sensor->state = 1;
+// }
return 1;
- //(freq < sensor.black_value*2)? 1 : 0; //freq
+ //(freq < sensor->black_value*2)? 1 : 0; //freq
}
#endif
\ No newline at end of file
