• 検索結果がありません。

Microsoft PowerPoint _2.プログラミングの基礎_final.pptx

N/A
N/A
Protected

Academic year: 2021

シェア "Microsoft PowerPoint _2.プログラミングの基礎_final.pptx"

Copied!
18
0
0

読み込み中.... (全文を見る)

全文

(1)

RTミドルウェアによるロボットプログラミング技術

(2)

概要

1. プログラミングの基礎

2. Linuxでのプログラミング

3. Windowsでのプログラミング

目標:

1.

LinuxおよびWindowsでの開発手法(主にC++)を学ぶ

2.

CMakeを利用して、同じプログラムをLinuxとWindowsとで

コンパイルして動作させる。

(3)

プログラミングの流れ

プログラム

コンパイル

リンク

実⾏

プログラム

コンパイル

(javac.exe)

JavaVM(java.exe)で

実⾏

プログラム

Pythonインタプリタで

実⾏

C++

Java

Python

ビルド

(コンパイル

+リンク)

(4)

CMake

• コンパイラに依存しないビルド⾃動化の

ためのフリーソフトウェア

• 様々なOS上の様々な開発環境⽤ビルドフ

ァイルを⽣成することができる

– Linux では Makefileを⽣成

– Windows ではVCのプロジェクトファイルを

⽣成

• 最近のオープンソースソフトウェアでは

CMakeでビルドするようになっているも

のが多数。

(5)

プログラム作成の流れ

コード作成

CMake

Visual C++

コンポーネントの

仕様の⼊⼒

VCプロジェクトファイル

または

Makefile

の⽣成

実装およびコンパイル

実⾏ファイルの⽣成

コード作成

CMake

make

+

gcc (g++)

Windows

Linux

途中まで流れは同じ、コンパイラが異なる

(6)

コンポーネント作成の流れ

RTBUilder

CMake

Visual C++

コンポーネントの

仕様の⼊⼒

VCプロジェクトファイル

または

Makefile

の⽣成

実装およびコンパイル

実⾏ファイルの⽣成

RTBUilder

CMake

make

+

gcc (g++)

Windows

Linux

(7)

演習︓CMakeを使ってみよう

• CMakeを使って同じプログラムをLinuxと

Windowsの両⽅でビルドしてみる。

• ⼿順︓

– サンプルプログラムをダウンロード

– CMakeLists.txtを編集

– cmake (cmake-gui)

– make or VC++ でコンパイル

– 実⾏

(8)

ソフトウェアのインストール

(Linux)

• openrtm.orgの

– 「ダウンロード」→「C++」→

「1.1.2」

• pkg_install_ubuntu.s

h をダウンロード

• sudo sh

pkg_install_ubuntu.s

h を実⾏

• cmakeもインストール

$

wget http://svn.openrtm.org/OpenRTM-aist/tags/RELEASE_1_1_2/OpenRTM-aist/build/pkg_install_ubuntu.sh

$

sudo sh pkg_install_ubuntu.sh –c

$

sudo apt-get install cmake

【使用コマンド一覧】

wget: ファイルなどをダウンロード

sudo: 管理者権限で実行

sh: シェルコマンド

(9)

Linux

ダウンロード

• ブラウザからダウンロ

ード または端末

“terminal” を開いて

wgetで取得&展開

• 以降の操作は terminal

で⾏うので開いたまま

$ $ mkdir workwget http://openrtm.org/openrtm/sites/default/files/6135/arm2dof_ver001.zip

--2016-11-05 22:57:38--: $ unzip arm2dof_ver001.zip Archive: arm2dof_ver001.zip creating: arm2dof/ inflating: arm2dof/arm2dof.cpp inflating: arm2dof/CMakeLists.txt $ cd arm2dof/ $ ls CMakeLists.txt arm2dof.cpp $

【使用コマンド一覧】

mkdir: フォルダ(ディレクトリ)を作成

wget: ファイルなどをダウンロード

unzip: ZIPファイルを展開

cd: ディレクトリに移動

ls: ファイル一覧を表示

左上ボタンを押して、検

索窓に

”terminal”と入

力し

terminal を起動

(10)

CMakeLists.txtの編集

• CMakeLists.txt をgedit(

エディタ)で開く

• 2⾏コメントイン

– ⾏頭の ʻ#ʼ を削除

• 保存・終了

add_executable(arm arm2dof.cpp)

の⾏は、

• 実⾏ファイル(executable)

arm2dof を作成せよ

• そのためのソースコードは

arm2dof.cpp である

ということを意味している

Linux

$ gedit CMakeLists.txt または $ vi CMakeLists.txt または $ emacs CMakeLists.txt

geditの編集画面

(11)

cmake & make & 実⾏

• build ディレクトリを作成

• cmake .. を実⾏

• make を実⾏

• arm2dofが⽣成される

• arm2dofを実⾏

Linux

n-ando@Ubuntu1604-64:~/work/arm2dof/build$ mkdir build

n-ando@Ubuntu1604-64:~/work/arm2dof/build$ cmake ..

-- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0

: 中略

-- Configuring done -- Generating done

-- Build files have been written to: /home/n-ando/work/arm2dof/build n-ando@Ubuntu1604-64:~/work/arm2dof/build$ make

Scanning dependencies of target arm2dof

[ 50%] Building CXX object CMakeFiles/arm2dof.dir/arm2dof.cpp.o [100%] Linking CXX executable arm2dof

[100%] Built target arm2dof

n-ando@Ubuntu1604-64:~/work/arm2dof/build$ ls

arm2dof CMakeCache.txt CMakeFiles cmake_install.cmake Makefile

n-ando@Ubuntu1604-64:~/work/arm2dof/build$ ./arm2dof

pos (x, y): -1, 1 ==> angle (th0, th1): 0, 0 pos (x, y): -0.5, 1 ==> angle (th0, th1): 0, 0 pos (x, y): 0, 1 ==> angle (th0, th1): 0, 0

pos (x, y): 0.5, 1 ==> angle (th0, th1): 0, 0 pos (x, y): 1, 1 ==> angle (th0, th1): 0, 0

n-ando@Ubuntu1604-64:~/work/arm2dof/build$

【使用コマンド一覧】

cmake: コマンド

make: Makefileに基づいてコンパイル・

リンクするためのコマンド

arm2dof: 今回作成する実行ファイル

【ディレクトリ指定】

. or ./ : 現在のディレクトリ(カレントディレ

クトリ)

.. or ../ : 現在のディレクトリの一つ上の

ディレクトリ(親ディレクトリ)

(12)

ソフトウェアのインストール

Windows)

• http://bit.ly/2fNLE6a

にアクセス

• 以下をインストール

– Python

– OpenRTM-aist

– PyYAML

– Cmake

– Doxygen

– TeraTerm

(13)

ダウンロード

Windows

• ブラウザからダウン

ロード

• ZIPを展開

• arm2dofフォルダの

下に

– arm2dof.cpp

– CMakeLists.txt

の2つのファイルが展開

される

http://bit.ly/2fpwDon

Windows

(14)

CMakeLists.txtの編集

• CMakeLists.txt をエ

ディタで開く

• 2⾏コメントイン

– ⾏頭の ʻ#ʼ を削除

add_executable(arm arm2dof.cpp)

の⾏は、

• 実⾏ファイル(executable)

arm2dof を作成せよ

• そのためのソースコードは

arm2dof.cpp である

ということを意味している

Windows

(15)

cmake-gui

スタートメニューからcmake-gui を起動

– スタートメニュー “cmake”内

– 検索窓でcmakeと⼊⼒するの

が早い

• CMakeLists.txtを受けのテキ

ストBOXにDnD

• “Configure”ボタンを押下

• ダイアログでVisual Studio

12 2013を選択

• 下の窓に “Configuring done”

ならOK

• “Generate”ボタンを押下

• 下の窓に “Generating done”

と出ていれば完了

CMakeLists.txt

を上のテキストボックスに

ドラッグアンドドロップ

② 下のテキストボックスに

“/build” を追加。上書き?

“OK” をクリック

“Configure”ボタンを押す

Visual Studio 12 2013 を選択

“Generate”ボタンを押す

Windows

(16)

コンパイル(ビルド)

• Build フォルダ内の

“Project.sln”をダブルクリ

ック

• Visual C++ 2013が起動

• “ビルド”→”ソリューション

のビルド”でコンパイル

と出ていれば正常終了

• arm2dof¥build¥Debug の

下に arm2dof.exe ができ

ている

ビルド: 2 正常終了、0 失敗、0 更新不要、1 スキップ

① ダブルクリックで

VC起動

② ビルド

Windows

(17)

実⾏

• コマンドプロンプトを起

– Explorerのアドレスバーに

“cmd” と⼊⼒しEnter

• プロンプトで

“arm2dof.exe” と⼊⼒

• 結果が表⽰される。

– ダミーコードなので、

angle = (0, 0) でしか表

⽰されない

– 2⽇⽬に練習問題として実

装してもらいます。

Windows

(18)

まとめ

• CMakeを利⽤すると、同じソースコード

をWindowsでもLinuxでコンパイルでき

– CMakeLists.txt をcmake (または

cmake-gui)で処理

– Windowsでは プロジェクトファイルとソリ

ューションファイル

– Linuxでは Makefile を作成

– それぞれの⽅法でビルド

参照

関連したドキュメント

First three eigenfaces : 3 個で 90 %ぐらいの 累積寄与率になる.

*この CD-ROM は,Microsoft Edge,Firefox,Google Chrome,Opera,Apple Safari

READ UNCOMMITTED 発生する 発生する 発生する 発生する 指定してもREAD COMMITEDで動作 READ COMMITTED 発生しない 発生する 発生する 発生する デフォルト.

参考資料ー経済関係機関一覧(⑤各項目に関する機関,組織,企業(2/7)) ⑤各項目に関する機関,組織,企業 組織名 概要・関係項目 URL

図 キハダマグロのサプライ・チェーン:東インドネシアの漁村からアメリカ市場へ (資料)筆者調査にもとづき作成 The Yellowfin Tuna Supply Chain: From Fishing Villages in

国の5カ年計画である「第11次交通安全基本計画」の目標値は、令和7年までに死者数を2千人以下、重傷者数を2万2千人

・大都市に近接する立地特性から、高い県外就業者の割合。(県内2 県内2 県内2/ 県内2 / / /3、県外 3、県外 3、県外 3、県外1/3 1/3

定可能性は大前提とした上で、どの程度の時間で、どの程度のメモリを用いれば計