センサやアクチュエータとのインターフェースは次の5つの関数を使って行なう。
void sensor_init(); センサの初期化 void actuator_init(); アクチュエータの初期化 void actuator_stop(); アクチュエータの停止 void actuator(); アクチュエータへの出力 Matrix sensor(); センサからの入力
センサの初期関数の例を次に示す。
Func void sensor_init() { void count_init(); // 変換係数の設定(m/カウント数) c_k = [[0.07489506 * 0.001] [0.04600000 * 0.001] [0.07501935 * 0.001]]; count_init(); // カウンタの初期化 }
アクチュエータの初期関数の例を次に示す。
Func void actuator_init() { void actuator_stop(); apd = amd = fsp = fsm = fcp = fcm = Z(DA_CH, 1); // 変換係数の設定 fsp(1) = 6.843; fcp(1) = 6.843/3; fsm(1) = 8.026; fcm(1) = 8.026/3; apd(1) = 8.355 ; amd(1) = 9.394 ; fsp(2) = 1.967 ; fcp(2) = 1.967/3; fsm(2) = 2.089 ; fcm(2) = 2.089/3; apd(2) = 1.050 ; amd(2) = 1.071 ; actuator_stop(); // アクチュエータ停止 }
アクチュエータを停止する関数の例を次に示す。
Func void actuator_stop() { void da_zero(); da_zero(); // D/A出力を0にする }
センサの出力を読み込む関数の例を示す。
Func Matrix sensor() { Integer i; Matrix cnt_data; Integer count_get(); // カウンタ読み込み関数 cnt_data = Z(CNT_CH,1); for (i = 1; i <= CNT_CH; i++){ cnt_data(i) = c_k(i) * count_get(i); } return cnt_data; }
アクチュエータへ出力する関数の例を示す。
Func void actuator(data) Matrix data; { Integer i; Index da_port; Matrix v; void da_conv(); // D/A出力関数 v = Z(DA_CH, 1); for (i = 1; i <= DA_CH; i++) { if (data(i) >= 0.0) { v(i) = data(i) / apd(i); } else { v(i) = data(i) / amd(i); } } da_port = [1 2]; da_conv(da_port, v); }