Code for the car to drive in a figure eight motion
Dependencies: mbed-rtos mbed MODSERIAL mbed-dsp telemetry
main.cpp@18:16f1297a4260, 2015-03-20 (annotated)
- Committer:
- ericoneill
- Date:
- Fri Mar 20 05:53:29 2015 +0000
- Revision:
- 18:16f1297a4260
- Parent:
- 17:3b545dc0c800
- Child:
- 19:29b3decea5e2
data acquisition;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ericoneill | 0:2002d645d2a6 | 1 | #include "mbed.h" |
ericoneill | 2:3eb545c3e6a1 | 2 | #include "rtos.h" |
cheryl_he | 14:09d61b20b102 | 3 | #include "telemetry.h" |
ericoneill | 0:2002d645d2a6 | 4 | |
ericoneill | 2:3eb545c3e6a1 | 5 | // Camera Pins |
ericoneill | 18:16f1297a4260 | 6 | DigitalOut clk(PTD5); |
ericoneill | 2:3eb545c3e6a1 | 7 | DigitalOut si(PTD4); |
ericoneill | 2:3eb545c3e6a1 | 8 | AnalogIn camData(PTC2); |
ericoneill | 2:3eb545c3e6a1 | 9 | //Servo, Motor, Serial Pins |
ericoneill | 2:3eb545c3e6a1 | 10 | PwmOut servo(PTA5); |
cheryl_he | 10:85f486ad4e5f | 11 | PwmOut motor1(PTA4); |
cheryl_he | 10:85f486ad4e5f | 12 | PwmOut motor2(PTA12); |
cheryl_he | 10:85f486ad4e5f | 13 | DigitalOut break1(PTC12); |
cheryl_he | 10:85f486ad4e5f | 14 | DigitalOut break2(PTC13); |
ericoneill | 2:3eb545c3e6a1 | 15 | Serial pc(USBTX, USBRX); |
ericoneill | 2:3eb545c3e6a1 | 16 | // Interrupt for encoder |
ericoneill | 2:3eb545c3e6a1 | 17 | InterruptIn interrupt(PTA13); |
ericoneill | 18:16f1297a4260 | 18 | const int maxFrames = 10; |
ericoneill | 18:16f1297a4260 | 19 | float frames[maxFrames][128]; |
ericoneill | 18:16f1297a4260 | 20 | float ADCdata [128]; |
ericoneill | 12:45e6cb021301 | 21 | Mutex line_mutex; |
ericoneill | 4:03594bf9a0de | 22 | |
ericoneill | 4:03594bf9a0de | 23 | void linecam_thread(void const *args){ |
ericoneill | 13:97708869a4ba | 24 | while(1){ |
ericoneill | 18:16f1297a4260 | 25 | //line_mutex.lock(); |
ericoneill | 13:97708869a4ba | 26 | pc.printf("["); |
ericoneill | 13:97708869a4ba | 27 | for(int i=0; i<128; i++){ |
ericoneill | 18:16f1297a4260 | 28 | //pc.printf("%f",ADCdata[i]); |
ericoneill | 13:97708869a4ba | 29 | pc.printf(" "); |
ericoneill | 13:97708869a4ba | 30 | } |
ericoneill | 13:97708869a4ba | 31 | pc.printf("]"); |
ericoneill | 18:16f1297a4260 | 32 | //line_mutex.unlock(); |
ericoneill | 13:97708869a4ba | 33 | } |
ericoneill | 5:764c2ffb523a | 34 | |
ericoneill | 4:03594bf9a0de | 35 | } |
ericoneill | 4:03594bf9a0de | 36 | |
ericoneill | 4:03594bf9a0de | 37 | |
ericoneill | 0:2002d645d2a6 | 38 | int main() { |
ericoneill | 18:16f1297a4260 | 39 | //Thread thread(linecam_thread); |
ericoneill | 18:16f1297a4260 | 40 | //thread.set_priority(osPriorityIdle); |
ericoneill | 18:16f1297a4260 | 41 | pc.printf("Beginning linecam data acquisition... "); |
ericoneill | 18:16f1297a4260 | 42 | for(int numFrames = 0; numFrames < maxFrames; numFrames++){ |
ericoneill | 18:16f1297a4260 | 43 | for(int integrationCounter = 0;integrationCounter < 151;) { |
ericoneill | 18:16f1297a4260 | 44 | if(integrationCounter % 151== 0){ |
ericoneill | 18:16f1297a4260 | 45 | si = 1; |
ericoneill | 18:16f1297a4260 | 46 | clk = 1; |
ericoneill | 18:16f1297a4260 | 47 | //wait(.00001); |
ericoneill | 18:16f1297a4260 | 48 | si = 0; |
ericoneill | 18:16f1297a4260 | 49 | clk = 0; |
ericoneill | 18:16f1297a4260 | 50 | integrationCounter = 0; |
ericoneill | 18:16f1297a4260 | 51 | |
ericoneill | 18:16f1297a4260 | 52 | |
ericoneill | 18:16f1297a4260 | 53 | } |
ericoneill | 18:16f1297a4260 | 54 | else if (integrationCounter > 129){ |
ericoneill | 18:16f1297a4260 | 55 | |
ericoneill | 18:16f1297a4260 | 56 | |
ericoneill | 18:16f1297a4260 | 57 | integrationCounter = 150; |
ericoneill | 18:16f1297a4260 | 58 | } |
ericoneill | 18:16f1297a4260 | 59 | else{ |
ericoneill | 18:16f1297a4260 | 60 | clk = 1; |
ericoneill | 18:16f1297a4260 | 61 | wait_us(50); |
ericoneill | 18:16f1297a4260 | 62 | //line_mutex.lock(); |
ericoneill | 18:16f1297a4260 | 63 | frames[numFrames][integrationCounter - 1] = camData; |
ericoneill | 18:16f1297a4260 | 64 | //line_mutex.unlock(); |
ericoneill | 18:16f1297a4260 | 65 | clk = 0; |
ericoneill | 18:16f1297a4260 | 66 | } |
ericoneill | 12:45e6cb021301 | 67 | |
ericoneill | 18:16f1297a4260 | 68 | integrationCounter++; |
ericoneill | 16:fa13ac00f583 | 69 | |
ericoneill | 16:fa13ac00f583 | 70 | } |
ericoneill | 18:16f1297a4260 | 71 | //frames[numFrames] = ADCdata; |
ericoneill | 18:16f1297a4260 | 72 | } |
ericoneill | 18:16f1297a4260 | 73 | |
ericoneill | 18:16f1297a4260 | 74 | for(int i =0; i<maxFrames; i++){ |
ericoneill | 18:16f1297a4260 | 75 | pc.printf("["); |
ericoneill | 18:16f1297a4260 | 76 | for(int j = 0; j < 128; j++){ |
ericoneill | 18:16f1297a4260 | 77 | pc.printf(" %f",frames[i][j]); |
ericoneill | 16:fa13ac00f583 | 78 | } |
ericoneill | 18:16f1297a4260 | 79 | pc.printf("]\n\r"); |
ericoneill | 0:2002d645d2a6 | 80 | } |
ericoneill | 0:2002d645d2a6 | 81 | } |