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
main.cpp
- Committer:
- Reckstyle
- Date:
- 2015-03-12
- Revision:
- 15:6453cd351452
- Parent:
- 14:3844d1dacece
- Child:
- 16:3649eb1a056d
File content as of revision 15:6453cd351452:
// 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
ie. if sensor rightright - sensorChecksum = 1*1 = 1
if rightright and rightcentre - sensorChecksum = 1*1 + 2*2 = 5
...
*/
#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(PTD3,PTD2); //TX,RX
//Serial pc(USBTX, USBRX);
//Timer MeasureTimer; //Timer used for measurement
//Motor_Driver motors(PTD4, PTA12, PTA4, PTA5, PTC9, PTC8, PWM_PERIOD_US);
typedef enum mode {REGULAR,SQUARE} mode; //enumeration for different states
mode driveMode; //declaring the variable for the states
int sensorsCheckSum; //varibale used for sensors mapping access
void measureSensors () {
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++){
if (measure(*sensorArray[i]) == 1) {//if sensor is white
sensorsCheckSum += (i+1)*(i+1);
}
}
//pc.printf("sensorsCheckSum is %i",sensorsCheckSum);
}
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("%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");
}
int main() {
/*
Motor_Driver motors(PTD4, PTA12, PTA4, PTA5, PTC9, PTC8, PWM_PERIOD_US);
motors.setSpeed(1.0f);
motors.forward();
motors.start();
wait(3);
motors.stop()
motors.reverse();
wait(200ms);
motors.start();
*/
// setup_counter(1000, 0);
// float frequency = measure_frequency(CHANNEL_1);
driveMode = REGULAR; //initialise drivemoder
sensor_initialise(); // initialise sensor values
wait(1); //give time to set up the system
sensorTimer.start(); // start timer for sensors
HC06.baud(9600);
HC06.printf("Press 'r'\n");
pc.printf("we start");
//HC06.printf("AT");
//HC06.printf("AT+PIN5555");
// pc.printf("Start...");
//
//
// while (1) {
//
// if (driveMode == REGULAR) {
// measureSensors();
// switch (sensorsCheckSum) {
// case 1: //right right is 1*1 + 0 + 0+ 0+0 +0
// pc.printf ("only Right is white \n");
// break;
// case 4 : //0*0 + 2*2 + 0 + 0 + 0
// pc.printf ("only Left is white \n");
// break;
// case 5 : //1*1 + 2*2 + 0 + 0
// pc.printf ("both are white \n");
// break;
//// case 91:
//// driveMode = SQUARE; //if all sensors are white you're in the square
//// break;
// default: //checksum is zero , all are black
// pc.printf ("BLACK BLACK");
// break;
// }
//
//
//
// }
// else { //if (driveMode == SQUARE}
// //implement the square searching thing..
//
// }
//
//
// }
//
}
/* TOBE deleted
double measure1 (){
sensorTimer.reset();
double freq,period = 0.0;
int n =0; //number of samples
int sensor_old = 0;
int sensor_new = 0;//variable to remember old sensor state
double time_us = sensorTimer.read();
while (n < NUMBER_SAMPLES){
sensor_new = pin_right_right.read();
if ( sensor_new== 1 && sensor_old == 0){ // detect on rising edge ,sensor_old
n++;
}
sensor_old = sensor_new;
}
double time_us2 = sensorTimer.read();
// pc.printf(" delta time is %f , time 2 is %f " , (time_us2 - time_us), time_us2);
period = time_us2/((double)NUMBER_SAMPLES); // Get time
freq = (1/period); // Convert period (in us) to frequency (Hz). Works up to 100kHz.
// pc.printf(" period is %f ", period);
return freq;//(freq < sensor.black_value*2)? 1 : 0;
}
*/
