計算機とプログラミング
1
!
2013/11/29
計算機とプログラミング
1
!
2012/12/9
今回の
PBLの目的
•
Learning by doing
•
自律ロボット制御プログラミングの考え方を学ぶ
•
センサ情報からロボットの行動を決定するプログラ
ムを実装する方法を学ぶ
•
サッカーをするエージェントの作成
•
標準的ではないライブラリを利用できるようになる.
•
詳しいドキュメントがない
•
ヘッダーファイルに書いてある内容から推測
•
必要ならテストコードを書いて確認
Schedule 1,2(一部変更の可能性有り)
イントロ,ベクトル,簡単なエージェントプログラム,
Makeファイル,簡単な行動プログラム(ゴールにキック)
簡単な関数を作ろう(一番近くのチームメートはどこ?)
2013 12/13(金)
2013 11/29(金)
2013 12/6(金)
2014 1/10(金), 2014 1/24(金)
2014 1/31(金)
深野先生講義
サッカーチームを作ろう! (グループごとの作業となります)
トーナメント試合!
2013 12/20(金)
役割分担,行動の変更,チーム分け
イントロ,ベクトル,簡単なエージェントプログラム,
Makeファイル,簡単な行動プログラム(ゴールにキック)
簡単な関数を作ろう(一番近くのチームメートはどこ?)
2014 1/6(月)
2013 12/9(月)
2013 12/16(月)
2014 1/23(木), 2014 1/27(月)
2014 2/3(月)
深野先生講義
サッカーチームを作ろう! (グループごとの作業となります)
トーナメント試合!
2014 1/20(月)
役割分担,行動の変更,チーム分け
Schedule 3,4(一部変更の可能性有り)
RoboCup
!実世界の人工知能研究
を促進する舞台
中型ロボットリーグ
ヒューマノイドリーグ
シミュレーションリーグ
浅田教授
RoboCup
2Dサッカーシミュレーション
1997年に創設
クライアントサーバー方式
自律型エージェント
マルチエージェントの研究
のための共通プラットフォー
ム
今日のトピック
サッカーのサーバープログラムとクライアントプログラム
を起動できる.
ベクトルを使って必要な変数の計算をする
.
エージェントプログラムの特徴をつかむ
.
サッカーエージェントのプログラムのコンパイル
.
簡単なサッカーエージェントのプログラム
.
今日の授業でできるようになってほしいこと
この授業のためのページ
http://www.er.ams.eng.osaka-u.ac.jp/user/ogino/
ogiwiki/wiki.cgi/lec2009
Example
http://www.er.ams.eng.osaka-u.ac.jp/user/ogino/
lecture/PBL2009a/demo.swf
RoboCup2012 Mexico City
Soccer Simulation 2D League Final Match.
HELIOS2011
(Fukuoka University, Osaka Prefecture University, Japan)
vs.
WrightEagle
(University of Science and Technology of China, China)
http://www.youtube.com/watch?v=cDhSjSYPvdE
シミュレータの仕組み
接続要求
エージェント
試合の
シミュレータの仕組み
シミュレータの仕組み
今日の予定
!
エージェントプログラミングとは?
!
演習
(Exercises)
●
エージェントのサンプルプログラムを動かしてみよう
エージェントプログラミング
エージェントプログラミングってなに?!
!
! An agent is anything that can be viewed as ! !
perceiving its environment through sensors ! ! and
acting upon that environment through effectors.! ! !
エージェントプログラミング
●普通のプログラム!
!
多くのプログラミングはユーザやデータベースから
記号のインプットがあり、同じインプットには同じ
アウトプットを期待される。!
!
エージェントプログラミング
例
float root(float A, float B, float C)
!
{
!
!
/* 以下の二次方程式の答を返す関数!
A*x*x + B*x + C = 0 */
!
!
float discriminant = B*B - 4*A*C;//判別式
!
!
if (discriminant < 0)
!
!!
printf("Error: discriminant is less than zero.");
!
!
!
return (-B + sqrt(discriminant)) / (2*A);
!
}
エージェントプログラミング
●
エージェントプログラミングは少し違う
!
感覚から行動を生成する。行動が状況を変化させ、
同じような入力に異なった反応を返すべき時もある。
感覚や行動は記号の場合もあるが連続値でなければ
ならない事がほとんど。!
!状況把握→情報処理→行動→状況変化
エージェントプログラミング
●
Programming an agent is different!
!
!
!
!
!
!
Perceive
Think
Act
Agent program:
int main()
!
{
!
ecobe_init( "testecobe" );
!
while (ecobe_update())
!
{
!
!
...
!
ecobe_flush();
!
}
!
ecobe_close();
!
}
!
エージェントプログラミング
感覚情報を
受信
情報処理
行動を送信
UNIXコマンド参考ページ等
http://www.k-tanaka.net/unix/
基本コマンドのリファレンス
!
http://www.fse.cs.ritsumei.ac.jp/
~takayuki/unix.html
(
emacsコマンドも収録)
!
その他にもいっぱいあるので
分からなければググる!
Unix コマンド (ディレクトリ)
cd [ディレクトリの移動] --- cd 自分のホームディレクトリに移動!
cd .. 一つ上のディレクトリに移動(".."は一つ上のディレクトリの意味)!
cd dirA dirA というディレクトリに移動 ls [今いるディレクトリのファイルのリストを表示] --- ls ファイルのリストを表示("."から始まるファイルは表示しない)!
ls -a ファイルのリストを表示("."から始まるファイルも全て(all)表示する)!
ls -l 長い(long)フォーマットで表示 pwd [今いるディレクトリを表示] --- pwd mkdir [ディレクトリの作成] --- mkdir dirA 今いるディレクトリに dirA というディ レクトリを作成する.Unix コマンド(ファイル操作)
rm [ファイルの削除] --- rm fileA "fileA" という名前のファイルを削除!
rmdir dirA "dirA" という名前のディレクトリを削除 (空のディレクトリしか消せません)!
rm -fr dirB "dirB" というディレクトリ(空でない)を強制削除 cp [ファイルのコピー] --- cp fileA fileB "fileA"を"fileB"という名前でコピー ln [エイリアスの作成] --- ファイルの分身を作る(Windows ではショートカッ ト,Mac ではエイリアス,Linux ではシンボリックリ ンクという) ln -s originalA linkfileB originalA というファイルのリンクを linkfileB とい う名前で作成する. mv [ファイルの移動・名前の変更] --- mv fileA dirB fileA という名前のファイルを dirB というディレク トリに移動する. mv fileA fileB fileA という名前のファイルを fileB という名前のファ イルに変更する.練習
1.自分のホームディレクトリに
”hellotest” という名前の
ディレクトリを作成してください.
2.そのディレクトリに移動して,エディター
emacsで
以下の内容の
hello.c を作成し,コンパイルしてください.
#include <stdio.h>
!
int main(void)
{
prin9(“Hello World!”);
!
return 0;
}
練習
3.自分のホームディレクトリに
“bin” というディレ
クトリを作成してください.
4.ディレクトリ
“bin” に移動して,”hello” という名
前でシンボリックリンクを作成してください.
Unix コマンド(シェル変数)
which [コマンドのある場所を表示] --- which comcom "comcom"というコマンドのある場所を表示す る.コマンドがなかったり,パスが通っていな かったら表示されない. echo [変数などを返す] --- echo $PATH 変数"$PATH" に設定されている値を表示する. export [変数の設定] --- export PATH=$PATH: /bin練習
5.自分のホームディレクトリで “which␣ls” として,ls コマンド
がどこにあるか確かめてください.また,
”which hello” を確かめ
てください.
6.以下のコマンドを実行して,ホームディレクトリの “bin” の
ディレクトリを
$PATH に追加してください.
export␣PATH=$PATH:~/bin
(“~” は自分のホームディレクトリの意味になります)
7. “echo $PATH” のコマンドで,追加されたことを確認し,再
び
“which hello” で “hello” が検索可能かどうか確かめてください
Unix コマンド
& [バックグラウンドで実行] --- commA & コマンド"commA"をバックグラウンドで実行 top [プロセスの表示] --- top 現在実行されているプロセスがCPU消費の順に表示される kill [プロセスを殺す] --- kill %1 プロセス番号1を終了させる。 プロセス番号はjobsで確認する。 jobs [実行中プロセスを表示する] --- jobs 自分の端末から実行中のプロセスを表示する killall [プロセスを殺す] --- killall [commandA] "commandA" というプロセスを終了させる練習
8. “hellotest” のディレクトリで,以下の内容の “sleeptest.c” を
作成,コンパイル.
#include <stdio.h>
!
int main(void)
{
sleep(10);
prin9(“Hello World!”);
!
return 0;
}
9. スリープする秒数を100秒にして,バックグラウンドで実
行し,
killall コマンドでプロセスを殺してください.
Exercises
サンプルエージェントを動かそう
!!
!
1. “agent”という名前のディレクトリを作成!
!
mkdir
agent
!
!
2.作ったディレクトリに移動!
!
cd
agent
!
!
3. コンパイルに必要なファイルへのリンクを作成
ln
-s
/home/toyonaka/share/rc/lib/ecobetrilearn.so
.
ln
-s
/home/toyonaka/share/rc/include/cinterface.h .
サッカーサーバーの設定
1) 自分のホームディレクトリで “.profile”のファイルを(作っ
て)編集して、以下の
2行を追加
!
export PATH=$PATH:/home/toyonaka/share/rc/bin
!
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./
その後,端末で以下のコマンドを実行
!
source ~/.profile
!
2) サッカーサーバーの設定ファイルを自分のディレクトリに追加
!
mkdir ~/.rcssserver
cp /home/toyonaka/share/rc/share/server.conf ~/.rcssserver/
!
3) サッカーサーバーをバックグラウンドで実行
!
rcsoccersim &
!
4) クライアントプログラムの実行
!
rcssclient
!
Exercises
#include "cinterface.h"
!!
int main()
!{
! !ecobe_init( "happyteam" );
! !while (ecobe_update())
! !{
! ! !ecobe_set_velocity(2,2);
! ! !ecobe_flush();
! !}
! !ecobe_close();
!}
!1. “first.c”の編集
(場所は
agentディレクトリ内)
!
!
emacs
first.c &
!
2. コンパイル
!
gcc
-o
first
first.c
ecobetrilearn.so
-lpthread
!
3. サーバープログラムの起動
!
rcsoccersim &
4. エージェントプログラムの起動
!
./first
!
Makefile
It allows creating dependency rules!
for controlling automatic compilation
Makefile
1- Makefile のサンプルをダウンロード
http://www.er.ams.eng.osaka-u.ac.jp/user/ogino/
lecture/PBL2009a/Makefile
!
!
!
!
!
!
2- 自分のプログラムのあるディレクトリーに “Makefile” と
いうファイル名で保存
!
3- 以下のコマンドを実行(プログラム名がfirst の場合)
make␣first
CC=gcc
LFLAGS=-lpthread
DEPS = ecobetrilearn.so
!
%: %.c $(DEPS)
$(CC) -o $@ $^ $(LFLAGS)
for any V, always: |unit(V)| = 1
!
Vector Arithmetics
ちょっと復習
!
•
Vectors are relative
!
•
Sum
!
•
Subtract
!
•
Scale
!
•
Unit vector: V / |V|
A
B
A+B
-B
A-B
A/2
unit(A)
A
2A
Vector Arithmetics
rr
Vrb
rb
can kick if |Vrb| < dr+db
Kicking to goal
rr
rb
Vrb
Vrgl
Vrgr
A
A/2
B
C
D
Vrgr - Vrgl
A=
B= Vrgl + A/2
C= B - Vrb
D= unit(C)
Task: compute V in the C program
Download
V
V= Vrb + D
rb = 0.085
cinterface.h
struct strct_vector {
!
float length;
!
float angle;
!
};
!
!
struct strct_robot {
!
int id;
!
struct strct_vector position;
!
};
!
!
struct strct_goal {
!
struct strct_vector pole1;
!
struct strct_vector pole2;
!
};
!
!
int ecobe_init(char *team_name);
!
void ecobe_close();
!
int ecobe_update();
!
void ecobe_flush();
!
!
cinterface.h
/* sum(p1,p2) returns the sum of two given vectors p1 and p2!
*!
*/!
struct strct_vector ecobe_sum(struct strct_vector p1, struct strct_vector p2);!
struct strct_vector ecobe_subtract(struct strct_vector p1, struct strct_vector p2);!
!
/* scale:!
* scales a strct_vector by multiplying it's lenght with a float scale value!
*/!
struct strct_vector ecobe_scale(struct strct_vector p, float scalar);!
!
/* normalize:!
* normalizes a strct_vector by setting it's lenght to 1!
*/!
struct strct_vector ecobe_unit(struct strct_vector p);!
!
/* get_ballpos:!
* gives you a vector pointing towards the ball!
*/!
struct strct_vector ecobe_get_ballpos();!
struct strct_goal ecobe_get_leftgoal();!
struct strct_goal ecobe_get_rightgoal();!
Exercise 1
http://www.er.ams.eng.osaka-u.ac.jp/user/ogino/lecture/PBL2009a/
exercise-1.pdf
Exercise 2, 3
!
ゴールのポールとポールの間の距離を出力するプ
ログラムを書きなさい
!