code:camera_driver
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | code:camera_driver [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | === Camera driver tutorial === | ||
+ | |||
+ | The aim of this tutorial is to create a camera (CCD) driver. In order to be | ||
+ | hardware independent, | ||
+ | camera - it will create a test (dummy) driver, which can be used to show how | ||
+ | the RTS2 works. | ||
+ | |||
+ | The believe is that this tutorial will enable interesting parties to write own | ||
+ | camera driver for theirs special hardware. | ||
+ | |||
+ | === Preparations - creating source file, Makefile === | ||
+ | |||
+ | First, change to rts2/ | ||
+ | the driver resides. | ||
+ | |||
+ | New camera driver shall be added to Makefile, so it will be properly generated | ||
+ | when automake machinery is invoked. To do this, add following lines to the end | ||
+ | of Makefile.am (in rts2/ | ||
+ | |||
+ | <code make> | ||
+ | |||
+ | bin_PROGRAMS += rts2-camd-test | ||
+ | rts2_camd_test_SOURCES = test.cpp | ||
+ | |||
+ | </ | ||
+ | |||
+ | Please note that as variables in Makefile.am must contain legal characters for | ||
+ | shell variable name, ' | ||
+ | rts2_camd_test_SOURCES is used, instead of rts2-camd-test_SOURCES. The automake | ||
+ | machinery takes care of replacing ' | ||
+ | |||
+ | The above lines instruct automake to add ' | ||
+ | programs make shall produce. And tells make, that rts2-camd-test shall be | ||
+ | produced from test.cpp source. | ||
+ | |||
+ | === Adding the source code === | ||
+ | |||
+ | Looking into | ||
+ | [[http:// | ||
+ | file, you will find that there are two pure virtual methods: | ||
+ | |||
+ | <code c++> | ||
+ | virtual int startExposure () = 0; | ||
+ | |||
+ | virtual int doReadout () = 0; | ||
+ | </ | ||
+ | |||
+ | We need to implement those. We also need to set width and height of the chip in | ||
+ | initChips. The generated data needs to be send with sendReadoutData method. See | ||
+ | the code below for full example: | ||
+ | |||
+ | <code c++> | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | #define TEST_WIDTH 100 | ||
+ | #define TEST_HEIGHT 200 | ||
+ | |||
+ | namespace rts2camd | ||
+ | { | ||
+ | |||
+ | class Test:public Camera | ||
+ | { | ||
+ | public: | ||
+ | Test (int argc, char **argv): | ||
+ | { | ||
+ | initCameraChip (TEST_WIDTH, | ||
+ | } | ||
+ | |||
+ | protected: | ||
+ | |||
+ | virtual int startExposure () | ||
+ | { | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | virtual int doReadout () | ||
+ | { | ||
+ | uint16_t data[TEST_WIDTH * TEST_HEIGHT]; | ||
+ | for (int i = 0; i < TEST_WIDTH * TEST_HEIGHT; | ||
+ | data[i] = random_num () * 100; | ||
+ | |||
+ | int ret = sendReadoutData ((char*) data, TEST_WIDTH * TEST_HEIGHT * sizeof (uint16_t), 0); | ||
+ | if (ret < 0) | ||
+ | return ret; | ||
+ | |||
+ | if (getWriteBinaryDataSize () == 0) | ||
+ | return -2; | ||
+ | return 0; | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | } | ||
+ | |||
+ | int main (int argc, char **argv) | ||
+ | { | ||
+ | rts2camd:: | ||
+ | return testcam.run (); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Place this content to src/ | ||
+ | |||
+ | === Building rts2-camd-test === | ||
+ | |||
+ | First, you need to make sure the changes in Makefile.am propagates to | ||
+ | Makefile.in and then to Makefile. Usually, you will need at least to run | ||
+ | automake RTS2 top directory (the directory with src and include subdirectories, | ||
+ | usually rts2). After running automake, just run make && sudo make install. | ||
+ | |||
+ | That should make rts2-camd-test available in the path. To launch those, just: | ||
+ | |||
+ | <code bash> | ||
+ | rts2-centrald | ||
+ | rts2-camd-test | ||
+ | </ | ||
+ | |||
+ | === Testing camera test driver === | ||
+ | |||
+ | First, run rts2-mon to verify you see C0 in device list. Your terminal window shall look like depicted below: | ||
+ | |||
+ | Then, run rts2-xfocusc -d C0 to get images from the camera. This shall create | ||
+ | window with random content of the image, as depicted below: | ||
+ | |||
+ | === Complicating it === | ||
+ | |||
+ | If you follow sucesfully the example to this line, congratulations - you | ||
+ | created working sceleton of the camera driver. To make it work with your | ||
+ | hardware, just implement startExposure and doReadout methods to start an | ||
+ | exposure and get data from the camera. | ||
code/camera_driver.txt · Last modified: 2014/04/01 00:00 (external edit)