/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X XYθズレ計測 ZURE3J2.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/09/02 Ver 2.0 00/05/19 パラメータ設定パッド追加、その他 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* * Include compiler runtime library */ #include #include /* * Include CSC90X library */ #include "f_stdlib.h" #include "f_time.h" #include "f_gui.h" #include "f_stdio.h" #include "f_graph.h" #include "f_image.h" #include "f_pinf.h" #include "f_video.h" #include "f_system.h" #include "f_search.h" #include "f_math.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void para_set( void ); void gs_joken( void ); void ptn_reg( void ); void ptn_disp( void ); void wind_set( void ); void kijun ( void ); void exec( void ); int search( int *, int *, int *, int * ); int d4i5_d( double ); void cross_mark( int, int, int ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " EXEC ", " ズレ計測 " }, { " PROC3 ", " 処理3 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 static char *select[3] = { "通常", " 高", "超高" }; int sts; char ss[40]; double dw; double cpx, cpy; int MAS_x_center; /* 基準値(x方向中点10倍値) */ int MAS_y_center; /* 基準値(y方向中点10倍値) */ int MAS_angle; /* 基準値(角度10倍値) */ int name1, name2; /* グレイパタン名称 */ int wwxa, wwya, wwxb, wwyb; int wwsotai_x, wwsotai_y; int wwx_center, wwy_center, wwangle; int wwx, wwy; int zure_x_center; /* ズレ(x方向中点) */ int zure_y_center; /* ズレ(y方向中点) */ int zure_angle; /* ズレ(角度) */ int wxs; /* サーチ範囲始点X */ int wys; /* サーチ範囲始点Y */ int wxe; /* サーチ範囲終点X */ int wye; /* サーチ範囲終点Y */ int seido; /* 精度 */ int complex; /* 複雑度 */ int mid_lower; /* 途中下限値 */ int last_lower; /* 最終下限値 */ /* * メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; name1 = 0x314e5450; /* ptn1 */ name2 = 0x324e5450; /* ptn2 */ MAS_x_center = 2550; /* 基準値x方向中点(10倍値) */ MAS_y_center = 2400; /* 基準値y方向中点(10倍値) */ MAS_angle = 450; /* 基準値角度(10倍値) */ wxs = 0; wys = 0; wxe = 511; wye = 479; seido = 1; complex = 1; mid_lower = 5000; last_lower = 7000; /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* カーソル初期化 */ Lib_init_cursor(); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /*GRAY_PTN.SYSを使用する*/ if ( NORMAL_RETURN == Lib_gs_open_data_file( CONTINUE_PTN_AREA ) ) { /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); para_set(); /* 設定 */ main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); exec(); /* ズレ計測 */ main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } Lib_gs_close_data_file(); } else Lib_display_message( 100, 200, "エラー", "パタンエリアは使用できません" ); } /* * メインメニュー表示 */ static void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)NULL, (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 ZURE3J2" ); Lib_chrdisp( 11, 10, "対象物の基準位置からのズレ(XYθ)を計測する" ); Lib_chrdisp( 11, 12, "サンプルです。" ); Lib_chrdisp( 11, 14, "サーチパタンを2個登録し、2パタン間の中点座標" ); Lib_chrdisp( 11, 16, "及び、2パタンを結ぶ直線の角度を基準値として" ); Lib_chrdisp( 11, 18, "あらかじめ取得します。" ); Lib_chrdisp( 11, 20, "計測時には基準位置とのズレ量を表\示します。" ); Lib_chrdisp( 11, 22, "サーチパタンは円形のものが適しています。" ); Lib_chrdisp( 11, 24, "それ以外の形状をサーチパタンとした場合は、角度の" ); Lib_chrdisp( 11, 26, "ズレが2〜3度以上になるとエラーになる場合があります。" ); } /************************************************************************/ /* 設定 */ /************************************************************************/ void para_set( void ) { int pad_level; int status_flag; int rtn; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); Lib_view_set_null( pad_level, 5, 5, "サーチ条件" , 0 ); Lib_view_set_null( pad_level, 5, 35, "パタン登録" , 1 ); Lib_view_set_null( pad_level, 5, 65, "パタン表\示" , 2 ); Lib_view_set_null( pad_level, 5, 95, "サーチ範囲" , 3 ); Lib_view_set_null( pad_level, 5, 125, "基準値取得" , 4 ); Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_command( pad_level ); for ( status_flag = ON; OFF != status_flag; ) { if ( ERROR_RETURN != ( rtn = Lib_process_command( pad_level ) ) ) { switch( rtn ) { case 0:/* サーチ条件 */ gs_joken(); break; case 1:/* パタン登録 */ ptn_reg(); break; case 2:/*パタン表示*/ ptn_disp(); break; case 3:/* サーチ範囲 */ wind_set(); break; case 4:/* 基準値取得 */ kijun(); break; case 102:/* 終了 */ status_flag = OFF; break; } } } Lib_erase_command( pad_level ); Lib_view_close( pad_level ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /************************************************************************/ /* サーチ条件設定 */ /************************************************************************/ void gs_joken( void ) { int pad_level_gs; PVAL value_gs[4]; int no; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); pad_level_gs = Lib_view_open(); Lib_view_set_title( pad_level_gs, "サーチ条件" ); Lib_view_set_select ( pad_level_gs, 5, 5, "精度" , seido - 1, 3 , select, 0 ); Lib_view_set_uniq_numeral( pad_level_gs, 5, 35, "複雑度" , complex, 1, 9, 1 ); Lib_view_set_uniq_numeral( pad_level_gs, 5, 65, "途中下限値", mid_lower , 1000, 9999 , 2 ); Lib_view_set_uniq_numeral( pad_level_gs, 5, 95, "最終下限値", last_lower, 1000, 9999 , 3 ); Lib_view_set_size( pad_level_gs, 100, 130, 35, 5 ); Lib_draw_menu( pad_level_gs ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level_gs, value_gs ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ seido = value_gs[0].select_type + 1; complex = value_gs[1].value_type; mid_lower = value_gs[2].value_type; last_lower = value_gs[3].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_gs ); Lib_view_close( pad_level_gs ); Lib_recover_plane( idc ); } /***********************************************************************/ /* パタン登録      */ /***********************************************************************/ void ptn_reg( void ) { int error; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_freeze( TRANSMIT ); if ( 0 == ( error = Lib_gs_defpat( name1 ) ) ) { if ( -1 == ( error = Lib_gs_defpat( name2 ) ) ) Lib_display_message( 150, 200, "エラー", "既に200個登録済みです" ); else if ( -2 == error ) Lib_display_message( 150, 200, "エラー", "パタン格納領域不足です" ); } else if ( -1 == error ) Lib_display_message( 150, 200, "エラー", "既に200個登録済みです" ); else if ( -2 == error ) Lib_display_message( 150, 200, "エラー", "パタン格納領域不足です" ); Lib_freerun(); Lib_recover_plane( idc ); } /************************************************************************/ /* パタン表示 */ /************************************************************************/ void ptn_disp( void ) { int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_gs_dsppat( ); Lib_freerun(); Lib_recover_plane( idc ); } /*********************************************************************/ /*  ウインド設定制御                        */ /*********************************************************************/ void wind_set( void ) { int pad_level_wind; PVAL value_wind[2]; int no; int x_size,y_size; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); pad_level_wind = Lib_view_open(); Lib_view_set_title( pad_level_wind, "処理範囲" ); x_size = wxe - wxs + 1; y_size = wye - wys + 1; Lib_view_set_box( pad_level_wind, 5, 5, "始点" , wxs , wys , 3, 1, 0 ); Lib_view_set_box( pad_level_wind, 5, 35, "サイズ", x_size, y_size, 3, 0, 1 ); Lib_view_set_size( pad_level_wind, 100, 130, 5, 5 ); Lib_draw_menu( pad_level_wind ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level_wind, value_wind ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ wxs = value_wind[0].box_type.x; wys = value_wind[0].box_type.y; wxe = value_wind[0].box_type.x + value_wind[1].box_type.x - 1; wye = value_wind[0].box_type.y + value_wind[1].box_type.y - 1; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_wind ); Lib_view_close( pad_level_wind ); Lib_recover_plane( idc ); } /***********************************************************************/ /* 基準値取得      */ /***********************************************************************/ void kijun( void ) { int out_inf[8]; int xa, ya, xb, yb; int sotai_x, sotai_y; char ss[40]; int xs,ys,xe,ye; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); if ( 0 == Lib_gs_infpat( name1, out_inf ) ) { xa = ( out_inf[4] * 10 ) + out_inf[2]; ya = ( out_inf[5] * 10 ) + out_inf[3]; xs = out_inf[4]; ys = out_inf[5]; xe = xs + out_inf[0] - 1; ye = ys + out_inf[1] - 1; Lib_box( xs, ys, xe, ye, SOLID_LINE ); cross_mark( xa / 10, ya / 10, 5 ); if ( 0 == Lib_gs_infpat( name2, out_inf ) ) { xb = ( out_inf[4] * 10 ) + out_inf[2]; yb = ( out_inf[5] * 10 ) + out_inf[3]; xs = out_inf[4]; ys = out_inf[5]; xe = xs + out_inf[0] - 1; ye = ys + out_inf[1] - 1; Lib_box( xs, ys, xe, ye, SOLID_LINE ); cross_mark( xb / 10, yb / 10, 5 ); /* サーチした2点を結ぶ対角線の中点算出 */ MAS_x_center = ( xb + xa ) / 2; MAS_y_center = ( yb + ya ) / 2; sotai_x = xb - xa; sotai_y = yb - ya; /* 角度算出 */ MAS_angle = Lib_atan360( sotai_x, sotai_y ); /* 結果表示 */ cpx = dw = (double)MAS_x_center / 10.0; Lib_sprintf( ss,"基準x : %.1lf", dw ); Lib_chrdisp( 1, 28, ss ); cpy = dw = (double)MAS_y_center / 10.0; Lib_sprintf( ss,"基準y : %.1lf", dw ); Lib_chrdisp( 1, 29, ss ); dw = (double)MAS_angle / 10.0; Lib_sprintf( ss,"基準θ : %.1lf", dw ); Lib_chrdisp( 1, 30, ss ); cross_mark( d4i5_d( (double)cpx ), d4i5_d( (double)cpy ), 5 ); Lib_display_keyinput( 460, 0, "確認" ); } else Lib_display_message( 70, 200, "エラー", "サーチパタンが登録されていません。" ); } else Lib_display_message( 70, 200, "エラー", "サーチパタンが登録されていません。" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_recover_plane( idc ); } /***********************************************************************/ /* 試行        */ /***********************************************************************/ void exec() { int rtn; Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ /* ビデオフリーズ */ Lib_freeze( TRANSMIT ); /* グレイサーチの実行 */ if ( 1 == ( rtn = search( &wwxa, &wwya, &wwxb, &wwyb ) ) ) { /* サーチした2点を結ぶ対角線の中点算出 */ wwx_center = ( wwxb + wwxa ) / 2; wwy_center = ( wwyb + wwya ) / 2; wwsotai_x = wwxb - wwxa; wwsotai_y = wwyb - wwya; /* 角度算出 */ wwangle = Lib_atan360( wwsotai_x, wwsotai_y ); /* 基準値からのズレ算出 */ zure_x_center = wwx_center - MAS_x_center; zure_y_center = wwy_center - MAS_y_center; zure_angle = wwangle - MAS_angle; /* 結果表示 */ cpx = dw = (double)wwx_center / 10.0; Lib_sprintf( ss,"x :%.1lf", dw ); Lib_chrdisp( 1, 25, ss ); cpy = dw = (double)wwy_center / 10.0; Lib_sprintf( ss,"y :%.1lf", dw ); Lib_chrdisp( 1, 26, ss ); dw = (double)wwangle / 10.0; Lib_sprintf( ss,"θ :%.1lf", dw ); Lib_chrdisp( 1, 27, ss ); dw = (double)zure_x_center / 10.0; Lib_sprintf( ss,"ズレx :%.1lf", dw ); Lib_chrdisp( 1, 28, ss ); dw = (double)zure_y_center / 10.0; Lib_sprintf( ss,"ズレy :%.1lf", dw ); Lib_chrdisp( 1, 29, ss ); dw = (double)zure_angle / 10.0; Lib_sprintf( ss,"ズレθ :%.1lf", dw ); Lib_chrdisp( 1, 30, ss ); cross_mark( d4i5_d( (double)cpx ), d4i5_d( (double)cpy ), 5 ); Lib_time_disp( 0, 0 ); Lib_display_keyinput( 460, 0, "確認" ); } else if ( 0 == rtn ) Lib_display_message( 100, 200, "サーチエラー", "対象物がありません" ); else if ( -1 == rtn ) Lib_display_message( 100, 200, "サーチエラー", "パタンが登録されていません" ); /* ビデオフリーラン */ Lib_freerun(); Lib_cls( ( GRAY_PLANE | CHAR_PLANE | LINE_PLANE ), BLACK_COLOR ); } /************************************************************************/ /* グレイサーチ実行( サーチ数2個 ) */ /************************************************************************/ int search( xa, ya, xb, yb ) int *xa; int *ya; int *xb; int *yb; { int Rslt_Buf[3]; int rtn; Lib_gs_window( ON_DISPLAY, wxs, wys, wxe, wye ); /* サーチ実行1 */ if ( 0 < ( rtn = Lib_gs_search( ON_DISPLAY, name1, 1, seido, complex, mid_lower, last_lower, Rslt_Buf ) ) ) { *xa = Rslt_Buf[0]; *ya = Rslt_Buf[1]; /* サーチ実行2 */ if ( 0 < ( rtn = Lib_gs_xsearch( SAME_IMAGE, ON_DISPLAY, name2, 1, seido, complex, mid_lower, last_lower, Rslt_Buf ) ) ) { *xb = Rslt_Buf[0]; *yb = Rslt_Buf[1]; } } return( rtn ); } /***********************************************************************/ /* 入力数値(double)の4捨5入した数値(int)を返す */ /***********************************************************************/ int d4i5_d( double in ) { int out; if ( in >= 0.0 ) out = (int)( in + 0.5 ); else out = (int)( in - 0.5 ); return( out ); } /***** 十字マーク *****/ void cross_mark( x, y, length ) int x; int y; int length; { Lib_drawline( x - length, y, x + length, y ); Lib_drawline( x, y - length, x, y + length ); }