This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:examples:vision [2012/05/16 13:21] – created raivo.sell | en:examples:vision [2026/02/19 11:30] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | < |
| - | <note important> | + | ====== |
| + | ===== CMUCam3 camera emulation as CMUCam2 ===== | ||
| - | ===== CMUCam3 kaamera emuleerimine CMUCam2-ena ===== | + | === Required software and references |
| - | + | - [[http:// | |
| - | ===Vajalik tarkvara ja kirjandus=== | + | - [[http:// |
| - | - [[http:// | + | - [[http:// |
| - | - [[http:// | + | |
| - | - [[http:// | + | |
| - [[http:// | - [[http:// | ||
| - | - [[http:// | + | - [[http:// |
| - | - [[http:// | + | - [[http:// |
| - | - [[http:// | + | - [[http:// |
| - | ===Sissejuhatus=== | + | === Introduction |
| - | CMUCam3 | + | CMUCam3 |
| - | ===Kaamera seadistamine=== | + | === Camera setup === |
| - | CMUCam3 | + | To emulate the CMUCam2 with a CMUCam3 |
| - | ===CMUCam2 GUI=== | + | === CMUCam2 GUI === |
| - | Tegemist on arvutile mõeldud graafilise kasutajaliidesega, | + | This is a graphical user interface for a computer that lets you view camera images and test other functions. The GUI tutorial is in link 3 and the software in link 4. Note that this is a Java program, so you need a JRE (Java Runtime Environment) |
| - | Programmi kasutamiseks tuleb kaamera ühendada võimaluse korral otse arvuti | + | To use the program, connect the camera directly to the computer |
| - | Üleval ääres on menüü, kust saab erinevaid funktsioone valida, nagu näiteks servode liigutamine. Kaamera pildi vaatamiseks tuleb minna vahelehele | + | At the top there is a menu where you can select different functions, such as moving servos. To view the camera image, go to the " |
| - | Kaamera vaheleht on veel selle poolest väga tähtis, et pildil soovitud värvil klikates saab teada selle koodi. Samal ajal tõstetakse teised sama värvi pikslid kah esile. | + | The Camera tab is important because clicking a color in the image shows its code. At the same time, other pixels of the same color are highlighted. |
| - | {{: | + | {{: |
| - | Pilt 1. Kaamera | + | Figure |
| - | Pildil kaks on toodud | + | In Figure 2 the " |
| - | {{: | + | {{: |
| - | Pilt 2. Color Tracking | + | Figure |
| - | Kodulaboriga värviotsimist tehes on antud programmiga hea värvivahemik määrata, mida otsida ja see reaalselt ära testida. Kodulabori väikesel ekraanil on ainult numbriline info ja selle järgi midagi kindlaks määrata on võimatu. | + | When searching for colors with HomeLab, this program is useful for determining the color range to track and testing it in practice. On the HomeLab small display you only have numeric information, |
| - | ===== CMUCam3 | + | ===== Using the CMUCam3 |
| - | Antud näited on mõeldud kasutama | + | These examples are intended for using the CMUCam3 |
| - | ==== Kodulabori tarkvara | + | ==== HomeLab software |
| - | Kodulabori poolne näitekood on tehtud, kasutades nii palju kui võimalik Kodulabori teeki. Siiski | + | The HomeLab example code is built as much as possible using the HomeLab library. However, |
| - | Failis | + | In CMUCAM.c, the camera-specific functions are located. Currently it includes color search and data reception. Because there are many commands, it is recommended to extend this file as needed, adding support for new packets, etc. |
| - | Fail USART.c | + | USART.c |
| - | ==== Värvi otsimine | + | ==== Color tracking |
| - | ==Vajalik riistvara== | + | == Required hardware |
| - CMUCam3 | - CMUCam3 | ||
| - | - Kodulabori Kontrollermoodul | + | - HomeLab Controller module |
| - | - Kodulabori Kommunikatsioonimoodul | + | - HomeLab Communication module |
| - | - Kodulabori Kasutajaliidese moodul | + | - HomeLab User Interface module |
| - | ==Kirjeldus== | + | == Description |
| - | Programm seadistab | + | The program configures the CMU camera to track a specific color. The center coordinates of the rectangle drawn around the color area are displayed on the HomeLab screen. |
| - | ekraanil kuvatakse ümber seda värvi ala joonistatud ristküliku keskpunkti | + | |
| - | koordinadid. | + | |
| - | {{: | + | {{: |
| - | Pilt 3. Programm koordinaate kuvamas | + | Figure |
| - | ==Kasutamine== | + | == Usage == |
| - | Ühenda moodulid kokku. Lülita kaamera toitelüliti sisse. | + | Connect the modules. Turn on the camera power switch. |
| - | Vajutades nupule | + | Pressing button |
| - | ekraanil formaadi | + | |
| - | ristküliku keskpunkti koordinaadid. Kui värvi ei nähta kuvatakse nullid. Programm on | + | |
| - | seadistatud otsima oranzhi värvi. | + | |
| * {{: | * {{: | ||
| - | ==== Lihtne | + | ==== Simple |
| - | ==Vajalik riistvara== | + | == Required hardware |
| - CMUCam3 | - CMUCam3 | ||
| - | - Kodulabori Kontrollermoodul | + | - HomeLab Controller module |
| - | - Kodulabori Kommunikatsioonimoodul | + | - HomeLab Communication module |
| - | - Kodulabori Kasutajaliidese moodul | + | - HomeLab User Interface module |
| - | ==Kirjeldus== | + | == Description |
| - | Programm kuvab suvalisi | + | The program displays random |
| - | nuppude abil kaamerat algväärtustada, värvi otsida ja tarkvara versiooni küsida. | + | |
| - | ==Kasutamine== | + | == Usage == |
| - | Ühenda moodulid kokku. Lülita kaamera toitelüliti sisse. | + | Connect the modules. Turn on the camera power switch. |
| - | Vajutades nupule | + | Press S1 to display the camera firmware version. S2 starts the preset color tracking. S3 resets the camera. |
| - | eelseadistatud värvi otsima. Nupp S3 aga resetib kaamera. | + | |
| * {{: | * {{: | ||
| + | <code c> | ||
| + | // | ||
| + | // CMU CAM 3 juhtimisega seotud funktsioonid | ||
| + | // 2011 | ||
| + | // Autor: Heiko Pikner | ||
| + | // | ||
| + | |||
| + | #include " | ||
| + | |||
| + | |||
| + | // | ||
| + | // Globaalsed muutujad | ||
| + | // | ||
| + | volatile char str_x[5]; | ||
| + | volatile char str_y[5]; | ||
| + | volatile int8_t packet_received = 0; | ||
| + | int8_t packet_t_typ=0; | ||
| + | int8_t pitcounter =0; | ||
| + | |||
| + | // | ||
| + | // Funktsiooni päised | ||
| + | // | ||
| + | void USART_Transmit(unsigned char); | ||
| + | |||
| + | // | ||
| + | // | ||
| + | // Pakettide tõlgendamine ja andmete töötlemine | ||
| + | // | ||
| + | // | ||
| + | void CMUPacketHandler(unsigned char c) | ||
| + | { | ||
| + | |||
| + | |||
| + | // Paketi tähise järgi T paketi tuvastamine | ||
| + | if(c==0x54) | ||
| + | { | ||
| + | packet_t_typ=1; | ||
| + | |||
| + | } | ||
| + | |||
| + | // Paketist Mx ja My eraldamine. Kumbki võib olla 1-3 kohaline | ||
| + | // number. Numbrid on eraldatud tühikutega. Mx talletatakse str_x massiivi | ||
| + | // ja My str_y massivi. Iga massiivi element on üks number. | ||
| + | if(packet_t_typ ==1) | ||
| + | { | ||
| + | pitcounter++; | ||
| + | |||
| + | |||
| + | if(pitcounter==3) | ||
| + | { | ||
| + | |||
| + | str_x[0]=c; | ||
| + | } | ||
| + | |||
| + | if(pitcounter==4) | ||
| + | { | ||
| + | if(c == 0x20) | ||
| + | { | ||
| + | pitcounter=6; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | |||
| + | str_x[1]=c; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | if(pitcounter == 5) | ||
| + | { | ||
| + | |||
| + | if(c == 0x20) | ||
| + | { | ||
| + | pitcounter=6; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | str_x[2]=c; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | if(pitcounter==7) | ||
| + | { | ||
| + | str_y[0]=c; | ||
| + | |||
| + | } | ||
| + | if((pitcounter==8)&& | ||
| + | { | ||
| + | if(c == 0x20) | ||
| + | { | ||
| + | pitcounter=6; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | str_y[1]=c; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | if((pitcounter==9)&& | ||
| + | { | ||
| + | if(c == 0x20) | ||
| + | { | ||
| + | pitcounter=6; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | |||
| + | str_y[2]=c; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | if(c == 0x0D) | ||
| + | { | ||
| + | packet_t_typ=0; | ||
| + | pitcounter=0; | ||
| + | packet_received = 1; | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | // | ||
| + | // | ||
| + | // | ||
| + | // | ||
| + | // | ||
| + | void GetVersion(void) | ||
| + | { | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | } | ||
| + | |||
| + | // | ||
| + | // | ||
| + | // | ||
| + | // | ||
| + | // | ||
| + | void ResetCam(void) | ||
| + | { | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | } | ||
| + | |||
| + | // | ||
| + | // | ||
| + | // Alusta valitud värvi trakkimist. Saada mask 'OM 0 3' ja seejärel | ||
| + | // 'TC 184 234 4 54 0 41' | ||
| + | // | ||
| + | // | ||
| + | void StartTracking(void) | ||
| + | { | ||
| + | // Sea mask, et kaamera saadaks ainult Mx ja My koordinaadid | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | | ||
| + | |||
| + | //Värvi valimiseks on formaat minRed maxRed minGreen maxGreen minBlue maxBlue | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | |||
| + | |||
| + | |||
| + | USART_Transmit(' | ||
| + | USART_Transmit(' | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #include " | ||
| + | |||
| + | // | ||
| + | //Muutujad, mis on defineeritud mujal | ||
| + | // | ||
| + | |||
| + | extern volatile int8_t packet_received; | ||
| + | |||
| + | extern volatile char str_x[5]; | ||
| + | extern volatile char str_y[5]; | ||
| + | |||
| + | |||
| + | // | ||
| + | //Nuppude viikude valik | ||
| + | // | ||
| + | pin button1 = PIN(C, 0); | ||
| + | pin button2 = PIN(C, 1); | ||
| + | pin button3 = PIN(C, 2); | ||
| + | |||
| + | |||
| + | // | ||
| + | // Seadista süsteem | ||
| + | // | ||
| + | static inline void init() | ||
| + | { | ||
| + | // Seab nupud töökorda | ||
| + | pin_setup_input_with_pullup(button1); | ||
| + | pin_setup_input_with_pullup(button2); | ||
| + | pin_setup_input_with_pullup(button3); | ||
| + | |||
| + | // LCD ekraani algseadistamine | ||
| + | lcd_gfx_init(); | ||
| + | |||
| + | // Ekraani puhastamine | ||
| + | lcd_gfx_clear(); | ||
| + | |||
| + | // Taustavalgustuse tööle lülitamine | ||
| + | lcd_gfx_backlight(true); | ||
| + | |||
| + | // Programmi nime kuvamine | ||
| + | lcd_gfx_goto_char_xy(3, | ||
| + | lcd_gfx_write_string(" | ||
| + | |||
| + | // Kuva Mx | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(" | ||
| + | |||
| + | // Kuva My | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(" | ||
| + | |||
| + | |||
| + | DDRE = (1<< | ||
| + | |||
| + | // Seriali seadistamine | ||
| + | UsartInit(); | ||
| + | |||
| + | // Katkestuste lubamine | ||
| + | sei(); | ||
| + | } | ||
| + | |||
| + | // | ||
| + | // | ||
| + | //MAIN | ||
| + | // | ||
| + | // | ||
| + | int main(void) | ||
| + | { | ||
| + | unsigned char new_value1, old_value1 = 0, new_value2, | ||
| + | old_value2 = 0, new_value3, old_value3 = 0; | ||
| + | |||
| + | |||
| + | // Seadista süsteem | ||
| + | init(); | ||
| + | |||
| + | |||
| + | while (1) | ||
| + | { | ||
| + | |||
| + | // Loeb nuppude väärtused | ||
| + | new_value1 = pin_get_debounced_value(button1); | ||
| + | new_value2 = pin_get_debounced_value(button2); | ||
| + | new_value3 = pin_get_debounced_value(button3); | ||
| + | |||
| + | // Nupp S1 alla vajutatud | ||
| + | if((!new_value1) && (old_value1)) | ||
| + | { | ||
| + | |||
| + | // Tee midagi | ||
| + | } | ||
| + | |||
| + | // Nupp S2 alla vajutatud | ||
| + | if((!new_value2) && (old_value2)) | ||
| + | { | ||
| + | // Alusta värvi otsimist | ||
| + | StartTracking(); | ||
| + | |||
| + | } | ||
| + | |||
| + | // Nupp S3 alla vajutatud | ||
| + | if((!new_value3) && (old_value3)) | ||
| + | { | ||
| + | // Tee midagi | ||
| + | |||
| + | } | ||
| + | |||
| + | // Jätab eelmised nupuväärtused meelde | ||
| + | old_value1 = new_value1; | ||
| + | old_value2 = new_value2; | ||
| + | old_value3 = new_value3; | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | // Kui pakett on saabunud, kuvab selle sisu ekraanile | ||
| + | if(packet_received == 1) | ||
| + | { | ||
| + | // Vii kursor algusesse | ||
| + | lcd_gfx_goto_char_xy(6, | ||
| + | |||
| + | // Kuva klobaalsest muutujast pakett ja kuva see | ||
| + | lcd_gfx_write_string((char*) & | ||
| + | |||
| + | // Vii kursor algusesse | ||
| + | lcd_gfx_goto_char_xy(6, | ||
| + | |||
| + | // Kuva klobaalsest muutujast pakett ja kuva see | ||
| + | lcd_gfx_write_string((char*) & | ||
| + | |||
| + | |||
| + | |||
| + | // Kustuta vana pakett, ehk täida see tühikutega | ||
| + | memset((char*) &str_x, 0x20, 4); | ||
| + | memset((char*) &str_y, 0x20, 4); | ||
| + | |||
| + | // Nulli paketi saabumist märkiv lipp | ||
| + | packet_received = 0; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | } | ||
| + | </ | ||