Skip to content

対戦させるロボットのスクリプトを動的に指定#73

Draft
EndoNrak wants to merge 24 commits intomainfrom
game
Draft

対戦させるロボットのスクリプトを動的に指定#73
EndoNrak wants to merge 24 commits intomainfrom
game

Conversation

@EndoNrak
Copy link
Copy Markdown
Owner

#72

@EndoNrak EndoNrak self-assigned this Jan 25, 2022
Comment thread commands/game/main.py
def main():
game = Game(parse().__dict__)
game.clone_repository()
game.catkin_build()
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catkin_buildしたときに同じ名前のpackageがあるとエラーが発生する

    raise RuntimeError('\n'.join(duplicates))
RuntimeError: Multiple packages found with the same name "burger_navigation":
- EndoNrak-burger_war_dev/burger_navigation
- burger_war_dev/burger_navigation
Multiple packages found with the same name "burger_war_dev":
- EndoNrak-burger_war_dev/burger_war_dev
- burger_war_dev/burger_war_dev

パッケージ名にもprefixをつける必要がありそう

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

各パッケージフォルダのpackge.xml内で決まってるっぽい

Comment thread burger_war_dev/launch/game-start.launch Outdated
</include>
<!--blue side bot-->
<arg name="blue_bot_launch" default="$(find burger_war)/launch/sim_level_1_cheese.launch" />
<group ns="enemy_bot">
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name_spaceをenemy_botにすることでtopicを名前空間分けできる

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name_spaceをenemy_botにすることでtopicを名前空間分けできる

cheeseとかteriyakiには<arg name=“namespace” >があるので良いが、your_burger.launchにはないので、エラーの原因になる
your_burger.launchを調べて、なければ追加する必要がありそう

Comment thread burger_war_dev/launch/game-start.launch Outdated

<!--red side bot-->
<arg name="red_bot_launch" default="$(find burger_war)/launch/sim_level_1_cheese.launch" />
<include file="$(arg red_bot_launch)">
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

red_bot_launchにlaunchファイルへのパスを指定することで任意のlaunchファイルを設定できるようにした

@EndoNrak
Copy link
Copy Markdown
Owner Author

package名に"-"が入るのはillegalらしい。。。

ERROR:  
ERROR: package name 'EndoNrak-burger_war_dev' is illegal and cannot be used in message generation.
Please see http://ros.org/wiki/Names
make[3]: *** [/home/endo_nrak/catkin_ws/devel/.private/EndoNrak-burger_war_dev/lib/python2.7/dist-packages/EndoNrak-burger_war_dev/msg/_WarState.py] Error 2
make[2]: *** [CMakeFiles/EndoNrak-burger_war_dev_generate_messages_py.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
WARNING: Package name "EndoNrak-burger_war_dev" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "EndoNrak-burger_navigation" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "EndoNrak-burger_war_dev" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "EndoNrak-burger_war_dev" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "EndoNrak-burger_navigation" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "EndoNrak-burger_war_dev" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "EndoNrak-burger_war_dev" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
make[1]: *** [all] Error 2

@EndoNrak
Copy link
Copy Markdown
Owner Author

https://wiki.ros.org/Names
ここを見ると、

 - First character is an alpha character ([a-z|A-Z])
 - Subsequent characters can be alphanumeric ([0-9|a-z|A-Z]), underscores (_) or a forward slash (/)
 - There is at most one forward slash ('/').

underscoresは"burger_war_dev"とかでも使ってるので避けたい!
slashはパスとごちゃごちゃになりそうでめんどくさそう
となるとrosの守備範囲は"/"を使ってフォルダ名とかは"-"で乗り切るか?
あるいは英数字で接続詞をつくるか?

@EndoNrak
Copy link
Copy Markdown
Owner Author

EndoNrak commented Feb 5, 2022

https://wiki.ros.org/Names ここを見ると、

 - First character is an alpha character ([a-z|A-Z])
 - Subsequent characters can be alphanumeric ([0-9|a-z|A-Z]), underscores (_) or a forward slash (/)
 - There is at most one forward slash ('/').

underscoresは"burger_war_dev"とかでも使ってるので避けたい! slashはパスとごちゃごちゃになりそうでめんどくさそう となるとrosの守備範囲は"/"を使ってフォルダ名とかは"-"で乗り切るか? あるいは英数字で接続詞をつくるか?

/で切ると上手くいかなかった
___で乗り切ることにした

Comment thread commands/game/game.py
for c in cmakelists:
pkg_name_mg.rename_pkg_name_in_cmakelists(c)
for y in launchs:
pkg_name_mg.rename_pkg_name_in_launch(y)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.launchファイルの中身の$(find {package})$(find {user}___{package})に書き換えている

Comment thread commands/game/game.py
def start(self):
move_to_catkin_ws()
os.chdir("src/burger_war_dev/commands")
cmd = "roslaunch game-start.launch red_bot_launch:={} blue_bot_launch:={}".format(self.red_launch, self.blue_launch)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_launch_filesで指定した.launchファイルの絶対パスをblue_bot_launchおよびred_bot_launchに渡している

Comment thread commands/game/main.py
Otherwise, gets the burger_war_dev code from github like 'git clone https://gihub.com/EndoNrak/burger_war_dev.git' and launch it")
parser.add_argument("-red", type=str)
parser.add_argument("-blue", type=str, default="cheese")
args = parser.parse_args()
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このpythonファイルが実行される際に付与される-red-blueオプションを解析している

Comment thread commands/game/package_name.py Outdated
# "burger_war_dev" -> ""
def get_user_from_user_pkg(self, user_pkg):
result = [""] + user_pkg.split("___")
result = result[-2]
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変数user_pkg'burger_war_dev'などの
___prefixを持たない場合にはresult["", ""]

___prefixを持つ場合には["", user, pkg]になる。

このやり方微妙すぎる

userにたまたま___が含まれている場合にはバグの原因になる

user = result if result not in ["burger_war_dev", "burger_war_kit"] else ""
return user

def rename_pkg_name_in_file(self, path, pattern):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ファイルの中身を書き換える関数の抽象化されたversion
.tempファイルに書き込んでいき、最後にremove, renameして入れ替えている

self.rename_pkg_name_in_file(path, pattern)

def rename_pkg_name_in_launch(self, path):
pattern = r'\(find (.+)\)'
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(find {package})にマッチングするようにしている

match_str = match.group(1)
__pkg_name = [""] + match_str.split("___")
pkg_name = __pkg_name[-1]
line = line.replace(match_str, self.get_user_pkg(user, pkg_name), 1)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(find package)/launch/package.launch" のような場合に、二個目のpackageまで書き換えないように
第三引数に1を指定している

Comment thread commands/game/util.py

def get_launchs():
move_to_catkin_ws()
launch_files = glob.glob('src/*/*/launch/*.launch')
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launchファイルは全て検索している。
python2系では**を使った再帰的な検索ができないので、このマッチングにマッチしない場所にある.launchファイルは見逃すことになる

<?xml version="1.0"?>
<launch>
<arg name="side" default="r"/> <!-- "b" = blue side, "r" = red side -->
<arg name="name_space" default=""/>
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

game_start.launchname_spaceenemy_botにしたいときがあるので追加した

@EndoNrak
Copy link
Copy Markdown
Owner Author

EndoNrak commented Feb 5, 2022

@ikemuuu
ちょっと助けてほしい。。。
いま、EndoNrak/burger_war_devEndoNrak___burger_war_devとしてcloneした後に
blue側でname_space=enemy_botでlaunchしようとしてる。
rvizの立ち上がりまではうまく行くんやけど、rvizになんも表示されてなくて、多分/enemy/scanをsubscribeできてないかんじ
原因調べてくれん??burger_navigationの中身あんまわかってないから詰んだ。。。

@EndoNrak
Copy link
Copy Markdown
Owner Author

EndoNrak commented Feb 5, 2022

@ikemuuu ちょっと助けてほしい。。。 いま、EndoNrak/burger_war_devEndoNrak___burger_war_devとしてcloneした後に blue側でname_space=enemy_botでlaunchしようとしてる。 rvizの立ち上がりまではうまく行くんやけど、rvizになんも表示されてなくて、多分/enemy/scanをsubscribeできてないかんじ 原因調べてくれん??burger_navigationの中身あんまわかってないから詰んだ。。。

ちなみにname_spaceを指定なしで実行すると、red側のbotでちゃんと動いてるからname_space関連の感じ

@ikemuuu
Copy link
Copy Markdown
Collaborator

ikemuuu commented Feb 9, 2022

@ikemuuu ちょっと助けてほしい。。。 いま、EndoNrak/burger_war_devEndoNrak___burger_war_devとしてcloneした後に blue側でname_space=enemy_botでlaunchしようとしてる。 rvizの立ち上がりまではうまく行くんやけど、rvizになんも表示されてなくて、多分/enemy/scanをsubscribeできてないかんじ 原因調べてくれん??burger_navigationの中身あんまわかってないから詰んだ。。。

これ,実行までの手順教えてくれん??

@EndoNrak
Copy link
Copy Markdown
Owner Author

発見済みの残課題

  • 新たにclone してきたリポジトリ内でrosnodeを作成する.pyファイルに実行権限を付与
  • 新たにclone してきたリポジトリ内のyour_burger.launchファイル内のpkg="burger_war_dev"にprefixをつける
  • your_burger.launchに<arg name="name_space" default=""/>を追加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants