- 追加された行はこの色です。
- 削除された行はこの色です。
[[RTAIの使い方]]
+ サンプルプログラム(showroom)のインストールと実行&br;
本来,CVS を使ってコマンドラインで
# cvs -d:pserver:anonymous@cvs.gna.org:/cvs/rtai co showroom
としてインストールするが,proxy サーバ経由では CVS が使えないようだ.&br;
そこで,スナップショット http://cvs.gna.org/daily/rtai-snapshot.tar.gz を持ってくる.
++ /usr/src に rtai-snapshot.tar.gz を展開.
# cd /usr/src
# tar zxvf rtai-snapshot.tar.gz
++ shared memory のサンプルプログラムを編集する(そのままコンパイル・実行するとハングアップするので注意):
# cd rtai/showroom/v3.x/kern/shm
--- モジュール(カーネル空間のプログラム) shm.c: [[編集前>/:RTAI/shm/shm.c.org]] → [[編集後>/:RTAI/shm/shm.c]]
--- アプリケーション(ユーザ空間のプログラム) display.c: [[編集前>/:RTAI/shm/display.c.org]] → [[編集後>/:RTAI/shm/display.c]]
++ コンパイル・実行(事前に .cshrc 等で PATH に /usr/realtime/bin を追加しておく)
# make
gcc -I. -I/usr/realtime/include -O2 -I/usr/src/linux/include -Wall -Wstrict-prototypes -pipe -o display display.c
make -C /usr/src/linux CC=gcc SUBDIRS=$PWD V= modules
make[1]: Entering directory `/usr/src/linux-2.6.20.21'
CC [M] /usr/src/rtai/showroom/v3.x/kern/shm/shm.o
LD [M] /usr/src/rtai/showroom/v3.x/kern/shm/shm_rt.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: vmlinux - Section mismatch: reference to .init.data:boot_params from .text between '_text' (at offset 0xc1000029) and 'checkCPUtype'
(略)
WARNING: "rt_busy_sleep" [/usr/src/rtai/showroom/v3.x/kern/shm/shm_rt.ko] undefined!
WARNING: "rt_get_time" [/usr/src/rtai/showroom/v3.x/kern/shm/shm_rt.ko] undefined!
WARNING: "nano2count" [/usr/src/rtai/showroom/v3.x/kern/shm/shm_rt.ko] undefined!
CC /usr/src/rtai/showroom/v3.x/kern/shm/shm_rt.mod.o
LD [M] /usr/src/rtai/showroom/v3.x/kern/shm/shm_rt.ko
make[1]: Leaving directory `/usr/src/linux-2.6.20.21'
undefined! とたくさん出るのは無視
# ../ldmod
# insmod shm_rt.ko
# ./display
(ctrl-C で止める)
数字が変化する様子が表示されればOK.(カーネル空間のモジュールがリアルタイムでカウンタを変化させ,shared memory を経由して,ユーザー空間のプログラムでカウンタの内容を表示する)
# rmmod shm_rt
# ../remod
ERROR: Module rtai_lxrt does not exist in /proc/modules
ERROR: Module rtai_smp does not exist in /proc/modules
ERROR: Module rtai_mup does not exist in /proc/modules
ERROR: Module rtai_up does not exist in /proc/modules
ERROR: Module rtai_hal is in use by rtai_sched
何故かエラー.
# lsmod
Module Size Used by
rtai_sched 80424 0
rtai_hal 32340 1 rtai_sched
(略)
手動で外す:
# rmmod rtai_sched
# rmmod rtai_hal
+ 実験用プログラム period の作成&br;
shm をベースにして,実行周期を記録するプログラム(period*)を作る.
# cd /usr/src/rtai/showroom/v3.x/kern
# cp -a shm period (とりあえずコピーしてから編集する)
# cd period
# mv display.c period_app.c
# mv shm.c period_module.c
Makefile, GNUmakefile 中,shm → period_module,display → period_app に修正する.&br;
period_module.c, period_app.c を適宜編集,ヘッダファイル period.h を作成する.&br;
参考(編集,コンパイル・実行を一通り行った後のディレクトリ): [[/usr/src/rtai/showroom/v3.x/kern/period/>/:RTAI/period/]]&br;
実行例:
# make
gcc -I. -I/usr/realtime/include -O2 -I/usr/src/linux/include -Wall -Wstrict-prototypes -pipe -o period_app period_app.c
make -C /usr/src/linux CC=gcc SUBDIRS=$PWD V= modules
make[1]: Entering directory `/usr/src/linux-2.6.20.21'
CC [M] /usr/src/rtai/showroom/v3.x/kern/period/period_module.o
/usr/src/rtai/showroom/v3.x/kern/period/period_module.c: In function ‘fun’:
/usr/src/rtai/showroom/v3.x/kern/period/period_module.c:27: 警告: ‘t0’ may be used uninitialized in this function
/usr/src/rtai/showroom/v3.x/kern/period/period_module.c:26: 警告: ‘s_time’ may be used uninitialized in this function
LD [M] /usr/src/rtai/showroom/v3.x/kern/period/period_module_rt.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: vmlinux - Section mismatch: reference to .init.data:boot_params from .text between '_text' (at offset 0xc1000029) and 'checkCPUtype'
WARNING: vmlinux - Section mismatch: reference to .init.data:boot_params from .text between '_text' (at offset 0xc1000037) and 'checkCPUtype'
(略)
[/usr/src/rtai/showroom/v3.x/kern/period/period_module_rt.ko] undefined!
WARNING: "rt_get_time" [/usr/src/rtai/showroom/v3.x/kern/period/period_module_rt.ko] undefined!
WARNING: "nano2count" [/usr/src/rtai/showroom/v3.x/kern/period/period_module_rt.ko] undefined!
CC /usr/src/rtai/showroom/v3.x/kern/period/period_module_rt.mod.o
LD [M] /usr/src/rtai/showroom/v3.x/kern/period/period_module_rt.ko
make[1]: Leaving directory `/usr/src/linux-2.6.20.21'
# ../ldmod
# insmod period_module_rt.ko
# ./period_app > foo.dat
# rmmod period_module_rt
# ../remod
# rmmod rtai_sched
# rmmod rtai_hal
[[foo.datをグラフ表示した結果>/:RTAI/period/foo.png]]
時間が経過するに従いジッタが生じている.余分なモジュールを削除する等して,要改善.
+ 矩形波を出力するプログラム period_da* (period* に D/A 出力を追加したもの)
-- モジュールのプログラム period_module.c に D/A 出力を追加したものを period_da_module.c とする.後は上記と同じ.
--- D/A 出力を追加するために,adc.c, adc.h を追加する.使用している D/A, A/D ボードは CONTEC のもの.
--- Makefile に,adc.o をリンクするように記述
--- adc.h にはボードの I/O ベースアドレスを記載する.調査方法は以下の通り:
# lspci -v
(略)
03:01.0 Multimedia controller: Contec Co., Ltd Unknown device 8183
Subsystem: Contec Co., Ltd Unknown device 8183
Flags: medium devsel, IRQ 10
I/O ports at ece0 [size=32]
03:02.0 Multimedia controller: Contec Co., Ltd Unknown device 8153
Subsystem: Contec Co., Ltd Unknown device 8153
Flags: medium devsel, IRQ 6
I/O ports at ecc0 [size=32]
id=8183 は D/A12-4(PCI), id=8153 は AD12-16(PCI).&br;
上記の場合,I/Oポートアドレスはそれぞれ 0xece0 と 0xecc0 の二つ.
--- 作業後のディレクトリ: [[/usr/src/rtai/showroom/v3.x/kern/period_da/>/:RTAI/period_da/]]&br;
実行方法は上記 period* の場合と同様.&br;
実行時,D/A 変換ボードの出力 0ch をオシロで見ると, 50μsec で 0[V] と 1[V] が切り替わる矩形波が観測できる.
+ 周波数応答実験用プログラム freqresp
-- 作業後のディレクトリ: [[/usr/src/rtai/showroom/v3.x/kern/freqresp/>/:RTAI/freqresp/]]
-- sin 等数学関数を使っていて,libm を static リンクする必要があるため, /usr/src/rtai/showroom/v3.x/kern/fp/ を参考にして GNUmakefile, Makefile を編集した.
-- 予め,FFTを計算するライブラリ [[librealfft.a>/:RTAI/freqresp/fft/real/librealfft.a]], [[libfft.a>/:RTAI/freqresp/fft/complex/libfft.a]] を /usr/local/lib/ にインストールしておく必要がある.これらライブラリのコンパイルは,[[/usr/src/rtai/showroom/v3.x/kern/freqresp/fft>/:RTAI/freqresp/fft/]] を参考のこと.
-- D/A の 0ch と A/D の 0ch を直結しておく.(ゲイン1,位相0の周波数応答が取れるはず)
&br;
++ コンパイル
# cd /usr/src/rtai/showroom/v3.x/kern/freqresp
# mkdir data
# make clean
# make
++ 実行
# ../ldmod
# /sbin/insmod freqresp_module_rt.ko
# ./freqresp_app
(2ch 分の周波数応答が出力されるが,一方がゲインがほぼ1, 位相が0になっていることを確認する)
# rmmod _freqresp_module_rt
# ../remod
ERROR: Module rtai_mq does not exist in /proc/modules
ERROR: Module rtai_lxrt does not exist in /proc/modules
ERROR: Module rtai_smp does not exist in /proc/modules
ERROR: Module rtai_mup does not exist in /proc/modules
ERROR: Module rtai_up does not exist in /proc/modules
(insmod していない module を rmmod しようとしてエラーになってるだけなので問題なし)
# rmmod rtai_sched
# rmmod rtai_hal
- RTLinux版とRTAI版の比較
&br;
| |RTLinux 版|RTAI版|
|period(実行周期を記録する)|[[period.h>/:RTAI/period.h]]|[[period.h>/:RTAI/period/period.h]]|
||[[period_module.c>/:RTAI/period_module.c]]|[[period_module.c>/:RTAI/period/period_module.c]]|
||[[period_app.c>/:RTAI/period_app.c]]|[[period_app.c>/:RTAI/period/period_app.c]]|
|period_da(DAボードから矩形波を出力する)|period.h(同上)|period.h(同上)|
||[[period_da_module.c>/:RTAI/period_da_module.c]]|[[period_da_module.c>/:RTAI/period_da/period_da_module.c]]|
||period_app.c(同上)|period_app.c(同上)|
||[[adc.h>/:RTAI/adc.h]]|[[adc.h>/:RTAI/period_da/adc.h]]|
||[[adc.c>/:RTAI/adc.c]]|[[adc.c>/:RTAI/period_da/adc.c]]|
|freqresp(周波数応答実験)|[[freqresp.h>/:RTAI/freqresp.h]]|[[freqresp.h>/:RTAI/freqresp/freqresp.h]]|
||[[freqresp_module.c>/:RTAI/freqresp_module.c]]|[[freqresp_module.c>/:RTAI/freqresp/freqresp_module.c]]|
||[[freqresp_app.c>/:RTAI/freqresp_app.c]]|[[freqresp_app.c>/:RTAI/freqresp/freqresp_app.c]]|
- プログラム作成の参考資料:
-- [[RTAI3.4 User Manual rev 0.3>https://www.rtai.org/index.php?module=documents&JAS_DocumentManager_op=downloadFile&JAS_File_id=46]]
-- [[RTAI API Documentation>https://www.rtai.org/documentation/magma/html/api/]]