1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rosrunを使わずros c++プログラムをバイナリから実行する

1
Last updated at Posted at 2021-07-28

はじめに

ros c++で作成したプログラムはrosrunを使用せずにバイナリファイルから実行することもでき、ここではそのやり方を記載します。

内容

例えば,以下の記事で作成したmy_helloパッケージのmy_helloというプログラムを実行してみます。

roscore
rosrun my_hello my_hello

そしてプロセス名を確認します。

$ ps -aux | grep my_hello
hoshina     7466  0.7  0.2 348852 19244 pts/3    Sl+  09:02   0:01 /home/hoshina/catkin_ws/devel/lib/my_hello/my_hello
hoshina     7584  0.0  0.0  17672   724 pts/1    S+   09:06   0:00 grep --color=auto my_hello

すると実際に動作しているプロセスは/home/hoshina/catkin_ws/devel/lib/my_hello/my_helloであることがわかります。

実際にバイナリファイルから実行してみます。

$ cd ~/catkin_ws/devel/lib/my_hello/
$ ./my_hello

[ INFO] [1627477760.933650008]: Hello world
[ INFO] [1627477761.033929098]: Hello world
[ INFO] [1627477761.133818627]: Hello world
...

正常に動作することがわかりました。

まとめ

ros c++プログラムは/home/{ユーザ名}/catkin_ws/devel/lib/{パッケージ名}/{実行ファイル名}のファイルから実行することができることが確認できました。

これを使用すると,例えばROSで作成したプログラムのバイナリだけ他のPCに共有することができ便利かもしれません。

おまけ

ちなみにroscoreプログラムの実行プロセスはどのようになっているかというと次の様になります。

$ ps -aux | grep roscore
hoshina     6077  0.3  0.5 295360 43912 pts/0    Sl+  08:41   0:07 /usr/bin/python3 /opt/ros/noetic/bin/roscore
hoshina     7706  0.0  0.0  17672   656 pts/1    S+   09:18   0:00 grep --color=auto roscore

roscoreの実行ファイルは/opt/ros/noetic/bin内にあることがわかりました。

そしてこのフォルダ内を見てみるとROSのコマンドの実行ファイルが色々と用意されていることが分かりました。

$ ls /opt/ros/noetic/bin/
catkin_find               rosmake       rqt_console
catkin_init_workspace     rosmaster     rqt_dep
catkin_make               rosmsg        rqt_graph
catkin_make_isolated      rosmsg-proto  rqt_image_view
catkin_test_results       rosnode       rqt_logger_level
catkin_topological_order  rospack       rqt_plot
rosbag                    rosparam      rqt_shell
rosboost-cfg              rosrun        run_selftest
rosclean                  rosservice    rviz
rosconsole                rossrv        selftest_example
roscore                   rosstack      selftest_rostest
roscreate-pkg             rostest       stage
rosgraph                  rostopic      tf_remap
roslaunch                 rosunit       view_frames
roslaunch-complete        roswtf        xacro
roslaunch-deps            rqt
roslaunch-logs            rqt_bag

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?