Code for the car to drive in a figure eight motion

Dependencies:   mbed-rtos mbed MODSERIAL mbed-dsp telemetry

Committer:
cheryl_he
Date:
Fri Mar 20 05:12:03 2015 +0000
Revision:
21:a9e9aa7da8db
Parent:
17:3b545dc0c800
Child:
22:986b3addda41
telemetry setup /not done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ericoneill 0:2002d645d2a6 1 #include "mbed.h"
ericoneill 2:3eb545c3e6a1 2 #include "rtos.h"
cheryl_he 21:a9e9aa7da8db 3 #include "MODSERIAL.h"
cheryl_he 14:09d61b20b102 4 #include "telemetry.h"
cheryl_he 21:a9e9aa7da8db 5 #include "telemetry-mbed.h"
ericoneill 0:2002d645d2a6 6
ericoneill 2:3eb545c3e6a1 7 // Camera Pins
ericoneill 2:3eb545c3e6a1 8 DigitalOut clk(PTA13);
ericoneill 2:3eb545c3e6a1 9 DigitalOut si(PTD4);
ericoneill 2:3eb545c3e6a1 10 AnalogIn camData(PTC2);
cheryl_he 21:a9e9aa7da8db 11
ericoneill 2:3eb545c3e6a1 12 //Servo, Motor, Serial Pins
ericoneill 2:3eb545c3e6a1 13 PwmOut servo(PTA5);
cheryl_he 10:85f486ad4e5f 14 PwmOut motor1(PTA4);
cheryl_he 10:85f486ad4e5f 15 PwmOut motor2(PTA12);
cheryl_he 10:85f486ad4e5f 16 DigitalOut break1(PTC12);
cheryl_he 10:85f486ad4e5f 17 DigitalOut break2(PTC13);
ericoneill 2:3eb545c3e6a1 18 Serial pc(USBTX, USBRX);
cheryl_he 21:a9e9aa7da8db 19
cheryl_he 21:a9e9aa7da8db 20 //Telemetry
cheryl_he 21:a9e9aa7da8db 21 MODSERIAL telemetry_serial(PTA2, PTA1);
cheryl_he 21:a9e9aa7da8db 22 telemetry::MbedHal telemetry_hal(telemetry_serial);
cheryl_he 21:a9e9aa7da8db 23 telemetry::Telemetry telemetry_obj(telemetry_hal);
cheryl_he 21:a9e9aa7da8db 24 telemetry::Numeric<uint32_t> tele_time_ms(telemetry_obj, "time", "Time", "ms", 0);
cheryl_he 21:a9e9aa7da8db 25 telemetry::NumericArray<uint16_t, 128> tele_linescan(telemetry_obj, "linescan", "Linescan", "ADC", 0);
cheryl_he 21:a9e9aa7da8db 26 telemetry::Numeric<float> tele_motor_pwm(telemetry_obj, "motor", "Motor PWM", "%DC", 0);
cheryl_he 21:a9e9aa7da8db 27 tele_motor_pwm.set_limits(0 ,1);
cheryl_he 21:a9e9aa7da8db 28
ericoneill 2:3eb545c3e6a1 29 // Interrupt for encoder
ericoneill 2:3eb545c3e6a1 30 InterruptIn interrupt(PTA13);
ericoneill 0:2002d645d2a6 31
ericoneill 12:45e6cb021301 32 float line [128];
ericoneill 12:45e6cb021301 33 Mutex line_mutex;
ericoneill 4:03594bf9a0de 34
ericoneill 4:03594bf9a0de 35 void linecam_thread(void const *args){
ericoneill 13:97708869a4ba 36 while(1){
ericoneill 13:97708869a4ba 37 line_mutex.lock();
ericoneill 13:97708869a4ba 38 pc.printf("[");
ericoneill 13:97708869a4ba 39 for(int i=0; i<128; i++){
ericoneill 13:97708869a4ba 40 pc.printf("%f",line[i]);
ericoneill 13:97708869a4ba 41 pc.printf(" ");
ericoneill 13:97708869a4ba 42 }
ericoneill 13:97708869a4ba 43 pc.printf("]");
ericoneill 13:97708869a4ba 44 }
ericoneill 5:764c2ffb523a 45
ericoneill 4:03594bf9a0de 46 }
ericoneill 4:03594bf9a0de 47
ericoneill 4:03594bf9a0de 48
ericoneill 0:2002d645d2a6 49 int main() {
ericoneill 4:03594bf9a0de 50 Thread thread(linecam_thread);
ericoneill 13:97708869a4ba 51 thread.set_priority(osPriorityIdle);
ericoneill 13:97708869a4ba 52 //thread.set_priority(-3);
ericoneill 12:45e6cb021301 53
ericoneill 16:fa13ac00f583 54 int integrationCounter = 0;
ericoneill 0:2002d645d2a6 55 while(1) {
ericoneill 16:fa13ac00f583 56 if(integrationCounter % 151== 0){
ericoneill 16:fa13ac00f583 57
ericoneill 16:fa13ac00f583 58 }
ericoneill 16:fa13ac00f583 59 else if (integrationCounter > 129){
ericoneill 16:fa13ac00f583 60 }
ericoneill 16:fa13ac00f583 61 else{
ericoneill 16:fa13ac00f583 62 clk = 1;
ericoneill 16:fa13ac00f583 63 wait_us(50);
ericoneill 16:fa13ac00f583 64 line[integrationCounter - 1] = camData;
ericoneill 16:fa13ac00f583 65 clk = 0;
ericoneill 16:fa13ac00f583 66 }
ericoneill 12:45e6cb021301 67
ericoneill 16:fa13ac00f583 68 integrationCounter++;
ericoneill 0:2002d645d2a6 69 }
ericoneill 0:2002d645d2a6 70 }