Code for the car to drive in a figure eight motion

Dependencies:   mbed-rtos mbed MODSERIAL mbed-dsp telemetry

main.cpp

Committer:
cheryl_he
Date:
2015-03-20
Revision:
22:986b3addda41
Parent:
21:a9e9aa7da8db

File content as of revision 22:986b3addda41:

#include "mbed.h"
#include "rtos.h"
#include "MODSERIAL.h"
#include "telemetry.h"
#include "telemetry-mbed.h"

// Camera Pins
DigitalOut clk(PTA13);
DigitalOut si(PTD4);
AnalogIn camData(PTC2);

//Servo, Motor, Serial Pins
PwmOut servo(PTA5);
PwmOut motor1(PTA4);
PwmOut motor2(PTA12);
DigitalOut break1(PTC12);
DigitalOut break2(PTC13);
Serial pc(USBTX, USBRX);

//Telemetry
MODSERIAL telemetry_serial(PTA2, PTA1);
/*
telemetry::MbedHal telemetry_hal(telemetry_serial);
telemetry::Telemetry telemetry_obj(telemetry_hal);
telemetry::Numeric<uint32_t> tele_time_ms(telemetry_obj, "time", "Time", "ms", 0);
telemetry::NumericArray<uint16_t, 128> tele_linescan(telemetry_obj, "linescan", "Linescan", "ADC", 0);
telemetry::Numeric<float> tele_motor_pwm(telemetry_obj, "motor", "Motor PWM", "%DC", 0);
*/

// Interrupt for encoder
InterruptIn interrupt(PTA13);

float line [128];
Mutex line_mutex;

void linecam_thread(void const *args){
    while(1){
        line_mutex.lock();
        pc.printf("[");
        for(int i=0; i<128; i++){
            pc.printf("%f",line[i]);
            pc.printf(" ");
        }
        pc.printf("]");
    }
    
}


int main() {
    Thread thread(linecam_thread);
    thread.set_priority(osPriorityIdle);
    //thread.set_priority(-3);
    //tele_motor_pwm.set_limits(0 ,1);
    int integrationCounter = 0;
    while(1) {
        if(integrationCounter % 151== 0){
            
        }
        else if (integrationCounter > 129){
        }
        else{
            clk = 1;
            wait_us(50);
            line[integrationCounter - 1] = camData;
            clk = 0;
        }
        
        integrationCounter++;
    }
}