ROSメッセージのお勉強
rosメッセージの復習
メッセージコマンド
すべてのメッセージを表示
$ rosmsg list
指定したメッセージの型を表示
$ rosmsg show geometry_msgs/Twist geometry_msgs/Vector3 linear float64 x float64 y float64 z geometry_msgs/Vector3 angular float64 x float64 y float64 z
パッケージへ行って中身確認
$ roscd geometry_msgs/msg/ $ e Twist.msg # This expresses velocity in free space broken into its linear and angular part\ s. Vector3 linear Vector3 angular
定義されているmsg型を利用してmsgを作ることができる↑
Vecter3を調べてみる
$ e Vector3.msg # This represents a vector in free space. # It is only meant to represent a direction. Therefore, it does not # make sense to apply a translation to it (e.g., when applying a # generic rigid transformation to a Vector3, tf2 will only apply the # rotation). If you want your data to be translatable too, use the # geometry_msgs/Point message instead. float64 x float64 y float64 z
指定したパッケージで使用されているメッセージ
$ rosmsg package turtlesim turtlesim/Color turtlesim/Pose
メッセージファイルの作成
msgデイレクトリにmsgファイルを作成
$ roscd sample $ mkdir msg $ cd msg $ touch msg_sample.msg
msg_sample.msgの中身↓
int32 data
package.xmlに以下を追加
<build_depend>message_generation</build_depend> <run_depend>message_runtime</run_depend>
CMakeLists.txtに以下を追加
find_package(catkin REQUIRED COMPONENTS rospy std_msgs message_generation # 追加 )
add_message_files( FILES msg_sample.msg )
generate_message( DEPENDENCIES std_msgs )
catkin_package( CATKIN_DEPENDS rospy std_msgs message_runtime # message_runtimeを追加 )
スクリプトから呼び出すときは
from sample.msg import msg_sample