0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ROSのRvizでstlファイルを表示する

Posted at

環境

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を表示すれば見れるはず

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?