
Team Design project 3 main file
Dependencies: LocalPositionSystem MMA8451Q Motor_Driver Sensors mbed
Fork of TDP_main by
main.cpp
- Committer:
- Joseph_Penikis
- Date:
- 2015-02-25
- Revision:
- 10:c9212bbfeae6
- Parent:
- 9:718987b106a8
- Child:
- 11:9e56d52485d1
File content as of revision 10:c9212bbfeae6:
// TESTING REPO COMMIT /* ****** MAIN PROGRAM ****** TODO : organisational routine still to be decided. 3 main approaches: -sequential prirority based tasks -Timer/Ticker driven with sequential prirority based tasks - interrupt driven from sensor inputs Please consider that although it is an embedded envrionment we are NOT creating a HARD-TIME real time system - delays can be dealt with */ #include "mbed.h" //#include "sensor_measure.h" #include "Motor_Driver.h" //#include "Sensors.h" #define PWM_PERIOD_US 10000 DigitalOut led(LED1); //Serial pc(USBTX, USBRX); //Timer MeasureTimer; //Timer used for measurement Motor_Driver motors(PTD4, PTA12, PTA4, PTA5, PTC9, PTC8, PWM_PERIOD_US); /* For deleting 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; } */ int main() { motors.setSpeed(0.5f); motors.forward(); wait(1); motors.start(0); led = 0; wait(2); motors.setSpeed(1.0f); wait(2); led = 1; motors.stop(0); wait(3); motors.reverse(); wait_ms(200); motors.start(0); wait(3); motors.stop(0); motors.setSteeringMode(PIVOT_CW); wait(1); motors.start(0); wait(2); motors.stop(0); } /*int main() { pc.baud(9600); start_systick(); pc.printf("Started!"); int frequency; while(1) { frequency = measure_clock_cycles(CHANNEL_1, 25); pc.printf("Debug: %i\n", frequency); wait_ms(200); } }*/