capstone_finish
Dependencies: BufferedSerial motor_sn7544
main.cpp@7:152fba230106, 2019-09-05 (annotated)
- Committer:
- kangmingyo
- Date:
- Thu Sep 05 13:04:01 2019 +0000
- Revision:
- 7:152fba230106
- Parent:
- 6:fe8b32cb9357
- Child:
- 8:221b2fc093e4
0905;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mio | 0:f3f80a0695ff | 1 | // |
mio | 0:f3f80a0695ff | 2 | // OV7670 + FIFO AL422B camera board test |
mio | 0:f3f80a0695ff | 3 | // |
mio | 0:f3f80a0695ff | 4 | #include "mbed.h" |
mio | 0:f3f80a0695ff | 5 | #include "ov7670.h" |
Jeonghoon | 3:2a3664dc6634 | 6 | #include <ros.h> |
Jeonghoon | 3:2a3664dc6634 | 7 | #include <ros/time.h> |
Jeonghoon | 3:2a3664dc6634 | 8 | #include <std_msgs/UInt8MultiArray.h> |
kangmingyo | 2:e98408458d2b | 9 | |
Jeonghoon | 3:2a3664dc6634 | 10 | std_msgs::UInt8MultiArray img; |
Jeonghoon | 3:2a3664dc6634 | 11 | ros::NodeHandle nh; |
Jeonghoon | 3:2a3664dc6634 | 12 | ros::Publisher img_pub("image_data", &img); |
kangmingyo | 2:e98408458d2b | 13 | |
mio | 0:f3f80a0695ff | 14 | |
kangmingyo | 7:152fba230106 | 15 | |
mio | 0:f3f80a0695ff | 16 | OV7670 camera( |
kangmingyo | 2:e98408458d2b | 17 | D14,D15, // SDA,SCL(I2C / SCCB) |
kangmingyo | 4:7b63cf3d205f | 18 | D9,D8,D11, // VSYNC,HREF,WEN(FIFO) |
mio | 0:f3f80a0695ff | 19 | //p18,p17,p16,p15,p11,p12,p14,p13, // D7-D0 |
kangmingyo | 7:152fba230106 | 20 | PortB,0x00FF, |
kangmingyo | 7:152fba230106 | 21 | D13,D12,D6,D2) ; // RRST,OE,RCLK,WRST |
mio | 0:f3f80a0695ff | 22 | |
Jeonghoon | 3:2a3664dc6634 | 23 | //Serial pc(USBTX,USBRX,115200) ; |
kangmingyo | 7:152fba230106 | 24 | |
mio | 0:f3f80a0695ff | 25 | |
kangmingyo | 2:e98408458d2b | 26 | //#undef QQVGA |
kangmingyo | 2:e98408458d2b | 27 | #define QQVGA |
mio | 1:509676f3be32 | 28 | |
mio | 0:f3f80a0695ff | 29 | #ifdef QQVGA |
kangmingyo | 7:152fba230106 | 30 | # define SIZEX (160) |
kangmingyo | 7:152fba230106 | 31 | # define SIZEY (120) |
kangmingyo | 7:152fba230106 | 32 | # define NUMBYTE (2) |
mio | 0:f3f80a0695ff | 33 | #else |
mio | 0:f3f80a0695ff | 34 | # define SIZEX (320) |
mio | 0:f3f80a0695ff | 35 | # define SIZEY (240) |
mio | 0:f3f80a0695ff | 36 | #endif |
mio | 0:f3f80a0695ff | 37 | |
Jeonghoon | 3:2a3664dc6634 | 38 | |
Jeonghoon | 3:2a3664dc6634 | 39 | uint8_t fdata[SIZEX*SIZEY]; |
kangmingyo | 7:152fba230106 | 40 | uint8_t fdata_ros[480]; |
kangmingyo | 7:152fba230106 | 41 | |
kangmingyo | 7:152fba230106 | 42 | uint8_t dummy; |
Jeonghoon | 3:2a3664dc6634 | 43 | |
Jeonghoon | 3:2a3664dc6634 | 44 | size_t size = SIZEX*SIZEY; |
kangmingyo | 2:e98408458d2b | 45 | |
kangmingyo | 7:152fba230106 | 46 | int main() |
kangmingyo | 7:152fba230106 | 47 | { |
kangmingyo | 7:152fba230106 | 48 | wait_ms(1); |
Jeonghoon | 3:2a3664dc6634 | 49 | // pc.baud(115200) ; |
mio | 0:f3f80a0695ff | 50 | camera.Reset() ; |
Jeonghoon | 3:2a3664dc6634 | 51 | nh.advertise(img_pub); |
mio | 0:f3f80a0695ff | 52 | |
mio | 0:f3f80a0695ff | 53 | #ifdef QQVGA |
kangmingyo | 2:e98408458d2b | 54 | // camera.InitQQVGA565(true,false) ; |
kangmingyo | 6:fe8b32cb9357 | 55 | camera.InitQQVGAYUV(false,false); |
kangmingyo | 2:e98408458d2b | 56 | |
kangmingyo | 7:152fba230106 | 57 | #else |
kangmingyo | 2:e98408458d2b | 58 | //camera.InitQVGA565(true,false) ; |
mio | 0:f3f80a0695ff | 59 | #endif |
kangmingyo | 7:152fba230106 | 60 | |
kangmingyo | 7:152fba230106 | 61 | |
mio | 0:f3f80a0695ff | 62 | // CAPTURE and SEND LOOP |
kangmingyo | 7:152fba230106 | 63 | |
kangmingyo | 7:152fba230106 | 64 | |
kangmingyo | 7:152fba230106 | 65 | while(1) { |
kangmingyo | 7:152fba230106 | 66 | |
kangmingyo | 7:152fba230106 | 67 | |
mio | 0:f3f80a0695ff | 68 | camera.CaptureNext() ; |
mio | 0:f3f80a0695ff | 69 | while(camera.CaptureDone() == false) ; |
Jeonghoon | 3:2a3664dc6634 | 70 | |
mio | 0:f3f80a0695ff | 71 | camera.ReadStart() ; |
kangmingyo | 7:152fba230106 | 72 | |
Jeonghoon | 3:2a3664dc6634 | 73 | for (int y = 0; y < SIZEX*SIZEY ; y++) { |
Jeonghoon | 3:2a3664dc6634 | 74 | camera.ReadOneByte(); |
Jeonghoon | 3:2a3664dc6634 | 75 | fdata[y]=camera.ReadOneByte(); |
mio | 0:f3f80a0695ff | 76 | } |
Jeonghoon | 3:2a3664dc6634 | 77 | |
kangmingyo | 7:152fba230106 | 78 | camera.ReadStop() ; |
kangmingyo | 7:152fba230106 | 79 | |
kangmingyo | 7:152fba230106 | 80 | for(int x=0; x<40; x++) { |
kangmingyo | 7:152fba230106 | 81 | for(int y=0; y<480; y++) { |
kangmingyo | 7:152fba230106 | 82 | fdata_ros[y]=fdata[(480*(x))+y]; |
kangmingyo | 7:152fba230106 | 83 | } |
Jeonghoon | 3:2a3664dc6634 | 84 | |
kangmingyo | 7:152fba230106 | 85 | img.data_length = 480; |
kangmingyo | 7:152fba230106 | 86 | img.data = &fdata_ros[0]; |
kangmingyo | 7:152fba230106 | 87 | img_pub.publish(&img); |
kangmingyo | 7:152fba230106 | 88 | nh.spinOnce(); |
kangmingyo | 7:152fba230106 | 89 | wait_ms(600); //max... |
kangmingyo | 7:152fba230106 | 90 | } |
Jeonghoon | 3:2a3664dc6634 | 91 | |
kangmingyo | 7:152fba230106 | 92 | |
kangmingyo | 7:152fba230106 | 93 | |
Jeonghoon | 3:2a3664dc6634 | 94 | } |
mio | 0:f3f80a0695ff | 95 | } |