<<PackageHeader(remote_monitor)>>
<<TOC(4)>>

== About ==
Remote monitoring package for navigation with [[https://openvpn.net/|OpenVPN]]. We actually succeeded in remotely monitoring [[Robots/CIR-KIT-Unit03]]'s pose running in Tsukuba from Fukuoka ([[https://www.google.com/maps/dir/%E6%97%A5%E6%9C%ACFukuoka-ken/Tsukuba+Station,+Tsukuba,+Ibaraki+Prefecture,+Japan/@34.8284911,133.016243,7z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x3541817af77eb125:0x97a20ffb4a51384d!2m2!1d130.418297!2d33.6065756!1m5!1m1!1s0x60220c62d3552d37:0x3487ddbc353229bd!2m2!1d140.1116438!2d36.0827702!3e4|1200 km away]])

How to connect remote PCs with OpenVPN can be seen in [[http://qiita.com/MoriKen/items/7fe17fda8442adb599d9|Qiita: 図解!UbuntuでOpenVPNを使う (Japanese Page)]].

Tutorial to integrate OpenVPN and ROS is [[http://qiita.com/MoriKen/items/00c2006e0c7ae914a9ba|ROS で OpenVPN を使う (Japanese Page)]].

== Demo Video ==
[[https://youtu.be/hpAnaV-bylQ|{{attachment:remote_monitor.png|remote_monitor|width="600"}}]]

下記のコマンドで上記動画のように遊べるはずです

{{{
$ roslaunch cirkit_unit03_autorun autorun_gazebo.launch 
$ roslaunch remote_monitor remote_monitor_server_gazebo.launch
$ roslaunch remote_monitor remote_monitor_client_gazebo.launch 
}}}

== Nodes ==
=== monitor_server ===
 * 遠隔監視PC側`node`.`service`で受信した位置と姿勢を地図上に表示させる.

=== monitor_client ===
 * 移動ロボット側`node`.一定距離毎に現在位置と姿勢を`service`で送信する.
 * デフォルトでは`/amcl_pose`を`subscribe`する.

== Installation ==
以下のコマンドにしたがってインストールしてください.  
なお`<catkin_ws>`は,任意のcatkinizeされたワークスペースへのパスを表します.

=== Clone the repository ===
{{{
$ cd <catkin_ws>/src
$ git clone https://github.com/CIR-KIT/remote_monitor.git
}}}

=== Clone the dependent repository via wstool ===
{{{
$ cd <catkin_ws>
$ wstool init src
$ wstool merge -t src src/remote_monitor/remote_monitor.rosinstall
$ wstool update -t src
}}}

=== Clone the dependent repository via rpsdep ===
{{{
$ rosdep update && rosdep install -r -y --from-paths src --ignore-src
}}}

=== Build ===
{{{
$ cd <catkin_ws>
$ catkin_make
$ source devel/setup.bash
}}}

== How to launch ==
=== service server ===
 * 地図の在処として,下記のパッケージ配下のフォルダを見に行きます.
  * $(find cirkit_unit03_maps)/map/`
 * 地図名は引数で指定して下さい.

==== 実機の場合のコマンド ====

{{{
$ roslaunch remote_monitor remote_monitor_server.launch map_yaml:=hogehoge.yaml
}}}

==== `Gazebo`の場合のコマンド ====

{{{
$ roslaunch remote_monitor remote_monitor_server_gazebo.launch map_yaml:=hogehoge.yaml
}}}

=== service client === 

==== サーバー側のグローバルIPを設定する. ====

 * まずサーバ側の人にグローバルIPを聞く.
 * 以下の要領で設定ファイルに反映させる.

{{{
$ cd /etc/openvpn
$ emacs client.conf
}}}

client.conf
{{{
# 省略

# グローバルIPアドレスを指定する.
remote 101.102.103.xxx 1194

# 省略
}}}

==== OpenVPNを再起動する. ==== 

{{{
$ service openvpn restart
}}}

==== ネットワークを確認する. ==== 

{{{
$ ifconfig
}}}

 * 下記のような`tun`デバイスが表示される.少し時間がかかる場合がある.

{{{
tun0      Link encap:不明なネット  ハードウェアアドレス 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inetアドレス:10.8.0.6  P-t-P:10.8.0.5  マスク:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  メトリック:1
          RXパケット:0 エラー:0 損失:0 オーバラン:0 フレーム:0
          TXパケット:12 エラー:0 損失:0 オーバラン:0 キャリア:0
          衝突(Collisions):0 TXキュー長:100 
          RXバイト:2892 (2.8 KB)  TXバイト:504 (504.0 KB)
}}}

 * そしてサーバにping.

{{{
$ ping 10.8.0.1
}}}

==== ROSネットワークの設定 ====

 * 必ず「全てのコンソール」で下記の設定をすること.

{{{
export ROS_MASTER_URI=http://10.8.0.6:11311
export ROS_HOST_NAME=10.8.0.6
export ROS_IP=10.8.0.6
}}}

 * 下記をsourceでもよい.

{{{
roscd remote_monitor/scripts
source vpn_setting_for_robot.sh
}}}

 * 一応確認する.

{{{
$ env | grep ROS
}}}

==== ROSネットワークの確認 ====

{{{
$ rosservice list
}}}

 * 下記のサービスがあることを確認する.

{{{
/remote_monitor_robot_pose
/remote_monitor_human_pose
}}}

==== モニタークライアントを起動する ====

===== 実機設定 =====
{{{
$ roslaunch remote_monitor remote_monitor_client.launch
}}}

===== Gazebo設定 =====
{{{
$ roslaunch remote_monitor remote_monitor_client_gazebo.launch
}}}

== parameters ==
=== /config/remote_monitor_server.yaml ===
{{{
#!clearsilver CS/NodeAPI
param{
  no_header=True
  1.name=ratio
  1.type=double
  1.desc=元画像ファイルを表示する際の初期縮小率
  1.default=0.2
}
}}}

=== /config/third_robot_client.yaml ===
{{{
#!clearsilver CS/NodeAPI
param{
  no_header=True
  1.name=interval_dist
  1.type=double
  1.desc=現在地を送る周期(距離[m]毎)
  1.default=1.0
  2.name=pose_topic
  2.type=string
  2.desc=`subscribe`するトピック名
  2.default="amcl_pose"
}
}}}

== Commands ==
地図画像をアクティブにした状態で下記キーを入力するとモードを切り替えられます.

{{{
#!clearsilver CS/NodeAPI
param{
  no_header=True
  1.name=`c`
  1.type=current
  1.desc=現在のロボットの位置のみを地図上に表示します.
  2.name=`h`
  2.type=history
  2.desc=履歴を含んだロボットの位置を地図上に表示します.
  3.name=`r`
  3.type=reset history
  3.desc=`history` モードの履歴をクリアします.
  4.name=`p`
  4.type=plus to ratio
  4.desc=地図を拡大します.historyモードの履歴は削除します.
  5.name=`m`
  5.type=minus to ratio
  5.desc=地図を縮小します.historyモードの履歴は削除します.
}
}}}

## AUTOGENERATED DON'T DELETE
## CategoryPackage