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_BartFork by
Revision 26:cbbfe012a757, committed 2015-03-23
- Comitter:
- Bartas
- Date:
- Mon Mar 23 12:32:32 2015 +0000
- Parent:
- 25:8be440e10126
- Commit message:
- asd
Changed in this revision
| main.cpp | 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 |
--- a/main.cpp Sun Mar 22 23:55:20 2015 +0000
+++ b/main.cpp Mon Mar 23 12:32:32 2015 +0000
@@ -1,13 +1,8 @@
-// TESTING REPO COMMIT
-
/*
****** MAIN PROGRAM ******
-
-
Please consider that although it is an embedded envrionment we are NOT creating a HARD-TIME real time system - delays can be dealt with
-
Sensors are mapped on the global variable sensorsCheckSum,
which multiplies the sensor number by itself to then decode,
which sensors are off and which are on
@@ -16,21 +11,14 @@
...
*/
-
-
#include "mbed.h"
#include "sensor_measure.h"
#include "Motor_Driver.h"
#include "shooter.h"
-//#include "Sensors.h"
#define PWM_PERIOD_US 10000
-
-//DigitalOut led(LED1);
-
Serial HC06(PTE0,PTE1); //TX,RX
-//Serial pc(USBTX, USBRX);
Timer measureTimer; //Timer used for measurement
@@ -45,33 +33,33 @@
void measureSensors () {
- sensorsCheckSum = 0; //zero it when first going into the routine
- int iterationNumber = NUMBER_SENSORS_REGULAR;
- if (driveMode == SQUARE) {
+ sensorsCheckSum = 0; //zero it when first going into the routine
+ int iterationNumber = NUMBER_SENSORS_REGULAR;
+ if (driveMode == SQUARE) {
iterationNumber += NUMBER_SENSORS_SQUARE;
- }
- for (int i = 0; i < iterationNumber;i++){
+ }
+ for (int i = 0; i < iterationNumber;i++){
//pc.printf("%i iteration%i ",i,iterationNumber);
- if (measure(sensorArray[i]) == 1) {//if sensor is white
+ if (measure(sensorArray[i]) == 1) {//if sensor is white
sensorsCheckSum += (i+1)*(i+1);
- }
- }
- if (oldValues[0] != sensorsCheckSum) {
+ }
+ }
+ if (oldValues[0] != sensorsCheckSum) {
for (k = 5; k > 0; k--) {
oldValues[k] = oldValues[k-1];
}
oldValues[0] = sensorsCheckSum;
- }
+ }
//pc.printf("sensorsCheckSum is %i",sensorsCheckSum);
}
void printBluetooth() { //for debugging
- pc.printf("LLU%i LRU%i rlu%i rru%i\n",sensorArray[7]->state,sensorArray[6]->state,sensorArray[1]->state,sensorArray[0]->state);
- pc.printf("LLD%i LRD%i rld%i rrd%i\n\n",sensorArray[5]->state,sensorArray[4]->state,sensorArray[3]->state,sensorArray[2]->state);
+ HC06.printf("LLU%i LRU%i rlu%i rru%i\n",sensorArray[7]->state,sensorArray[6]->state,sensorArray[1]->state,sensorArray[0]->state);
+ HC06.printf("LLD%i LRD%i rld%i rrd%i\n\n",sensorArray[5]->state,sensorArray[4]->state,sensorArray[3]->state,sensorArray[2]->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());
- pc.printf("sensorCheckSum%i\n\n",sensorsCheckSum);
+ HC06.printf("sensorCheckSum%i\n\n",sensorsCheckSum);
//HC06.printf("passedTime1 %i passedTime2 \n\n",passedTime1,passedTime2);
}
@@ -79,7 +67,7 @@
Motor_Driver motors(PTA5, PTC9, PTC8,PTD4, PTA12, PTA4, PWM_PERIOD_US);
- // motors.setSpeed(0.1f);
+// motors.setSpeed(0.1f);
// motors.forward();
// motors.start();
// wait(2);
@@ -97,8 +85,7 @@
// motors.setRightSpeed (0.1f);
// wait(5);
// motors.stop();
-
- //wait(1);
+// wait(1);
// motors.reverse();
// wait(5);
// motors.stop();
@@ -107,34 +94,24 @@
// wait(5);
// motors.stop();
// wait(1);
-// motors.reverse();
-
-
-//motors.start();
-
- // setup_counter(1000, 0);
- // float frequency = measure_frequency(CHANNEL_1);
+// motors.reverse();
+// motors.start();
+
+// setup_counter(1000, 0);
+// float frequency = measure_frequency(CHANNEL_1);
measureTimer.start();
driveMode = REGULAR; //initialise drivemoder
sensor_initialise(); // initialise sensor values
wait(1); //give time to set up the system
-
sensorTimer.start(); // start timer for sensors
-// float normalSpeed = 0.01f;
-// HC06.baud(9600);
-// HC06.printf("working..");
-// motors.setSpeed(normalSpeed);
-// motors.forward();
-// motors.start();
-//
-//
-//
-// wait(3);
- // while(1){
-// if (pc.getc() == 'r') {
-// measureSensors();
- //measureTimer.reset();
-// printBluetooth();
+ pc.printf("Hello");
+ while(1){
+ if (HC06.getc() == 'r') {
+ measureSensors();
+ measureTimer.reset();
+ printBluetooth();
+ wait(1);
+ }
//passedTime1 = measureTimer.read_ms();
//if (sensorsCheckSum == 0) {
// motors.setSpeed(normalSpeed);
@@ -155,21 +132,14 @@
// }
//HC06.printf("AT");
//HC06.printf("AT+PIN5555");
-
-
- // pc.printf("Start...");
-
// int testOtherCases = 0; //needed for control statements
-
-
-
- while (1) {
-
+// while (1) {
+//
if (driveMode == REGULAR) {
measureSensors();
- switch (sensorsCheckSum) {
- case 0: // all black, turn around by 180 degrees
- for (k=0;k<6;k++) { //right turn situation
+ switch (sensorsCheckSum) {
+ case 0: // all black, turn around by 180 degrees or a possible turn on the left
+ for (k=0;k<6;k++) { //left turn situation
if (oldValues[k] == 194) {
motors.stop();
motors.setSteeringMode(NORMAL);
@@ -177,6 +147,7 @@
motors.setSpeed(0.1f);
motors.start();
wait(1);
+ motors.stop();
} else {
motors.stop();
motors.setSteeringMode(NORMAL);
@@ -197,6 +168,8 @@
}
break;
case 30: //all right are white, left all black >> turn right(move left wheel)
+ motors.setSteeringMode(NORMAL);
+ motors.forward();
motors.setRightSpeed(0.15f);
motors.setLeftSpeed(0.5f);
break;
@@ -204,10 +177,10 @@
// motors.setRightSpeed(0.15f);
// motors.setLeftSpeed(0.1f);
// break;
- case 94: //normal starting position, half of right and half of left are white, (move right wheel)
+ case 94: //normal <<STARTING POSITION>>, half of right and half of left are white
motors.setSteeringMode(NORMAL);
+ motors.forward();
motors.setSpeed(0.1f);
- motors.forward();
motors.start();
break;
case 104: //right all white, left half white >> turn right
@@ -250,27 +223,11 @@
break;
}
}
-}
-}
-}
-}
-
// if (testOtherCases == 1) {
// if (sensorsCheckSum < 96){ // adjust right
-// }
-// else {//adjust left
-// }
+// } else {//adjust left
+// }
// testOtherCases = 0;
-// }
-//
-//
-//
-// }
-// else { //if (driveMode == SQUARE}
-// //implement the square searching thing..
-//
-// }
-//
-//
-// }
-//
+// } else { //if (driveMode == SQUARE} //implement the square searching thing.
+ }
+ }
--- a/sensor_measure.h Sun Mar 22 23:55:20 2015 +0000 +++ b/sensor_measure.h Mon Mar 23 12:32:32 2015 +0000 @@ -1,5 +1,4 @@ /* - Sensor measurement header file. Contains the pin declarations and variables for all sensors-related work @@ -21,14 +20,14 @@ #define NUMBER_SENSORS_SQUARE 0 //define pinout for all the sensors -DigitalIn pin_right_right_up(PTE29); -DigitalIn pin_right_left_up(PTC1); -DigitalIn pin_right_right_down(PTC2); -DigitalIn pin_right_left_down(PTE30); -DigitalIn pin_left_right_down(PTB2); -DigitalIn pin_left_left_down(PTE22); //pte22 -DigitalIn pin_left_right_up(PTB3); //pte29 -DigitalIn pin_left_left_up(PTE23); +DigitalIn pin_right_right_up(PTC2); +DigitalIn pin_right_left_up(PTE30); +DigitalIn pin_right_right_down(PTE29); +DigitalIn pin_right_left_down(PTC1); +DigitalIn pin_left_right_down(PTB3); +DigitalIn pin_left_left_down(PTE22); +DigitalIn pin_left_right_up(PTE23); +DigitalIn pin_left_left_up(PTB2); //timer used by the sensor
