見出し画像

RaspberryPiとUbuntuでEPICSはじめました#2 EPICSインストールまで

この記事は、EPICS(Experimental Physics and Industrial Control System)の初学用にまとめた記事です。

RaspberryPiをIOC化しよう!

EPICS 7.0.4とBase 3.15.8がありますが、迷ったら数字の大きい方!ってことでEPICSをインストールしてみます。構成がいろいろ違うのですがこの辺は初学時点では悩まず前に進むこととします。

下記を参考にしましたが色々異なります。

Raspberry Pi 3 Model B Rev.2 + Ubuntu 20.04 LTS + EPICS7.0.4の構成とします。

Ubuntu serverのインストールを行う

・http://cdimage.ubuntu.com/releases/20.04/release/ubuntu-20.04-preinstalled-server-arm64+raspi.img.xzをダウンロードしてSDカードに書き込みしました。この辺りは他にもたくさん情報があるので省略します。

インストールが済んだらSDカードをRaspberryPIに挿して、LANに接続後起動。DHCP環境ならばケーブル接続だけで設定が不要なので有線LANを使います。
次にEPICSをインストールします。

sshで他の端末からRaspberryPiへ接続

RaspberryPiのコンソールからCUIで入力することも可能ですが、他のPCやMacで調べ物して操作するのにいちいちキーボードを替えるのが面倒ですし、RaspberryPi用にディスプレイを用意する必要がない、あとなんか外から操作すると立派な技術者になった気になれるので、外からsshで接続してPcやMacから操作しましょう。

起動後、ubuntuアカウントのパスワードを変更したら、「IPv4 address for th0:xxx.xxx.xxx.xxx」を確認して、sshでRaspberryPiへ接続します。
Mac:ターミナルを使用、Windows:適当なターミナル(teratermとか)を使用する。Permission denied (publickey,password).が出たらsudoを付ける。以降はsshからの操作を記載します。

$ sudo ssh ubuntuxxx.xxx.xxx.xxx

作業用アカウント作成

Argonne国立研究所のHPからSoftwareを選択すると、[Base]、[Modules]、[Extensions]と[Distributions]がありそれぞれ・・・

Base: epicsの本体です。
Modules: IOCsで使う設定です。ここにない場合は自分で作ります。
Extensions:IOCs, OPIsで使うツール類です。GUIアプリケーション、Pythonなどの言語から使うライブラリがあります。
Distributions:色々ありますが今は不要なのでまた今度。

アカウントユーザー名:epicsを追加して、インストールもそちらで行えるようにsudo権限を追加します。

# epicsアカウントを追加 
ubuntu@ubuntu:~$ sudo adduser epics
Adding user `epics' ...
Adding new group `epics' (1001) ...
Adding new user `epics' (1001) with group `epics' ...
Creating home directory `/home/epics' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for epics
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y

# epicsアカウントにsudo権限を追加する
​ubuntu@ubuntu:~$ sudo usermod -aG sudo epics
ubuntu@ubuntu:~$ 

一度sshを終了してepicsアカウントでログインして以降はこちらのアカウントで進めます。

# ログアウト
ubuntu@ubuntu:~$ exit
# epicsアカウントでログイン
$ sudo ssh epics@192.168.0.x
epics@192.168.0.x's password: 
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-1008-raspi aarch64)

* Documentation:  https://help.ubuntu.com
* Management:     https://landscape.canonical.com
* Support:        https://ubuntu.com/advantage

 System information as of Fri Jul  3 00:27:04 UTC 2020

 System load:  0.21              Temperature:           58.0 C
 Usage of /:   33.9% of 7.05GB   Processes:             132
 Memory usage: 31%               Users logged in:       1
 Swap usage:   0%                IPv4 address for eth0: 192.168.0.6

* "If you've been waiting for the perfect Kubernetes dev solution for
  macOS, the wait is over. Learn how to install Microk8s on macOS."

  https://www.techrepublic.com/article/how-to-install-microk8s-on-macos/

44 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable


*** System restart required ***
Last login: Fri Jul  3 00:26:20 2020 from 192.168.0.4
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

epics@ubuntu:~$ 

update&upgradeしておます。

時間がかかるので先にやっておきましょう。

epics@ubuntu:~$ sudo apt update
[sudo] password for epics: 
...
      
Reading package lists... Done
Building dependency tree       
Reading state information... Done
48 packages can be upgraded. Run 'apt list --upgradable' to see them.

epics@ubuntu:~$ sudo apt upgrade
...
epics@ubuntu:/opt/epics/base$ 

epicsのダウンロード

フォルダー構成を先に考えておきます。
インストール先:/opt/epics 配下にインストールします。
/opt/epics/tmp下をファイルのダウンロード先とします。

# /opt/epics,/opt/epics/tmpフォルダを作成して所有者を変更
epics@ubuntu:~$ sudo mkdir -p /opt/epics/tmp
[sudo] password for epics: 
epics@ubuntu:/opt/epics/tmp$ sudo chown epics:epics /opt/epics
epics@ubuntu:/opt/epics/tmp$ sudo chown epics:epics /opt/epics/tmp
# 一応確認
epics@ubuntu:/opt/epics/tmp$ ls -l /opt
total 4
drwxr-xr-x 3 epics epics 4096 Jul  3 00:35 epics
epics@ubuntu:/opt/epics/tmp$ ls -l /opt/epics
total 4
drwxr-xr-x 2 epics epics 4096 Jul  3 00:35 tmp
epics@ubuntu:/opt/epics/tmp$ 

# ダウンロードする
epics@ubuntu:~$ cd /opt/epics/tmp
epics@ubuntu:/opt/epics/tmp$ wget https://epics-controls.org/download/base/base-7.0.4.tar.gz
--2020-07-03 00:45:29--  https://epics-controls.org/download/base/base-7.0.4.tar.gz
Resolving epics-controls.org (epics-controls.org)... 141.14.140.4
Connecting to epics-controls.org (epics-controls.org)|141.14.140.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2975446 (2.8M) [application/x-gzip]
Saving to: ‘base-7.0.4.tar.gz’

base-7.0.4.tar.gz   100%[===================>]   2.84M   931KB/s    in 3.1s    

2020-07-03 00:45:34 (931 KB/s) - ‘base-7.0.4.tar.gz’ saved [2975446/2975446]

epics@ubuntu:/opt/epics/tmp$ ls -l
total 2908
-rw-rw-r-- 1 epics epics 2975446 May 29 02:34 base-7.0.4.tar.gz

# 解凍する
epics@ubuntu:/opt/epics/tmp$ cd /opt/epics
epics@ubuntu:/opt/epics$ gzip -dc ./tmp/base-7.0.4.tar.gz | tar xvf -
base-7.0.4/documentation/RecordReference.md
base-7.0.4/documentation/KnownProblems.html
base-7.0.4/documentation/README.darwin.html
base-7.0.4/documentation/ReleaseChecklist.html
...

epics@ubuntu:/opt/epics$ ls -l
total 8
drwxrwxr-x 8 epics epics 4096 Jul  3 00:48 base-7.0.4
drwxr-xr-x 2 epics epics 4096 Jul  3 00:45 tmp

# 名前が長いのでシンボリックリンクを作成しておきます
epics@ubuntu:/opt/epics$ ln -s base-7.0.4 base
epics@ubuntu:/opt/epics$ ls -l
total 8
lrwxrwxrwx 1 epics epics   10 Jul  3 00:54 base -> base-7.0.4
drwxrwxr-x 8 epics epics 4096 Jul  3 00:48 base-7.0.4
drwxr-xr-x 2 epics epics 4096 Jul  3 00:45 tmp
epics@ubuntu:/opt/epics$ 

フォルダの中身は・・・Makefileがありますね。

epics@ubuntu:/opt/epics$ cd /opt/epics/base
epics@ubuntu:/opt/epics/base$ ls -l
total 40
-rw-r--r--  1 epics epics 4710 May 28 23:12 LICENSE
-rw-r--r--  1 epics epics  782 May 28 23:12 Makefile
-rw-r--r--  1 epics epics 1031 May 28 23:12 README
drwxrwxr-x  3 epics epics 4096 Jul  3 00:48 configure
drwxrwxr-x  2 epics epics 4096 Jul  3 00:48 documentation
drwxrwxr-x 11 epics epics 4096 Jul  3 00:48 modules
drwxrwxr-x  4 epics epics 4096 Jul  3 00:48 src
drwxrwxr-x  2 epics epics 4096 Jul  3 00:48 startup
drwxrwxr-x  3 epics epics 4096 Jul  3 00:48 test
epics@ubuntu:/opt/epics/base$ 

コンパイルしてインストール

その前に・・・インストールしたてのubuntu環境にはコンパイルするツールがないので先にインストールが必要です。
ここは初学の方に向けてエラーを出しながら手探りで作業を進めます。
知識がある方やビルド環境が整っている場合は、読み飛ばして普通にインストールしても問題ないと考えています。
尚、RaspberryPi以外のUbuntuやCentosでも同様の手順でインストールは可能です。

make, gcc, g++ がインストールされていて
export EPICS_HOST_ARCH=linux-arm が設定されていればmake可能

ここは初学の為、手探りで試してみます。まずはmakeを試してみます。

epics@ubuntu:/opt/epics/base$ make

Command 'make' not found, but can be installed with:

sudo apt install make        # version 4.2.1-1.2, or
sudo apt install make-guile  # version 4.2.1-1.2

いきなり動きません。makeが見つからないからまずはmakeのインストールして再びmake実行!

epics@ubuntu:/opt/epics/base$ sudo apt install make
[sudo] password for epics: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
 make-doc
The following NEW packages will be installed:
 make
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 154 kB of archives.
After this operation, 389 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 make arm64 4.2.1-1.2 [154 kB]
Fetched 154 kB in 2s (102 kB/s)                    
Selecting previously unselected package make.
(Reading database ... 99138 files and directories currently installed.)
Preparing to unpack .../make_4.2.1-1.2_arm64.deb ...
Unpacking make (4.2.1-1.2) ...
Setting up make (4.2.1-1.2) ...
Processing triggers for man-db (2.9.1-1) ...

# makeインストール後、make実行
epics@ubuntu:/opt/epics/base$ make
./src/tools/EpicsHostArch.pl: Architecture 'aarch64-linux-gnu-thread-multi' not recognized
configure/CONFIG:58: configure/os/CONFIG..Common: No such file or directory
make: *** No rule to make target 'configure/os/CONFIG..Common'.  Stop.
epics@ubuntu:/opt/epics/base$ 


次にmake: *** No rule to make targetって怒られます。
configure/CONFIG:58: で怒られているので
vi configure/CONFIG
で58行目を確認すると・・・

include $(CONFIG)/os/CONFIG.$(EPICS_HOST_ARCH).Common

となっていますconfigure/osを確認するとずらずらと・・・

epics@ubuntu:/opt/epics/base$ ls configure/os
CONFIG.Common.RTEMS
CONFIG.Common.RTEMS-at91rm9200ek
...
CONFIG.linux-arm.Common

Installation Instructions を確認すると(先に確認しておけよって声が遠くから聞こえてくる気がするようなしないような・・・マニュアル読まない派なのでね)

Set environment variables

Files in the base/startup directory have been provided to help set required path and other environment variables.

EPICS_HOST_ARCH Before you can build or use EPICS R3.15, the environment variable EPICS_HOST_ARCH must be defined. A perl script EpicsHostArch.pl in the base/startup directory has been provided to help set EPICS_HOST_ARCH. You should have EPICS_HOST_ARCH set to your host operating system followed by a dash and then your host architecture, e.g. solaris-sparc. If you are not using the OS vendor's c/c++ compiler for host builds, you will need another dash followed by the alternate compiler name (e.g. "-gnu" for GNU c/c++ compilers on a solaris host or "-mingw" for MinGW c/c++ compilers on a WIN32 host). See configure/CONFIG_SITE for a list of supported EPICS_HOST_ARCH values.

ビルドする前にEPICS_HOST_ARCHを設定すると書いてます。
なのでRaspberryPiのUbuntuを使う場合は、linux-armを設定しておきましょう。

epics@ubuntu:/opt/epics/base$ export EPICS_HOST_ARCH=linux-arm
epics@ubuntu:/opt/epics/base$ echo $EPICS_HOST_ARCH
linux-arm

三度makeをかけるも次に・・・


epics@ubuntu:/opt/epics/base$ make
make -C ./configure install
make[1]: Entering directory '/opt/epics/base-7.0.4/configure'
perl -CSD ../src/tools/makeMakefile.pl O.linux-arm ../..
mkdir -p O.Common
make -C O.linux-arm -f ../Makefile TOP=../.. \
   T_A=linux-arm install
make[2]: Entering directory '/opt/epics/base-7.0.4/configure/O.linux-arm'
Installing CFG file ../../cfg/CONFIG_LIBCOM_MODULE
...
make[4]: /usr/bin/gcc: Command not found
Installing PERL_MODULES file ../../../../lib/perl/EPICS/macLib.pm
make[4]: *** No rule to make target 'ccl.o', needed by 'e_flex'.  Stop.
make[4]: Leaving directory '/opt/epics/base-7.0.4/modules/libcom/src/O.linux-arm'
make[3]: *** [../../../configure/RULES_ARCHS:58: install.linux-arm] Error 2
make[3]: Leaving directory '/opt/epics/base-7.0.4/modules/libcom/src'
make[2]: *** [../../configure/RULES_DIRS:85: src.install] Error 2
make[2]: Leaving directory '/opt/epics/base-7.0.4/modules/libcom'
make[1]: *** [../configure/RULES_DIRS:85: libcom.install] Error 2
make[1]: Leaving directory '/opt/epics/base-7.0.4/modules'
make: *** [configure/RULES_DIRS:85: modules.install] Error 2
epics@ubuntu:/opt/epics/base$ 
​

/usr/bin/gccがないって怒られますのでインストールです。

epics@ubuntu:/opt/epics/base$ sudo apt install gcc
...

四度make

epics@ubuntu:/opt/epics/base$ s@ubuntu:/opt/epics/base$ make
,,,
epicmake[4]: /usr/bin/g++: Command not found
make[4]: *** No rule to make target 'antelope', needed by '../../../../bin/linux-arm/antelope'.  Stop.
make[4]: Leaving directory '/opt/epics/base-7.0.4/modules/libcom/src/O.linux-arm'
make[3]: *** [../../../configure/RULES_ARCHS:58: install.linux-arm] Error 2
make[3]: Leaving directory '/opt/epics/base-7.0.4/modules/libcom/src'
make[2]: *** [../../configure/RULES_DIRS:85: src.install] Error 2
make[2]: Leaving directory '/opt/epics/base-7.0.4/modules/libcom'
make[1]: *** [../configure/RULES_DIRS:85: libcom.install] Error 2
make[1]: Leaving directory '/opt/epics/base-7.0.4/modules'
make: *** [configure/RULES_DIRS:85: modules.install] Error 2

今度は/usr/bin/g++がないと言われるのでinstallです。

epics@ubuntu:/opt/epics/base$ sudo apt install g++

五度make・・・時間がかかりますが、ビルドができました。

epics@ubuntu:/opt/epics/base$ make
...
​

念のためできた確認してみます。PATHが通っていないので直接softIocを実行してみましょう。epics>が表示されればmakeは完了しています。

epics@ubuntu:/opt/epics/base$ ./bin/linux-arm/softIoc
dbLoadDatabase("/opt/epics/base-7.0.4/bin/linux-arm/../../dbd/softIoc.dbd")
softIoc_registerRecordDeviceDriver(pdbbase)
epics> 

epics>からの抜けるにはC+c(Control+c)で終了します。

このままでは不便なのでPATHを通しましょう。

に書かれているのでフォルダ名を合わせて一番下へ追加します。

epics@ubuntu:~$ vi ~/.bashrc

# viが起動したら「i(Insertモード)」にしてカーソルを.bashrcの最後へ移動
# 下記を追加して「esc」、「:qw」でファイルを上書き&終了

export EPICS_BASE=/opt/epics/base
export EPICS_HOST_ARCH=linux-arm
export PATH=${EPICS_BASE}/bin/${EPICS_HOST_ARCH}:${PATH}

一度exitでsshから抜けて再度sshでログインしてsoftIocがパスなし動作するか確認します。

epics@ubuntu:~$ softIoc
dbLoadDatabase("/opt/epics/base-7.0.4/bin/linux-arm/../../dbd/softIoc.dbd")
softIoc_registerRecordDeviceDriver(pdbbase)
epics> 

softIocが動いたので無事PATHが通りました。

実際にRaspberryPiのGPIOの状態を取得、設定するにはどうしたら良いのでしょうか?次に説明します。



この記事が気に入ったらサポートをしてみませんか?