1
1

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 5 years have passed since last update.

MATLAB←→ROSでカメを動かす

Last updated at Posted at 2019-11-01

#概要
MATLAB(Windows)からROS(Ubuntu)にメッセージを送って,turtlesimパッケージのカメを動かす.

#環境

  • Ubuntu 16.04 LTS
  • ROS1 Kinetic Kame
  • Windows 10
  • MATLAB R2018b

#環境変数の設定
ここをちゃんと設定しないとROSネットワークが正常に動作しません.
データ送信は出来ても,受信はできないということが起きます.

ポイントは,ROS_HOSTNAMEROS_IPを同一にすることです.

##MATLAB

matlab
setenv('ROS_MASTER_URI','http://ここにUbuntuのIPアドレスを入力してください:11311');
setenv('ROS_HOSTNAME','ここにWindowsのIPアドレスを入力してください');
setenv('ROS_IP','ここにWindowsのIPアドレスを入力してください');

rosinit
>>The value of the ROS_MASTER_URI environment variable, http://ここにUbuntuIPアドレスが表示されます:11311, will be used to connect to the ROS master.
>>The value of the ROS_HOSTNAME environment variable, ここにWindowsIPアドレスが表示されます, will be used to set the advertised address for the ROS node.
>>Initializing global node /matlab_global_node_83800 with NodeURI http://ここにWindowsIPアドレスが表示されます:64160/

成功すると上記のようになります.

##ROS
bashの設定ファイル.bashrcに以下のコードを追加します.

.bashrc
export ROS_HOSTNAME=ここにUbuntuのIPアドレスを入力してください
export ROS_IP=ここにUbuntuのIPアドレスを入力してください
export ROS_MASTER_URI=http://ここにUbuntuのIPアドレスを入力してください:11311

設定したらsourceコマンドで.bashrcを再読み込みするか,端末を開きなおしましょう.

ちゃんと設定できているかはechoコマンドで環境変数を表示させることで確認できます.

terminal
echo $ROS_IP
echo $ROS_MASTER_URI

ここまで終わったら,ROSのマスターを起動しturtlesimのturtlesim_nodeを起動しておきましょう.

#カメを動かす
##メッセージの作成

以下のメッセージを生成します.

matlab
chatterpub = rospublisher('/chatter', 'std_msgs/String')
chattermsg = rosmessage(chatterpub);

chattermsg.Linear.X=2.0
chattermsg.Linear.Y=0.0
chattermsg.Linear.Z=0.0
chattermsg.Angular.X=0.0
chattermsg.Angular.Y=0.0
chattermsg.Angular.Z=1.8

以下のコマンドでメッセージを送ると,カメが円を描くように動きます.

matlab
send(chatterpub,chattermsg)

#参考URL

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?