環境
Ubuntu22.04 LTS
ROS Noetic
表示したいモデルの作成
Windows版Fusion360で行った。
好きなモデルの作成後、左のパネルのボディ上で右クリックし、エクスポートからSTLにエクスポートした。
何故かはわからないが、プロジェクトからエクスポートした場合、読み込めてもRvizで表示できなかった。そのため必ずボディからエクスポートを行う。
プログラムの作成
こちらの記事を参考にした。
generate_stl_object.py
#!/usr/bin/env python3
import rospy
from visualization_msgs.msg import Marker
rospy.init_node("marker_mesh_sample")
pub1 = rospy.Publisher('marker1', Marker, queue_size=10)
pub2 = rospy.Publisher('marker2', Marker, queue_size=10)
r = rospy.Rate(10)
while not rospy.is_shutdown():
mesh_marker = Marker()
mesh_marker.header.frame_id = "world"
mesh_marker.header.stamp = rospy.Time.now()
mesh_marker.pose.orientation.w = 1.0
mesh_marker.scale.x = 1.0
mesh_marker.scale.y = 1.0
mesh_marker.scale.z = 1.0
mesh_marker.type = Marker.MESH_RESOURCE
mesh_marker.mesh_use_embedded_materials = True
mesh_marker.mesh_resource = "package://project1/src/meshes/poll.stl"
mesh_marker.pose.position.x = 0.0
mesh_marker.pose.position.y = 0.0
mesh_marker.pose.position.z = 2.0
mesh_marker.color.r = 1.0
mesh_marker.color.g = 1.0
mesh_marker.color.b = 0.1
mesh_marker.color.a = 1.0
pub1.publish(mesh_marker)
mesh_marker.mesh_resource = "package://project1/src/meshes/star.stl"
mesh_marker.pose.position.x = 0.0
mesh_marker.pose.position.y = 0.0
mesh_marker.pose.position.z = 0.0
mesh_marker.color.r = 1.0
mesh_marker.color.g = 1.0
mesh_marker.color.b = 0.1
mesh_marker.color.a = 1.0
pub2.publish(mesh_marker)
r.sleep()
あとは実行してRviz上でMakerを表示すれば見れるはず